I have a deployment running in Kubernetes and want to update the "args" prior to applying an update so that when it restarts, it uses a different entrypoint arg than it did during its initial startup, which also included some data bootstrapping.
I know you can run kubectl set image
to update the image that the deployment or replicaset is running, but how can I also update the args without deleting and re-creating the resource?
You can simply, do kubectl edit deployment/<deployment-name>
(see docs), modify the args
field of your container spec, and save+quit from your $EDITOR
.
This will update the deployment spec "in place" and delete and restart your pods with the new arguments. Under the hood this is no different from deleting and restarting your pods.
You can use kubectl patch
as pointed in the answer by @mr.franco. I'm using this to patch args
of kubernetes-dashboard
Deployment without modifying their official installation manifest.
Here is a full example of how you can replace (in terms of JSON patch) container args
on existing Deployment:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml
kubectl get deployment kubernetes-dashboard --namespace kubernetes-dashboard -o=json | jq '.spec.template.spec.containers[0].args'
[
"--auto-generate-certificates",
"--namespace=kubernetes-dashboard"
]
kubectl patch deployment \
kubernetes-dashboard \
--namespace kubernetes-dashboard \
--type='json' \
-p='[{"op": "replace", "path": "/spec/template/spec/containers/0/args", "value": [
"--auto-generate-certificates",
"--enable-insecure-login",
"--enable-skip-login",
"--namespace=kubernetes-dashboard"
]}]'
kubectl get deployment kubernetes-dashboard --namespace kubernetes-dashboard -o=json | jq '.spec.template.spec.containers[0].args'
[
"--auto-generate-certificates",
"--enable-insecure-login",
"--enable-skip-login",
"--namespace=kubernetes-dashboard"
]
You can use kubectl patch
for that use case.
For reference you can check that answer.