Build a Kubectl Plugin from Scratch
Steps and code about creating a useful kubectl plugin using Golang
The command-line tool kubectl is indispensable when using Kubernetes. You need it to query related Pod
and Service
information both in developing or performing some maintenance operations, such as events, scale, rolling update, etc.
However, when using kubectl, there are many inconveniences. Though Kubernetes is officially maintaining kubectl¹, and you can submit the problems, improvement, and even PR in its Github Issues, you still have to wait long before its release.
The most common solution is Kubectl-Plugin Pattern²
Plugins extend
kubectl
with new sub-commands, allowing for new and custom features not included in the main distribution ofkubectl --from Kubernete²
Plugins are some codes that can be used as a subcommand of kubectl. Usually, we use plugins to solve complex information queries, monitor log collection, debug Kubernetes resources, and so on.
This article is to record my process and experience in writing kubectl plugins.
Use existing Kubectl Plugins
In the beginning, general users will search for the tools they need in the existing plugin list instead of writing…