Updating running Kubernetes resources from the kubectl commandline using the patch command image 45

Updating running Kubernetes resources from the kubectl commandline using the patch command

All too often I found myself editing Kubernetes resource definitions in the Kubernetes Dashboard. Modifying for example the type of a service. Typically I would git clone yaml files, run  them in a single statement and then manually change a few details.

image

After just the tiniest of search efforts, I ran into the kubectl patch command, that is created for just this purpose.

kubectl patch svc eventbuspublisherservice -p ‘{“spec”: {“type”: “NodePort”}}’ –namespace my_space

This will change the type of the eventbuspublisherservice  to  NodePort.

An alternative approach with patch is to create a YAML file with the desired new or updated content for the resource definition. Use a statement like this to apply the contents of the YAML file:

kubectl patch deployment my-deployment –patch “$(cat my-patch.yaml)” –namespace my_space

image

Documentation: https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/