Background
Currently, Kubernetes is the most popular container orchestration platform. Kubectl is the most popular command-line tool to interact with Kubernetes cluster. Kubernetes is quite extensible. In this post, we are going to see how to make use of kubectl plugin manager Krew to extend the functionality of Kubectl.
Krew plugin manager
You might have heard about package managers such as Homebrew for Mac, Chocolatey or Winget for Windows or apt-get for Linux. These package managers help us to search, install, uninstall and upgrade packages or software on our operating system. Similar to the package managers, there are plugins or extensions. These help to extend the functionality of a tool or program. The most common examples of plugins or extensions are found with browsers and also Integrated Development Environment(IDE) such as Visual Studio, IntelliJ Idea, Eclipse etc.
I hope you got the context now with regards to the plugins and package manager. Coming back to the topic of this blog post, we will look at Krew which is a package manager specifically for kubectl. As a plugin manager for kubectl, Krew performs 3 main activities
- discover kubectl plugins
- install them on your machine
- keep the plugins up-to-date
As of this writing, there are 151 kubectl plugins that are distributed by krew. Krew is cross-platform and works on Windows, macOS and Linux. Note that there are some plugins that work only on a particular operating system.
In the video, we can see how to install Krew and work with different plugins.
Krew commands
- krew install krew - install krew on the system
- kubectl krew list - list installed plugins
- kubectl krew search - search available plugins
- kubectl krew install [plugin name] - install a plugin
- kubectl krew info [plugin name] - get info about the plugin
- kubectl krew uninstall [plugin name] - uninstall a plugin
- kubectl krew update - update the index of plugins
- kubectl krew upgrade - upgrade plugin version
Useful Kubectl plugins
In the video, these plugins are demonstrated.
pod-lens
Pod-lens plugin shows the hierarchy of different objects related to a pod such as the namespace, container, services that interact with the pods, the associated persistent volume claim (PVC), secrets etc.
The output shows an interactive option to select the pods in a namespace. By default, it shows the summary for the selected pod and once we select an individual pod the plugin lists all the dependencies.pod-dive
Pod dive gives a minimal view of pod. As compared to the pod-lens it shows a hierarchical view of pod along with the siblings which are pods running on the same node. This can be quite handy to know what other pods are running on the node where a specific pod is currently scheduled to run.
pod-inspect
Pod inspect is somewhat similar to pod-dive. Instead of showing the hierarchy, it depicts the information in a tabular format.
images
I particularly like the images plugin. It gives information about the container images in the Kubernetes cluster. This can be quite handy to know which all images are running in the cluster and what is the source of those images. There is also a quick summary presented at the top of the output which lists the number of namespaces, pods, containers and different versions of images.
rbac-view
The rbac-view plugin gives details about the ClusterRoles and Roles.
Conclusion
Krew is quite handy when it comes to extending the functionality of kubectl using plugins. It makes life easier for searching, installing and managing the plugins. Without Krew, it would be difficult to know what plugins are available and how to keep them updated. I demonstrated only a handful of plugins here. If you have used any other kubectl plugin and find it useful please recommend using the comments either on Youtube video or this blog post. I would love to hear feedback from viewers/readers about krew and different kubectl plugins.
Until next time, Code with Passion and Strive for Excellence.