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

Lucas Jellema

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/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Next Post

ADF Performance Monitor: Error Diagnostics

Facebook0TwitterLinkedinApplication errors are often hard to retrieve, or take a lot of time to resolve. When you are suffering from errors, and have a lack of clarity when errors happen, you would like to have useful error diagnostics for analysis. The ADF Performance Monitor automatically captures detailed diagnostics for each […]