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:

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.

Now you should be able to use Krew via the 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:

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.

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:

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.

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

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

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

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

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.

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.

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:

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

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:

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.