Practical Guide – kubectx & kubens
Managing multiple Kubernetes clusters and namespaces with plain kubectl can get repetitive.
Two handy tools – kubectx and kubens – simplify switching contexts and namespaces.
1. 🔧 Installation
Linux / macOS
Windows (with Chocolatey)
2. ⚙️ Setup & Verify
Ensurekubectl works with clusters:
3. 🧭 Usage
🔄 Switch Contexts (kubectx)
- List available contexts:
- Switch to a context:
- Rename a context:
- Switch back to previous context:
📂 Switch Namespaces (kubens)
- List all namespaces:
- Switch to namespace:
- Switch back to previous namespace:
4. 📑 Common Workflows
Example: Change Context + Namespace
kubectl commands run in production cluster, payments namespace.
5. 🎨 Bonus Features
- Fuzzy search support if
fzfis installed → lets you pick context/namespace interactively.
- Works seamlessly with
k9s→ if you already use it.
6. ✅ Summary
kubectx→ switch between clusters/contexts easily.kubens→ switch between namespaces quickly.- Both save time and reduce human error vs typing full
kubectl configcommands.
⚡ These tools are must-haves for anyone managing multiple Kubernetes clusters/namespaces daily.
