Kubernetes Quick Tip – Using “Krew”, the Package Manager for kubectl Plugins
If you're a frequent user of the Kubernetes command line tool "kubectl", you might be asking yourself the question: "What is Krew, and what does it do?"
Krew is the plugin manager for the kubectl command line tool. It's a simple tool that helps you find, install and manage kubectl plugins in a consistent way.
Kubectl plugins are extremely easy to install and are a great way to simplify Kubernetes command line tasks by extending the capabilities of the kubectl command.
In just a few short steps below, you’ll find simple instructions for installing the Krew tool along with several examples of how to use a few of my favorite kubectl plugins.
Installing/Configuring Krew
- Installing Krew:
Krew can easily be installed in a matter of minutes on Linux, MacOS, or Windows by following the simple instructions for your particular OS here: https://krew.sigs.k8s.io/docs/user-guide/setup/install/
Since I am running Bash shell in Linux, I simply ran the install script in the link above and then added the line: export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" to my ~/.bashrc file.
After restarting my shell, I can confirm that Krew is installed correctly by running the command kubectl krew:
$> kubectl krew
krew is the kubectl plugin manager. You can invoke krew through kubectl: "kubectl krew [command]..." Usage: kubectl krew [command] Available Commands: help Help about any command index Manage custom plugin indexes info Show information about an available plugin install Install kubectl plugins list List installed kubectl plugins search Discover kubectl plugins uninstall Uninstall plugins update Update the local copy of the plugin index upgrade Upgrade installed plugins to newer versions version Show krew version and diagnostics Flags: -h, --help help for krew -v, --v Level number for the log level verbosity Use "kubectl krew [command] --help" for more information about a command. |
- Download the plugin list:
Update the local copy of the Krew plugin index by running the command kubectl krew update:
$> kubectl krew update
Updated the local copy of plugin index. |
- Discover plugins available on Krew:
To discover Krew plugins, you can either browse the current list of over 130 plugins in your browser at https://krew.sigs.k8s.io/plugins or display the list of available plugins by running the command kubectl krew search:
$> kubectl krew search
NAME DESCRIPTION INSTALLED access-matrix Show an RBAC access matrix for server resources no advise-psp Suggests PodSecurityPolicies for cluster no auth-proxy Authentication proxy to a pod or service no [...]
|
Kubectl Plugin Examples
As mentioned above, there are over 130 kubectl plugins available through Krew, so let’s take a look at how to install and use a few of my favorite kubectl plugins:
1. pod-dive
The kubectl “pod-dive” plugin returns data associated with the pod no matter where it is running, such as its origin workload, namespace, the node where it is running and its node pod siblings, as well basic health status of it all.
First, let’s install the “pod-dive” plugin with the command kubectl krew install pod-dive:
$> kubectl krew install pod-dive
Updated the local copy of plugin index. Installing plugin: pod-dive Installed plugin: pod-dive Usage: kubectl pod-dive [pod name] [flags]
|
Now let’s look at an example of the output returned when using the pod-drive plugin. Usage: kubectl pod-dive [pod name]
|
2. get-all
If you use kubectl on a regular basis, then you’re probably well aware of this fact: For a complete overview of all resources in a Kubernetes cluster, the command "kubectl get all --all-namespaces" is not enough, because it simply does not show everything. Lucky for us, the "get-all" plugin lists really all resources the cluster has to offer.
First, let’s install the “pod-dive” plugin with the command kubectl krew install get-all:
$> kubectl krew install get-all
Updated the local copy of plugin index. Installing plugin: get-all Installed plugin: get-all Usage: kubectl pod-dive [pod name] [flags]
|
Now let’s look at an example of the output returned when using the pod-drive plugin with the command kubectl get-all:
**Since the “kubectl get-all” command I ran on my cluster below returned 460 lines/resources, I’ve clipped the output at the bottom of the table below with […]. So, let’s just say that the “get-all” plugin REALLY does get all resources in the cluster!
Detailed usage documentation of the” get-all” plugin and its optional arguments can be found here: https://github.com/corneliusweig/ketall/blob/master/doc/USAGE.md
[...] |
Be sure to browse through the large and growing list of kubectl plugins managed by Krew here: https://krew.sigs.k8s.io/plugins
I’m sure you’ll find quite a few plugins that will help save you time and help to eliminate the occasional hand cramp from typing out so many kubectl commands!
(Speaking of hand cramps, if you’re a Linux or MacOS user, be sure to enable kubectl auto-completion and create a k for kubectl command alias while you’re at it :) https://kubernetes.io/docs/tasks/tools/install-kubectl/#optional-kubectl-configurations )
Krew Reference URLs:
- - Krew Home Page: https://krew.sigs.k8s.io
- - Krew QuickStart/Install: https://krew.sigs.k8s.io/docs/user-guide/quickstart
- - Krew Plugin List: https://krew.sigs.k8s.io/plugins
- - Krew User Guide: https://krew.sigs.k8s.io/docs/user-guide/
- - Krew Official GitHub Repo: https://github.com/kubernetes-sigs/krew