Kubernetes: Krew plugins manager, and useful kubectl plugins list

By | 10/01/2021
 

One of the most valuable features of the kubectl utility is its plugins.

Of course, there are things like Lens, widely used by developers who don’t like working in the terminal, or tools like k9s, but kubectl‘s plugins worth for a dedicated post.

So, in this post, we will install Krew – kubectl‘s plugins manager, and will take a look at the list of the plugins, that are used by me during work.

Krew – plugins manager for the kubectl

Recently, kubectl got its own plugins manager, Krew.

It has a plugins repository used to install and upgrade plugins.

On the Arch Linux krew can be installed from AUR:

Arch Linux:

yay -S krew

Update its packages list:

kubectl krew update

Look for a plugin, for example,  topology:

kubectl krew search topology
NAME      DESCRIPTION                                INSTALLED
topology  Explore region topology for nodes or pods  no

Install it:

kubectl krew install topology
Updated the local copy of plugin index.
Upgrades available for installed plugins:
* rbac-tool v1.2.1 -> v1.3.0
Installing plugin: topology
Installed plugin: topology
\
| Use this plugin:
|      kubectl topology
| Documentation:
|      https://github.com/bmcustodio/kubectl-topology
/

And check:

kubectl topology help
Provides insight into the topology of a Kubernetes cluster.
Usage:
kubectl-topology [command]
Available Commands:
help        Help about any command
node        Provides insight into the distribution of nodes per region or zone.
pod         Provides insight into the distribution of pods per region or zone.

kubectl – useful plugins list

At the end of this post I’ll add a couple of links with a similar plugins list, and here below let’s take a look at the best, as for me, plugins that I’m using during work.

kubectl-topology

Let’s start from the kubectl-topology plugin that allows to display all cluster’s WorkerNodes, their regions, and pods located on each node:

kubectl-resources

The kubectl-resources plugin can display extended information about limits and resources used by pods on WorkerNodes.

Install with Go:

go get github.com/howardjohn/kubectl-resources

kubectl-free

The kubectl-free plugin is similar to the free utility in Linux – it will display information about used and available resources on WorkerNodes.

Install it by downloading an archive from the release page, unzip, and copy to the /usr/local/bin:

cd /tmp/
wget https://github.com/makocchi-git/kubectl-free/releases/download/v0.2.0/kubectl-free_0.2.0_Linux_x86_64.zip
unzip kubectl-free_0.2.0_Linux_x86_64.zip
sudo cp kubectl-free_0.2.0_Linux_x86_64/kubectl-free /usr/local/bin/

And run it:

kubecolor

kubecolor is very useful to make kubectl‘s output more readable by colonizing it.

Install with Go:

go install github.com/dty1er/kubecolor/cmd/kubecolor@latest

Add an alias to the  ~/.bashrc:

alias kk="kubecolor"

And result:

kubectl-watch

An improved variant of the kubectl --watch. The project’s page is here>>>.

Install:

git clone https://github.com/lee0c/kubectl-watch.git
cd kubectl-watch
chmod +x kubectl-watch
sudo mv  kubectl-watch /usr/local/bin/

Check:

kubectl plugin list
The following kubectl-compatible plugins are available:
/usr/local/bin/kubectl-watch
...

And run:

kubectl-clogs

An advanced logs viewer. Similar to the kubectl logs -f, but can tail logs from all pods in a namespace. More details here>>>.

Install:

go install github.com/ivkalita/kubectl-clogs/cmd/kubectl-clogs@latest

And check logs from the istio-system namespace:

kubectl-who-can

kubectl-who-can is used to display RBAC permissions and accesses.

Install with Krew:

kubectl krew install who-can

And check who is able to delete pods in the default namespace:

kubectl-rolesum

kubectl-rolesum is also used to work with the Kubernetes RBAC to check permissions.

Install:

kubectl krew install rolesum

And check permissions for the kiali-service-account ServiceAccount in the istio-system namespace:

ketall

ketall will display indeed all resources including Secrets, ServiceAccount, Roles, Binding and so on, and not only Pods, Services, Daemonsets, Deployments, and ReplicaSets, as it is when using the kubectl get all.

Install:

kubectl krew install get-all

An example of the  kubectl get all command’s output:

And with the ketallkubectl get-all:

kubectl-status

kubectl-status can display extended information about pods’ statuses, nodes, deployments, services, and so on.

Install:

kubectl krew install status

And check Kubernetes WorkerNodes status with the role: data-workers label set:

Pod-Dive

Pod-Dive will display information about a Kubernetes Pod – its WorkerNode, a namespace, containers in that pod, and other pods, that are running on the same WorkerNode.

Install:

kubectl krew install pod-dive

And check a Pod:

kubectl-janitor

kubectl-janitor – a “cleaner” for a Kubernetes cluster. Can find problematic resources, such as unscheduled pods, failed jobs, volumes, etc.

Install:

kubectl krew install janitor

And find all pods that are not scheduled to a WorkerNode:

kubectl-cf

And the last plugin for today  – kubectl-cf.

Actually, there are a lot of plugins to simply work with kubectl‘s contexts, but I’m using dedicated files for clusters instead of dedicated contexts:

ls -1 ~/.kube/ | grep kubeconfig
dev-1-18.kubeconfig
prod-1-18.kubeconfig
stage-1-18.kubeconfig
test-1-18.kubeconfig

For a faster switch between them, we can use the kubectl-cf plugin, that will work via creating symlinks to the  ~/.kube/config file.

Pay attention, that all files must have the .kubeconfig extension.

Install it – clone its repository, build, and copy to the /usr/local/bin:

git clone https://github.com/spongeprojects/kubectl-cf.git
cd kubectl-cf/
go build -o kubectl-cf
sudo cp kubectl-cf /usr/local/bin/

Useful links



Also published on Medium.