How to patch Kubernetes Daemonset How to patch Kubernetes Daemonset kubernetes kubernetes

How to patch Kubernetes Daemonset


Try this command:

kubectl patch ds/name --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/ports/1", "value":{"containerPort":8888,"name":"http"}}]'


As already mentioned by David in the comment it is better to keep every change under version control.

But if you really need to do this, here is the command:

kubectl patch ds -n ingress nginx-ingress-microk8s-controller --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/ports/-", "value":{"containerPort":1234,"name":"my-port-1234","hostPort":1234,"protocol":"TCP"}}]'

patch command is explained in k8s docs: update-api-object-kubectl-patch,and the json type patch details are explained in rfc6902.