Krew is the official plugin manager for the kubectl command-line tool. Much like apt for Debian or Homebrew for macOS, it allows users to easily discover, install, and manage custom extensions that add new subcommands to Kubernetes.
Core Functionality
- Discovery: Users can search a community-curated index of over 200 plugins designed for tasks like security auditing, resource visualization, and cluster management.
- Lifecycle Management: It automates the process of installing, updating, and removing plugins across different operating systems (Linux, macOS, and Windows).
- Unified Interface: Once a plugin is installed via Krew, it is invoked directly through kubectl (e.g., kubectl <plugin-name>).
Installation
MacOS example output:
% (
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
)
+-zsh:142> mktemp -d
+-zsh:142> cd /var/folders/8j/60m6_18j359_39ls0sr9ccvm0000gp/T/tmp.LKDSyQcO10
+-zsh:143> OS=+-zsh:143> uname
+-zsh:143> OS=+-zsh:143> tr '[:upper:]' '[:lower:]'
+-zsh:143> OS=darwin
+-zsh:144> ARCH=+-zsh:144> uname -m
+-zsh:144> ARCH=+-zsh:144> sed -e s/x86_64/amd64/ -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/'
+-zsh:144> ARCH=arm64
+-zsh:145> KREW=krew-darwin_arm64
+-zsh:146> curl -fsSLO https://github.com/kubernetes-sigs/krew/releases/latest/download/krew-darwin_arm64.tar.gz
+-zsh:147> tar zxvf krew-darwin_arm64.tar.gz
x ./LICENSE
x ./krew-darwin_arm64
+-zsh:148> ./krew-darwin_arm64 install krew
Adding "default" plugin index from https://github.com/kubernetes-sigs/krew-index.git.
Updated the local copy of plugin index.
Installing plugin: krew
Installed plugin: krew
\
| Use this plugin:
| kubectl krew
| Documentation:
| https://krew.sigs.k8s.io/
| Caveats:
| \
| | krew is now installed! To start using kubectl plugins, you need to add
| | krew's installation directory to your PATH:
| |
| | * macOS/Linux:
| | - Add the following to your ~/.bashrc or ~/.zshrc:
| | export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
| | - Restart your shell.
| |
| | * Windows: Add %USERPROFILE%\.krew\bin to your PATH environment variable
| |
| | To list krew commands and to get help, run:
| | $ kubectl krew
| | For a full list of available plugins, run:
| | $ kubectl krew search
| |
| | You can find documentation at
| | https://krew.sigs.k8s.io/docs/user-guide/quickstart/.
| /
/
Add Krew path to PATHs:
% vi ~/.zshrc
% cat ~/.zshrc
...
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" <-- added manually
Reload .zshrc configuration file within the currently running Zsh terminal (or just restart the terminal):
% source ~/.zshrc
Installation verification:
% kubectl krew
krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."
Usage:
kubectl krew [command]
Available Commands:
help Help about any command
index Manage custom plugin indexes
info Show information about an available plugin
install Install kubectl plugins
list List installed kubectl plugins
search Discover kubectl plugins
uninstall Uninstall plugins
update Update the local copy of the plugin index
upgrade Upgrade installed plugins to newer versions
version Show krew version and diagnostics
Flags:
-h, --help help for krew
-v, --v Level number for the log level verbosity
Use "kubectl krew [command] --help" for more information about a command.
Common Commands
To use Krew, you must first install it as a kubectl plugin itself. Key commands include:
kubectl krew update: Updates the local list of available plugins.
kubectl krew search: Finds plugins in the official Krew index.
kubectl krew install <plugin>: Installs a specific plugin.
kubectl krew list: Displays all plugins currently installed through Krew.
kubectl krew upgrade: Updates all installed plugins to their latest versions.
Example:
% kubectl krew install deprecations
Updated the local copy of plugin index.
Installing plugin: deprecations
Installed plugin: deprecations
\
| Use this plugin:
| kubectl deprecations
| Documentation:
| https://github.com/rikatz/kubepug
| Caveats:
| \
| | * By default, deprecations finds deprecated object relative to the current kubernetes
| | master branch. To target a different kubernetes release, use the --k8s-version
| | argument.
| |
| | * Deprecations needs permission to GET all objects in the Cluster
| /
/
WARNING: You installed plugin "deprecations" from the krew-index plugin repository.
These plugins are not audited for security by the Krew maintainers.
Run them at your own risk.
Popular Plugins Managed by Krew
- ctx / ns: Rapidly switch between Kubernetes contexts and namespaces.
- tree: Visualizes the hierarchy of Kubernetes resources in a tree view.
- access-matrix: Displays an RBAC (Role-Based Access Control) matrix for server resources.
- get-all: Lists all resources in a namespace, including those often missed by kubectl get all.
Note on Security (!)
Plugins in the Krew index are community-contributed and are not audited for security by the Kubernetes maintainers; you should only install plugins from sources you trust.
---

No comments:
Post a Comment