kubectl inspect pod mypod
Creating a kubectl plugin in 30 seconds
While there’s currently no kubectl inspect
command like the title suggests, kubectl does now have a newly redesigned plugin system that allows you to easily create your own inspect
command and have it do whatever you want — maybe something like in the following asciicast:
As you can see, my kubectl inspect
plugin enables you to quickly display a Kubernetes resource’s YAML — with syntax highlighting!
I know people hate YAML, but I prefer inspecting a resource by looking at its raw YAML over using something likekubectl describe
. With syntax highlighting, reading the YAML is a breeze.
I’ve recently upgraded from cat
(meow) to bat
(squeek?) for printing out files, but getting it to make my resource shine with colors required too many keystrokes. For example:
$ kubectl get pod mypod -o yaml | bat -l yaml -p
That’s a lot of extra characters to type, but it’s worth it, since it brings up this beautifully-colored YAML:
After using the command for a while, I had a brainwave and realized I could create a new kubectl plugin that would allow me to simply type:
$ kubectl inspect pod mypod
It took me less than 30 seconds to create the plugin. All that was needed was to add a file called kubectl-inspect
to my path with the following contents:
#!/bin/bash
kubectl get "$@" -o yaml | bat -l yaml -p
And that’s it! No need to register the plugin with kubectl or anything! I bet you didn’t think it could be done in 30 seconds, right?
So what will your first kubectl plugin be?
P.S.: The new kubectl plugin system is available from v1.12.0-beta.1 onwards.
P.P.S.: Don’t forget to do a chmod +x
on the plugin file.