kubens
Switch easily between Kubernetes namespaces
TLDR
List the namespaces
Change the active namespace
Switch to the previous namespace
SYNOPSIS
kubens [NAMESPACE]
kubens -
kubens --current
kubens --set-default [NAMESPACE]
kubens --unset-default
kubens --help
kubens --version
PARAMETERS
[NAMESPACE]
Switches to the specified Kubernetes namespace. If omitted, lists all available namespaces in the current context.
- or --previous
Switches to the previously active Kubernetes namespace.
-c or --current
Displays the name of the currently active Kubernetes namespace.
--set-default [NAMESPACE]
Sets a default namespace that will be used for new contexts if no namespace is specified. If [NAMESPACE] is omitted, it sets the current namespace as default.
--unset-default
Removes the default namespace setting for new contexts.
-h or --help
Displays the help message and usage information for kubens.
-v or --version
Shows the version information of the kubens command.
DESCRIPTION
The kubens command is a powerful and convenient utility designed to simplify the process of switching between Kubernetes namespaces. It acts as a wrapper around the verbose kubectl config set-context
command, allowing users to rapidly change their active Kubernetes namespace with a single, intuitive command. By default, running kubens without any arguments lists all available namespaces in the current Kubernetes context, making it easy to discover and select the desired namespace.
This tool is widely used by developers and operations teams to improve workflow efficiency when working with multiple namespaces, eliminating the need to repeatedly type long kubectl
commands. It works by directly modifying the active context's namespace entry within your kubeconfig
file. Often installed as part of the kubectx project, kubens is an essential companion for anyone frequently interacting with Kubernetes clusters, streamlining the navigation across different logical environments or projects within a single cluster.
CAVEATS
kubens relies on a properly configured kubeconfig
file and an active Kubernetes context. It modifies the kubeconfig
file directly to change the namespace, so ensure appropriate permissions. It is not an official part of the kubectl
distribution and is typically installed as part of the kubectx project, meaning its availability depends on that installation.
<I>DEFAULT NAMESPACE CONFIGURATION</I>
The kubens command provides functionality to set or unset a default namespace for newly created or used Kubernetes contexts. Using --set-default [NAMESPACE] allows you to define a specific namespace that kubens will automatically apply when you switch to a context that does not have an explicit namespace defined, or when creating a new context. This can be incredibly useful for ensuring consistency across your environments, especially if you consistently work within a particular namespace across various clusters or projects. The --unset-default option removes this global default setting.
HISTORY
kubens was developed by Ahmet Alp Balkan as part of the kubectx project. It emerged from the need to streamline the frequent context and namespace switching operations that Kubernetes users perform daily, which were cumbersome using native kubectl config
commands. Released as an open-source tool, it quickly gained widespread adoption in the Kubernetes community due to its significant productivity improvements and user-friendly interface.
SEE ALSO
kubectx(1), kubectl(1), kubectl-config(1)