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

0

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/

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.

Leave a Reply

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