How to Set Up Krew Plugin Manager for kubectl
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 updatebefore installing new plugins. - Keep plugins updated with
kubectl krew upgrade. - Share a plugin list with your team for consistency.
Common Mistakes with krew plugin
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro