Member-only story

Command for Those Who Don’t Want Use Kubectl Edit

Maciej
2 min readJul 27, 2021

--

Photo by Erik Mclean on Unsplash

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#…

--

--

Maciej
Maciej

Written by Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.

No responses yet