Kubectx and kubens are companion command-line utilities that change kubectl cluster contexts and namespaces quickly. They also support isolated or read-only shells per context.
Overview
The kubectx utility switches among kubeconfig contexts so operators can jump between Kubernetes clusters without editing config files by hand. It can return to the previous context, rename contexts, and spawn shells limited to a single context, including read-only shells that block write operations.
Kubens adjusts the active namespace kubectl uses. It can revert to the prior namespace and force a namespace selection even when that namespace is not present yet.
Both tools integrate with fzf when it is installed, offering an interactive menu and fuzzy search over long context names. Tab completion is available on bash, zsh, and fish. Output colors can be tuned with environment variables or disabled entirely.
Installation paths include common package managers on Linux, macOS, and Windows, kubectl krew plugins, or standalone binaries added to PATH. They are designed as power tools alongside standard kubectl workflows.
Key features
- Quick kubectl context switching
- Namespace changes via kubens
- Previous context and namespace recall
- Isolated and read-only context shells
- fzf interactive fuzzy selection
- Shell tab completion support
- Configurable terminal color output
- Context rename in kubeconfig
Use cases
- Managing many Kubernetes clusters locally
- Rapid namespace changes during debugging
- Safer exploration in read-only shells
- Shortening long kube context names