Kubectl — Plugins Operation

K8s kubectl Deep Dive



Besides default kubectl operations, you can also use plugins with kubectl . Under the hood, aplugin in kubectl is just an executable file (a complied Go program or a Bash shell script, etc), and the name of which begins with kubectl- . To install the plugin, what yuo need to do is just put its executable file in a directory that’s in your PATH variable.

To intall and manage plugins for kubectl , I would recommend krew. Krew (https://krew.sigs.k8s.io/) is the K8s plugin manager and is probably the easiest way to find and install plugins.

What is Krew

Krew is the plugin manager for kubectl command-line tool. Krew helps you:

  • Discover kubectl plugins,
  • Install them on your machine,
  • Keep the installed plugins up-to-date.

krew provides a simple way to download, retrieve and manage other plugins for kubectl, similar to Unix/Linux system's apt, yum, brew and other tools. There are about 200+ kubectl plugins currently distributed on Krew. Krew works across all major platforms, like macOS, Linux and Windows.

The kubectl plugin mechanism was declared stable in K8s v1.14 and entered the GA state. The plugin mechanism of kubectl is to allow developers to publish custom kubectl subcommands in independent binary form.

Install Krew

Make sure you have git installed. Then run the following command to install Krew:

set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" &&
KREW="krew-${OS}_${ARCH}" &&
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
tar zxvf "${KREW}.tar.gz" &&
./"${KREW}" install krew
Adding "default" plugin index from https://github.com/kubernetes-sigs/krew-index.git.
Updated the local copy of plugin index.
Installing plugin: krew
Installed plugin: krew
| Use this plugin:
| kubectl krew
| Documentation:
| https://krew.sigs.k8s.io/
| Caveats:
| \
| | krew is now installed! To start using kubectl plugins, you need to add
| | krew's installation…