Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
Although there’s more than one way to distribute and install kubectl plugins, the simplest way is to use krew. It is a package manager for kubectl and makes the installation and management of kubectl plugins a cakewalk. To get started, you would have to first install krew on your machine. You can refer to this installation document to do so.
To install any plugin, say the whoami plugin, run the following command:
I have made a demo plugin called kubectl-count, which we will be using for this small demo. The complete source code can be found here: https://github.com/neelanjan00/kubectl-count. In a nutshell, this plugin allows you to count the instances of Kubernetes resources present in your cluster. So for example, you can count the number of pods in a namespace, the number of nodes in your cluster, or the total number of deployments in all the namespaces of your cluster.
The source code of the plugin is pretty straightforward, we use the Cobra CLI to create a boilerplate CLI project.