Right, so you’ve mastered the basic krab-ing (kubectl get), the art of the describe, and you can exec into a Pod in your sleep. Welcome to the big leagues. Now it’s time to talk about how to make this Swiss Army knife of a tool even more powerful. Because let’s be honest, while kubectl is brilliant, it’s also a bit… minimalistic by design. The creators wisely decided not to cram every single niche feature imaginable into the core tool. Instead, they gave us a plugin system, and the community—in its infinite, beautiful wisdom—built krew to manage it. Think of krew as Homebrew or apt-get, but specifically for extending your kubectl command.

The Plugin System: It’s Just a File in Your PATH

At its heart, the kubectl plugin system is so stupidly simple it’s genius. There’s no complex API, no registration process. If you have an executable file anywhere in your system’s PATH named kubectl-something, you can run it by typing kubectl something. That’s it. That’s the whole song and dance.

Go ahead, try it. Create a ridiculously simple plugin right now:

cat << EOF > ./kubectl-hello
#!/bin/bash
echo "Hello, k8s traveler! You are currently using context: \$(kubectl config current-context)"
EOF

chmod +x ./kubectl-hello
mv ./kubectl-hello /usr/local/bin/ # Or anywhere else on your PATH

Now, just run:

kubectl hello

You should see a friendly greeting and your current context. See? No magic. kubectl just found the executable kubectl-hello and ran it. This simplicity is its greatest strength. You can write a plugin in Bash, Python, Go, or even a compiled binary. As long as it’s executable and named correctly, it’s in the club.

Enter krew: The Plugin Manager You Actually Need

Now, the problem with the “just put a file in your PATH” approach is discovery and management. How do you find these plugins? How do you update them? Manually scouring GitHub is a recipe for madness. This is where krew swoops in like a superhero in a cape.

krew is itself a kubectl plugin (kubectl-krew) that provides a central index and a package manager for other plugins. It finds, downloads, installs, and updates plugins for you. It is, unequivocally, a must-have.

First, you have to install krew itself. The instructions are on the GitHub repo, but here’s the meat of it for Unix-like systems:

(
  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
)

Then, add krew to your PATH by adding this to your shell profile (.bashrc, .zshrc, etc.):

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

After a quick exec $SHELL or opening a new terminal, you’re in business.

Finding and Installing Must-Have Plugins

Now for the fun part. Use krew search to find plugins. Let’s say you’re tired of decoding kubectl get nodes -o json | jq ... to check node capacity:

krew search node
# You'll likely see a plugin called 'resource-capacity'

krew install resource-capacity

Now you can run:

kubectl resource-capacity

This gives you a beautiful, human-readable table of CPU and memory allocatable across your nodes. It’s a massive time-saver.

Another absolute banger is ctx and ns. Switching contexts and namespaces with kubectl config use-context and kubectl config set-context --current --namespace= is a chore. These plugins provide interactive menus:

krew install ctx ns
kubectl ctx  # Interactive menu to switch contexts
kubectl ns   # Interactive menu to switch namespaces in your current context

It’s the kind of quality-of-life improvement that makes you wonder how you ever lived without it. The designers of the core CLI were right to keep this out—it’s opinionated—but oh boy, is it necessary in practice.

The Dark Side: Security and Stability

Here’s the part where I have to be the brilliant but responsible friend: be careful. krew plugins are just executables that run with the same permissions as your kubectl (which is to say, your Kubernetes permissions). The krew index is curated, but it’s not impervious. You are implicitly trusting the plugin author.

  • Best Practice: Before you install a plugin with a million downloads, check its GitHub repo. When was it last updated? Are there open issues? Does the code look sane? Don’t just krew install random-plugin-from-a-stranger.
  • Stability: Plugins can break between kubectl versions. The maintainers try to keep up, but sometimes a change in the core CLI API will leave a plugin in the dust until its author updates it. If a core kubectl command is mission-critical for you, a plugin might not be the right tool for that job.
  • The --enable-alpha Flag: Some plugins require you to pass --enable-alpha to use them. This is a big, flashing warning sign that says “This plugin might set your cluster on fire in a way we didn’t anticipate.” Tread lightly.

So, use krew. It will make you exponentially more productive and your CLI experience infinitely more pleasant. But like any powerful tool, respect it. Understand that you’re venturing beyond the officially supported core, into the wild and wonderful world of open source. It’s mostly amazing, but it pays to keep your wits about you.