I am trying to run my pod using below command but keep getting error error: Invalid JSON Patch
.
kubectl run -i tmp-pod --rm -n=my-scripts --image=placeholder --restart=Never --overrides= "$(cat pod.json)"
here is my pod.json
file
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "test",
"namespace": "my-ns",
"labels": {
"app": "test"
}
},
"spec": {
"containers": [
{
"name": "test",
"image": "myimage",
"command": [
"python",
"/usr/bin/cma/excute.py"
]
}
]
}
}
what i am doing wrong here?
CodePudding user response:
it's working for me however i have tried removing namespace
pod.json
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "test",
"labels": {
"app": "test"
}
},
"spec": {
"containers": [
{
"name": "test",
"image": "myimage",
"command": [
"python",
"/usr/bin/cma/excute.py"
]
}
]
}
}
command
kubectl run -i tmp-pod --rm --image=placeholder --restart=Never --overrides= "$(cat pod.json)"
CodePudding user response:
I did a bit of testing and it seems there is an issue with Cmder not executing $()
properly - either not working at all, or treating newlines as Enter, and thus executing a commant before entire JSON is passed.
You may want to try running your commands in PowerShell:
kubectl run -i tmp-pod --rm -n=my-scripts --image=placeholder --restart=Never --overrides=$(Get-Content pod.json -Raw)
There is a similar issue on GitHub [Windows] kubectl run not accepting valid JSON as --override on Windows (same JSON works on Mac) #519. Unfortunately, there is no clear solution for this.
Possible solutions are:
- Passing JSON as a string directly
kubectl run -i tmp-pod --rm -n=my-scripts --image=placeholder --restart=Never --overrides='{"apiVersion":"v1","kind":"Pod","metadata":{...}}'
- Using
'
instead of"
around overrides. - Using triple quotes
"""
instead of single quotes"
in JSON file.