Member-only story
Introduction
For those of us who don’t want to edit resources with an editor that launches with a kubectl edit
command, there is command kubectl patch
, so let’s take advantage of it. The nice thing about the patch command is that you don’t have to handwrite it in the editor. Since resources can be changed with one liner, it is also suitable for embedding in shell scripts.
Let’s test this !
Run example deployment
root@vagrant:/home/vagrant# kubectl create deployment nginx --image=spy86/nginx:latest
deployment.apps/nginx created
root@vagrant:/home/vagrant# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx-6465f7cb5d-phgmr 1/1 Running 0 8s
root@vagrant:/home/vagrant# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 10s
root@vagrant:/home/vagrant#
Modify the container image
It can be used when you want to change the image version temporarily.
root@vagrant:/home/vagrant# kubectl patch deployment nginx -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx","image":"spy86/nginx:147"}]}}}}'
deployment.apps/nginx patched
root@vagrant:/home/vagrant#…