How do I update the args for a Kubernetes deployment

4/16/2018

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?

-- runforrestrun
docker
kubernetes

3 Answers

4/16/2018

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.

-- ffledgling
Source: StackOverflow

5/27/2020

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"
]
-- illagrenan
Source: StackOverflow

11/29/2018

You can use kubectl patch for that use case.

For reference you can check that answer.

-- mr.franco
Source: StackOverflow