kubens
Switch easily between Kubernetes namespaces
TLDR
List the namespaces
Change the active namespace
Switch to the previous namespace
SYNOPSIS
kubens [<namespace>]
PARAMETERS
[NAMESPACE]
Target namespace to switch to. Omitting it launches interactive fuzzy-search menu.
-h, --help
Display help information and exit.
DESCRIPTION
kubens is a lightweight kubectl plugin designed to streamline switching between Kubernetes namespaces. It offers an intuitive interactive menu that lists all namespaces accessible in your current context, highlighting the active one with an asterisk (*). Users navigate with arrow keys, select with Enter, and cancel with Ctrl+C.
Direct switching is also supported by specifying a namespace: kubens my-namespace. This updates the namespace in your current kubeconfig context, affecting all subsequent kubectl commands without altering the context itself.
Unlike the verbose kubectl config set-context --current --namespace=<name>, kubens saves time in multi-namespace environments, such as development clusters with default, kube-system, and custom namespaces. It's part of the kubectx toolkit, enhancing Kubernetes CLI productivity for developers and operators managing complex setups.
CAVEATS
Requires kubectl and kubeconfig setup. Only modifies current context's namespace; install as plugin via Go, Homebrew, or binaries. Interactive mode unavailable in non-TTY environments.
INSTALLATION
brew install kubectx (includes kubens) on macOS/Linux.
go install github.com/ahmetb/kubectx/kubens@latest.
Add to PATH and ensure executable.
UNSET NAMESPACE
Run kubens interactively and select "(none)" or use kubectl config unset contexts.<current>.namespace.
HISTORY
Developed by Ahmet Imran as companion to kubectx. First released in 2018 under the kubectx GitHub project to address cumbersome namespace switching in Kubernetes CLI workflows. Gained popularity with Kubernetes adoption, now widely used via package managers.


