Sign In

Curriculum 24: Kubectl Plugins & Krew

Installing Krew

12 min · 35 XP

Installing Krew

Krew is the plugin manager for kubectl. It works like apt or brew but specifically for kubectl plugins, giving you access to over 200 community-maintained plugins.

Installation Steps

Install Krew by running the official installation script:

# macOS and Linux
(
  set -x; cd "$(mktemp -d)" &&
  OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -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
)

Setting Up PATH

After installation, add Krew's bin directory to your PATH:

# Add to ~/.bashrc or ~/.zshrc
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

# Reload your shell
source ~/.zshrc   # or source ~/.bashrc

Verifying the Installation

# Check that krew is working
kubectl krew version

# Update the plugin index
kubectl krew update

# List installed plugins
kubectl krew list

How Krew Works

Krew downloads plugin binaries and places them in ~/.krew/bin/. Since kubectl discovers plugins by looking for executables named kubectl-* on your PATH, adding the Krew bin directory makes all installed plugins immediately available.

# The plugin index is a git repository of plugin manifests
# Update it regularly to see new and updated plugins
kubectl krew update

Installing Your First Plugin

# Install the popular 'ctx' plugin for fast context switching
kubectl krew install ctx

# Now use it
kubectl ctx

Key Takeaways

  • Krew is installed via a shell script and lives in ~/.krew/
  • You must add ~/.krew/bin to your PATH for plugins to be discoverable
  • Run kubectl krew update regularly to refresh the plugin index
  • Plugins installed through Krew work as regular kubectl subcommands