Skip to content

How to Set Up Krew Plugin Manager for kubectl

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Set Up Krew Plugin Manager for kubectl. We cover key concepts, practical examples, and best practices.

The Problem

You try to install a kubectl plugin with Krew but get Error: plugin "some-plugin" not found, failed to install plugin: plugin download failed, or kubectl plugin-name returns error: unknown command. Krew manages kubectl plugins but configuration issues prevent installation and usage.

Quick Fix

Fix 1: Krew Not Installed

WRONG — trying to install a plugin without Krew:

kubectl krew install ctx
# command not found: kubectl-krew

RIGHT — install Krew:

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

# Add to PATH:
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

kubectl krew version
# OPTION   VALUE
# GitTag   v0.4.4

Fix 2: Plugin Index Outdated

kubectl krew install sniff
# Error: plugin "sniff" not found

RIGHT — update the plugin index:

kubectl krew update
# Updated the local and remote plugin index
# (plugins are now up to date)
kubectl krew install sniff
# Installed plugin: sniff

Fix 3: Plugin Download Failed

kubectl krew install ctx
# Installing "ctx" plugin...
# Error: failed to install plugin: failed to download plugin archive:
#   download "https://github.com/.../kubectx_linux_amd64.tar.gz": dial tcp: connection refused

RIGHT — check network connectivity and retry:

# Check if the download URL is reachable:
curl -I https://github.com/kubernetes-sigs/krew/releases/latest/download/krew.yaml
# If behind a proxy, set HTTP_PROXY:
export HTTP_PROXY=http://proxy:8080
export HTTPS_PROXY=http://proxy:8080

# Retry the installation:
kubectl krew install ctx

Fix 4: Plugin Not Found in PATH

kubectl ctx
# error: unknown command "ctx"

WRONG — Krew's bin directory is not in PATH:

echo $PATH
# /usr/local/bin:/usr/bin:/bin
# (~/.krew/bin is not included)

RIGHT — add Krew to PATH:

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
kubectl ctx
# (switches context successfully)

Make it permanent:

echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc

Fix 5: Plugin Already Installed

kubectl krew install ctx
# Error: plugin "ctx" is already installed

RIGHT — upgrade the plugin instead:

kubectl krew upgrade ctx
# Upgrading plugin "ctx"... done
# Or upgrade all plugins:
kubectl krew upgrade

Fix 6: List and Remove Plugins

kubectl krew list
# PLUGIN   VERSION
# ctx      v0.9.5
# ns       v0.9.5
# sniff    v1.6.1

kubectl krew uninstall sniff
# Uninstalling plugin "sniff"... done

Use DodaTech's Plugin Manager to discover, install, and update kubectl plugins across your team, ensuring everyone has consistent tooling.

Prevention

  • Install Krew from the official GitHub release.
  • Add Krew's bin directory to your shell profile permanently.
  • Run kubectl krew update before installing new plugins.
  • Keep plugins updated with kubectl krew upgrade.
  • Share a plugin list with your team for consistency.

Common Mistakes with krew plugin

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world K8S code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between Krew and kubectl plugins?

Krew is a plugin manager that installs and manages kubectl plugins. Plugins are standalone binaries that extend kubectl (e.g., kubectl ctx, kubectl sniff). Krew handles discovery, installation, and upgrades; plugins handle specific tasks.

How do I find useful kubectl plugins?

Run kubectl krew search to browse all available plugins. Popular plugins include ctx (switch contexts), ns (switch namespaces), sniff (capture pod network traffic), access-matrix (RBAC visualization), and score (security analysis).

Can I install a plugin manually without Krew?

Yes, download the binary and place it in any directory in your PATH with the name kubectl-<plugin>. For example, kubectl-ctx in /usr/local/bin. However, Krew makes installation, updates, and removal much easier.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro