Quick Links

Krew is a package manager for Kubectl, the official Kubernetes CLI. Using Krew you can find, install, and update Kubectl plugins that extend the CLI with additional functionality.

Kubectl's plugins mechanism supports several plugin installation methods. The simplest way is to pop plugins straight into a directory that's in your PATH. This is a manual process which offers no way to update the plugin as new releases are published.

Krew provides common package management functionalities for the Kubectl plugin ecosystem. It maintains a public index of known packages and supports third-party indexes too. The latter lets you publish plugins privately within an organization or team.

Installing Krew

Krew is an open-source tool that's part of the Kubernetes project. It doesn't come bundled with Kubectl though. To get started with Krew, you must manually download and install the latest release. Current Krew distributions work with Kubectl v1.12 and later.

Downloads are available from the project's GitHub releases page. The distribution tar archives contain the Krew binary. Run its installation script to finish adding Krew to your system:

$ ./krew-linux_amd64 install krew

A complete script that automatically downloads and installs the correct Krew distribution for your system is available within the documentation.

Next you should update your PATH to include Krew's bin directory. This is located within $KREW_ROOT which is usually $HOME/.krew. Executables from Kubectl plugins you install will be stored inside the bin subdirectory.

$ export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

Now you should be able to use Krew via the kubectl krew command:

~$ kubectl krew

krew is the kubectl plugin manager.

You can invoke krew through kubectl: "kubectl krew [command]..."

Usage:

kubectl krew [command]

...

Updating the Plugin Index

Krew's plugin index catalogs all the currently available plugins you can install. It works similarly to the package lists used by OS-level package managers such as apt.

Update the index periodically so your Krew installation has access to the latest versions of all available plugins:

$ kubectl krew update

Updated the local copy of plugin index.

Installing Plugins

The install command adds new plugins to Kubectl. It can install any of the plugins listed in Krew's index. Krew takes care of downloading the plugin and registering it with Kubectl.

$ kubectl krew install ctx

Updated the local copy of plugin index.

Installing plugin: ctx

Installed plugin: ctx

...

Krew automatically updates its plugin index before installation, ensuring you get the new plugin's latest release. Once the install completes, you'll see some basic information from the plugin's author at the bottom of the command's output.

Now you can use the plugin's commands via the kubectl CLI:

$ kubectl ctx my-context

Updating to New Plugin Releases

One of Krew's biggest advantages is its integrated plugin update system. Running the upgrade command will refresh the package index and update all your installed plugins to their newest release. This process is fully automatic.

$ kubectl krew upgrade

Updated the local copy of plugin index.

...

You can upgrade plugins individually by passing their names to the upgrade command:

$ kubectl krew upgrade ctx

If you ever want to remove a plugin, supply its name to the uninstall command:

$ kubectl krew uninstall ctx

Krew will ensure the plugin's completely removed from your system.

The list command shows all your plugins and their installed versions:

~$ kubectl krew list

PLUGIN VERSION

ctx v0.9.4

krew v0.4.3

ns v0.9.4

Krew itself appears in the plugin list and is supported by the update system. Running upgrade or upgrade krew will fetch and install the latest Krew release before your plugins are updated.

Searching for Plugins

The search command lets you browse the Krew package index from your terminal.

~$ kubectl krew search cert-manager

NAME DESCRIPTION INSTALLED

cert-manager Manage cert-manager resources inside your cluster no

Once you've found a plugin you're interested in, run the info command to find out more about it. This reveals the plugin's current version number, a link to its website, and a short description supplied by the author.

~$ kubectl krew info cert-manager

NAME: cert-manager

INDEX: default

URI: https://github.com/jetstack/cert-manager/releases/download/v1.7.0/kubectl-cert_manager-linux-amd64.tar.gz

SHA256: 73618617b9ec42994c3ea77bbc8be743e382501d42ad2ee7aeca0d32c15655c0

VERSION: v1.7.0

HOMEPAGE: https://github.com/jetstack/cert-manager

DESCRIPTION:

The official plugin accompanying cert-manger, a Kubernetes add-on to

automate the management and issuance of TLS certificates. Allows for

direct interaction with cert-manager resources e.g. manual renewal of

Certificate resources.

Using Custom Indexes

Krew supports custom indexes that facilitate plugin installation from your own sources. Indexes are simply Git repositories with a plugins folder containing YAML manifests. These files define the plugins that are available for installation. The structure of Krew's default index is a useful model when you're setting up your own.

To add an index, pass its repository URL to the index add command:

$ kubectl krew index add custom-index https://example.com/krew/index.git

To reference plugins in your index, prefix their names with your chosen index name:

$ kubectl krew install custom-index/example-plugin

When no prefix is given, Krew uses the default/ prefix instead. This always refers to Krew's built-in plugin index. If you'd prefer to direct unprefixed plugin names to your own index, set the KREW_DEFAULT_INDEX_URI environment variable to your repository's URL:

$ export KREW_DEFAULT_INDEX_URI="https://example.com/krew/index.git"

# Automatically resolved to the custom index

$ kubectl krew install example-plugin

Publishing Your Own Plugins

It's fairly straightforward to distribute your own plugins to users via Krew. First you need to create an archive of your Kubectl plugin's content, either as a .tar.gz or .zip file. Upload this to a publicly accessible location - your project's website or GitHub releases page are both good choices.

Write a Krew plugin manifest next. This is a simple YAML file which provides basic information about your plugin such as its name, description, and current version. The manifest also includes your plugin archive's public URL. When a user installs your plugin, Krew will fetch its archive from the URL specified in the manifest.

Once you've written your manifest, you can commit it to a Git repository. Add that repository as a custom Krew index to add your plugin to your Kubectl installation. Submissions to Krew's public index are accepted by creating a pull request to its repository that adds your manifest in the plugins directory.

Conclusion

Krew simplifies Kubernetes plugin discovery, installation, and management. It's a handy convenience tool for anyone using Kubectl plugins. Krew offers a full package management experience that includes custom private indexes for your internal tools.

The public index contains over 180 plugins covering all aspects of Kubernetes management. Some popular options include cert-manager, for working with Cert-Manager objects in your cluster, tail, offering simplified log streaming, score for static analysis of your objects, and ctx and ns to streamline switching between contexts and namespaces.