I am to patch an image onto init containers
my image is stored in a variable called $IMAGE_NAME
When I run
kubectl patch deployment production-art-backend -p {"spec":{"template":{"spec":{"initContainers":[{"name":"run-migrations","image":"$IMAGE_NAME"}]}}}}
it patches the image as 'IMAGE_NAME' and not the value inside the variable IMAGE_NAME, how can I patch the image dynamically?
Please try below command :
kubectl patch deployment production-art-backend --patch="{\"spec\":{\"template\":{\"spec\":{\"initContainers\":[{\"name\":\"run-migrations\",\"image\":\"$IMAGE_NAME\"}]}}}}"
It worked for me.
This is a bash issue, not necessarily a kubectl
issue!
Because the JSON string requires double quotes, you need to wrap the variable inside single quotes. Try this:
kubectl patch deployment production-art-backend -p {"spec":{"template":{"spec":{"initContainers":[{"name":"run-migrations","image":"'${IMAGE_NAME}'"}]}}}}