Kubectx and Kubens
Ahmet Balkan
- One minute read - 184 wordsManaging Kubernetes clusters in production often means juggling many namespaces and clusters. Relying solely on kubectl for context and namespace switching can quickly become a confusing and tedious process. The tools kubectx and kubens simplify this workflow by providing quick, intuitive commands to switch between clusters and namespaces without lengthy kubectl config calls.
Kubectx
With this tool, you don’t have to make use of lengthy kubectl config commands to switch between contexts. This tool is particularly useful for switching context between clusters in a multi-cluster environment.
Installation
sudo git clone https://github.com/ahmetb/kubectx /opt/kubectxsudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectxSyntax
To list all contexts:
kubectxTo switch to a new context:
kubectx <context_name>To switch back to the previous context:
kubectx -To see the current context:
kubectx -cKubens
This tool allows users to switch between namespaces quickly with a simple command.
Installation
sudo git clone https://github.com/ahmetb/kubectx /opt/kubectxsudo ln -s /opt/kubectx/kubens /usr/local/bin/kubensSyntax
To switch to a new namespace:
kubens <new_namespace>To switch back to the previous namespace:
kubens -