Getting started
Introduction
Krew is the official kubectl plugin manager developed by Kubernetes SIG CLI. It provides access to over 200 kubectl plugins with simple installation and upgrade workflows.
- Version: v0.4.5 (March 2025)
- Requirements: kubectl v1.12+
- Platforms: macOS, Linux, Windows
Installation (macOS/Linux)
# One-line installation
(
set -x; cd "$(mktemp -d)" &&
OS="$(uname | tr '[:upper:]' '[:lower:]')" &&
ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -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
)
PATH Configuration
# bash/zsh - add to ~/.bashrc or ~/.zshrc
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# fish - add to ~/.config/fish/config.fish
set -gx PATH $PATH $HOME/.krew/bin
# Apply changes
exec $SHELL
After installation, restart your shell or source your profile.
Quick Start
# Update plugin index
kubectl krew update
# Search for plugins
kubectl krew search
# Install essential plugins
kubectl krew install ctx ns stern
# List installed plugins
kubectl krew list
# Upgrade all plugins
kubectl krew upgrade
Core Commands
Plugin Management
# Update plugin index
kubectl krew update
Updates the local plugin index (does NOT upgrade plugins).
# Install plugins
kubectl krew install access-matrix
kubectl krew install ctx ns stern
Install one or multiple plugins.
# Upgrade plugins
kubectl krew upgrade
kubectl krew upgrade <PLUGIN>
Upgrade all or specific plugin.
# Uninstall plugins
kubectl krew uninstall access-matrix
Discovery
# List all available plugins
kubectl krew search
# Search by keyword
kubectl krew search log
kubectl krew search rbac
# Show plugin details
kubectl krew info stern
# List installed plugins
kubectl krew list
Information
# Show krew version
kubectl krew version
# Show plugin information
kubectl krew info <PLUGIN>
Displays description, version, homepage.
Backup & Restore
# Backup installed plugins
kubectl krew list | tee krew-backup.txt
# Restore on another machine
kubectl krew install < krew-backup.txt
Popular Plugins
Essential Tools
| Plugin | Description |
|---|---|
ctx |
Switch between contexts (kubectx) |
ns |
Switch namespaces (kubens) |
stern |
Multi-pod log tailing |
tree |
Show resources in tree format |
neat |
Remove clutter from YAML output |
Debugging & Logs
| Plugin | Description |
|---|---|
tail |
Stream logs from multiple pods |
logs |
Advanced log filtering |
debug-shell |
Debug pods with shell access |
sniff |
Packet capture for pods |
RBAC & Security
| Plugin | Description |
|---|---|
access-matrix |
Show RBAC access matrix |
whoami |
Show current user info |
view-secret |
Decode and view secrets |
rbac-lookup |
Reverse lookup for RBAC |
Resource Management
| Plugin | Description |
|---|---|
resource-capacity |
Show resource usage |
get-all |
Get all resources in namespace |
sick-pods |
Find problematic pods |
outdated |
Find outdated images |
See full list at krew.sigs.k8s.io/plugins
Configuration
Default Directories
| Path | Purpose |
|---|---|
$HOME/.krew |
Installation directory |
$HOME/.krew/bin |
Plugin executables |
$HOME/.krew/index |
Plugin index repository |
$HOME/.krew/store |
Downloaded plugin archives |
Environment Variables
# Custom installation directory
export KREW_ROOT=/opt/krew
# Custom plugin index
export KREW_DEFAULT_INDEX_URI='git@github.com:foo/custom-index.git'
# Proxy configuration
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1
Windows Installation
- Download
krew.exefrom GitHub releases - Run Command Prompt as Administrator
- Execute
krew.exe install krew - Add
%USERPROFILE%\.krew\binto PATH
Note: Administrator rights required for symbolic link creation.
Troubleshooting
PATH Not Configured
Symptom: kubectl: command 'krew' not found
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
# Restart shell
exec $SHELL
Plugin Not Found After Install
Symptom: kubectl: unknown command "plugin-name"
# Verify plugin installed
kubectl krew list
# Check PATH includes krew
echo $PATH | grep krew
# List krew executables
ls -la ~/.krew/bin/
Fix: Ensure ~/.krew/bin is in PATH and restart shell.
Network Proxy Issues
# Configure proxy
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
export NO_PROXY=localhost,127.0.0.1
# Update index through proxy
kubectl krew update
kubectl Version Incompatibility
Requirement: kubectl v1.12 or later
# Check kubectl version
kubectl version --client --short
# Upgrade kubectl (macOS)
brew upgrade kubernetes-cli
# Upgrade kubectl (Linux)
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
Windows Symbolic Link Errors
Symptom: Installation fails with permission errors
Fix: Run Command Prompt or PowerShell as Administrator
Plugin Update Confusion
Issue: kubectl krew update doesn't upgrade plugins
Solution:
kubectl krew update→ Updates plugin indexkubectl krew upgrade→ Upgrades installed plugins
Two separate commands by design.
Plugin Development
Plugin Manifest Structure
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: restart
spec:
version: "v0.0.1"
homepage: https://github.com/example/kubectl-restart
shortDescription: "Restarts a pod"
description: |
Restarts a pod by deleting and
recreating it.
platforms:
- selector:
matchExpressions:
- key: "os"
operator: "In"
values:
- darwin
- linux
uri: https://github.com/example/kubectl-restart/archive/v0.0.3.zip
sha256: d7079b79bf4e10e55ded435a2e862efe310e019b6c306a8ff04191238ef4b2b4
files:
- from: "kubectl-restart-*/restart.sh"
to: "./restart.sh"
bin: restart.sh
Supported Platforms
| OS | Architectures |
|---|---|
darwin |
amd64, arm64 |
linux |
amd64, 386, arm, arm64, ppc64le |
windows |
amd64, 386 |
Archive Formats: .zip, .tar.gz
Windows Limitation: Only .exe executables (no .bat or .ps1)
Publishing Plugins
- Create plugin manifest (
.yamlfile) - Test locally with custom index
- Submit PR to kubernetes-sigs/krew-index
- Follow contribution guidelines
- Wait for review and merge
Custom Plugin Indexes
# Use custom index
export KREW_DEFAULT_INDEX_URI='git@github.com:foo/custom-index.git'
kubectl krew update
Useful for private plugin repositories.
Architecture
Self-hosting Model
Krew is itself a kubectl plugin managed by Krew:
# Krew manages itself
kubectl krew upgrade krew
Bootstrap problem solved by initial installation script.
Plugin Execution
- Krew creates symbolic links in
~/.krew/bin/ - Links named
kubectl-<plugin>(e.g.,kubectl-ctx) - kubectl discovers plugins in PATH automatically
- Run as
kubectl <plugin>(e.g.,kubectl ctx)
Naming Conventions
| Plugin Name | Executable | Command |
|---|---|---|
ctx |
kubectl-ctx |
kubectl ctx |
view-secret |
kubectl-view_secret |
kubectl view-secret |
Note: Dashes in plugin names become underscores in executable names.
Directory Structure
$HOME/.krew/
├── bin/ # Symbolic links to plugins
├── index/ # Git clone of plugin index
├── receipts/ # Installation metadata
└── store/ # Downloaded plugin archives
Best Practices
Regular Maintenance
# Weekly: Update plugin index
kubectl krew update
# Monthly: Upgrade installed plugins
kubectl krew upgrade
Backup Strategy
# Before major system changes
kubectl krew list > ~/krew-plugins-$(date +%F).txt
# Restore
kubectl krew install < ~/krew-plugins-2026-02-04.txt
Security Considerations
- Plugins run with your kubectl credentials
- Review plugin source before installation
- Install only from trusted sources
- Check plugin manifest for suspicious URLs
- Audit installed plugins periodically
# Review plugin details before installing
kubectl krew info <plugin>
Plugin Discovery
# Search before installing
kubectl krew search <keyword>
# Read plugin description
kubectl krew info <plugin>
# Check plugin homepage
kubectl krew info <plugin> | grep homepage
Version Pinning
Krew doesn't support version pinning. Always installs latest version.
Workaround: Fork plugin repository and use custom index.
Quirks & Gotchas
Update vs Upgrade Confusion
kubectl krew update # Updates plugin INDEX only
kubectl krew upgrade # Upgrades INSTALLED plugins
Gotcha: update does NOT upgrade your plugins. You must run upgrade separately.
Shell Restart Required
After installation:
# Required for PATH changes
exec $SHELL
# Or source profile manually
source ~/.bashrc
Gotcha: Plugins won't be available until shell is restarted.
Windows Administrator Required
- Windows requires Administrator rights for symbolic link creation
- Not needed on macOS/Linux
Gotcha: Installation fails without admin rights on Windows.
Plugin Name vs Command Name
# Plugin name in krew
kubectl krew install ctx
# Command name (no 'krew')
kubectl ctx
Gotcha: Don't run kubectl krew ctx — it's just kubectl ctx.
Plugin Updates Don't Auto-Run
Krew doesn't auto-upgrade plugins.
Workaround: Set up weekly cron job:
# Add to crontab
0 9 * * 1 kubectl krew upgrade
No Version Pinning
Krew always installs latest plugin version.
Workaround: Use custom plugin index with pinned versions.
Useful Workflows
Fresh System Setup
# 1. Install krew (run installation script)
# 2. Add to PATH
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# 3. Update index
kubectl krew update
# 4. Install essential plugins
kubectl krew install \
ctx \
ns \
stern \
neat \
tree \
whoami \
view-secret \
access-matrix
Migration to New Machine
# On old machine
kubectl krew list > krew-plugins.txt
# Copy krew-plugins.txt to new machine
# On new machine (after installing krew)
kubectl krew update
kubectl krew install < krew-plugins.txt
Clean Uninstall
# 1. Uninstall all plugins
kubectl krew uninstall $(kubectl krew list | awk '{print $1}')
# 2. Remove krew directory
rm -rf ~/.krew
# 3. Remove from PATH
# Edit ~/.bashrc or ~/.zshrc and remove krew PATH line
# 4. Restart shell
exec $SHELL
Audit Installed Plugins
# List installed plugins with details
kubectl krew list | while read plugin _; do
echo "=== $plugin ==="
kubectl krew info "$plugin" | grep -E "(DESCRIPTION|HOMEPAGE)"
done
Offline Plugin Installation
# 1. Download plugin archive manually
curl -LO https://github.com/user/plugin/archive/v1.0.0.tar.gz
# 2. Create custom manifest
# 3. Install from custom index
# Note: Krew doesn't support direct file installation
Limitation: Krew requires Git-based indexes.
Examples
Context & Namespace Switching
# Install ctx and ns plugins
kubectl krew install ctx ns
# Switch context
kubectl ctx minikube
# Switch namespace
kubectl ns kube-system
# List contexts
kubectl ctx
# List namespaces
kubectl ns
Multi-Pod Log Tailing
# Install stern
kubectl krew install stern
# Tail logs from all pods matching pattern
kubectl stern myapp
# Tail with filters
kubectl stern myapp --since 15m
kubectl stern myapp --container nginx
kubectl stern myapp --namespace prod
Clean YAML Output
# Install neat
kubectl krew install neat
# Get pod YAML without clutter
kubectl get pod mypod -o yaml | kubectl neat
# Remove managed fields
kubectl get deploy -o yaml | kubectl neat
RBAC Access Matrix
# Install access-matrix
kubectl krew install access-matrix
# Show access matrix for current user
kubectl access-matrix
# Show for specific user
kubectl access-matrix --as user@example.com
# Show for service account
kubectl access-matrix --as system:serviceaccount:default:mysa
View Decoded Secrets
# Install view-secret
kubectl krew install view-secret
# View all keys in secret
kubectl view-secret mysecret
# View specific key
kubectl view-secret mysecret -k password
# Decode to file
kubectl view-secret mysecret -k cert > cert.pem
Resource Tree View
# Install tree
kubectl krew install tree
# Show resource tree
kubectl tree deployment myapp
kubectl tree service myapp
kubectl tree namespace prod
Also see
- Krew Official Documentation - Official Krew docs
- Krew Plugin Directory - All available plugins
- Krew GitHub Repository - Source code
- Krew Plugin Development Guide - How to create plugins
- kubectl Cheatsheet - kubectl command reference