How to manage Kubectl plugins using Krew package manager

  

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 

  1. discover kubectl plugins
  2. install them on your machine
  3. 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

Here are some of the commands demonstrated in the video related to krew
  • 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.

spacer

Improve productivity while working with Kubernetes using kubectl power tools Kubectx and kubens

 

Background

If you are a DevOps or Site Reliability Engineer (SRE) engineer, most probably you will be working with multiple clusters. You might also be working with multiple namespaces across these clusters. It can be quite time consuming to switch between contexts and namespaces while working with the kubectl command-line tool.

kubectl power tools

Kubernetes is quite popular nowadays and it is very common for people to work with Kubernetes clusters using kubectl as command-line interface. Most people prefer to work with kubectl instead of working with GUI based tools.

For SRE and DevOps engineers as well as developers who are working with multiple clusters say for example Dev, staging / UAT and Production environments, they need to switch the context. In many enterprises, the Kubernetes clusters are shared by different teams. In order to isolate workloads, kubernetes namespaces are used. You need to provide the namespace everytime any command is executed.

In such scenarios switching between namespaces on the same cluster and also switch the whole context to point to a different cluster can be a cumbersome task. That is where I came across two power tools while working with kubectl, kubectx and kubens.

In the video, we can see how to install kubectx and kubens along with Fuzzy Search (FZF) tool for interactive mode.

Conclusion

Using kubectx and kubens helps to improve productivity while working with kubectl. We don't need to remember lengthy context names and also names of each and every namespace in the cluster. Get more productive by using these power tools.

Until next time, Code with Passion and Strive for Excellence.

spacer