Power tools for kubernetes : kubectx + kubens
kubectx is a tool to switch between contexts (clusters) on kubectl faster.
kubens is a tool to switch between Kubernetes namespaces (and configure them for kubectl) easily.
Stable versions of kubectx and kubens are small bash scripts that you can find in this repository. Starting with v0.9.0, kubectx and kubens are now rewritten in Go.
Repository: https://github.com/ahmetb/kubectx
You can install and use the Krew kubectl plugin manager to get kubectx and kubens.
kubectl krew install ctx
kubectl krew install nsAfter installing, the tools will be available as kubectl ctx and kubectl ns.
If you use Homebrew you can install like this:
brew install kubectxThis command will set up bash/zsh/fish completion scripts automatically. Make sure you configure your shell to load completions for installed Homebrew formulas.
Available as packages on Chocolatey
choco install kubens kubectxAvailable as packages on Scoop
scoop bucket add main
scoop install main/kubens main/kubectxSince kubectx and kubens are written in Bash, you should be able to install them to any POSIX environment that has Bash installed.
- Download the
kubectx, andkubensscripts. - Either:
- save them all to somewhere in your
PATH, - or save them to a directory, then create symlinks to
kubectx/kubensfrom somewhere in yourPATH, like/usr/local/bin
- save them all to somewhere in your
- Make
kubectxandkubensexecutable (chmod +x ...)
Example installation steps:
sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx
sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens# switch to another cluster that's in kubeconfig
$ kubectx minikube
Switched to context "minikube".
# switch back to previous cluster
$ kubectx -
Switched to context "oregon".
# rename context
$ kubectx dublin=gke_ahmetb_europe-west1-b_dublin
Context "gke_ahmetb_europe-west1-b_dublin" renamed to "dublin".
# change the active namespace on kubectl
$ kubens kube-system
Context "test" set.
Active namespace is "kube-system".
# go back to the previous namespace
$ kubens -
Context "test" set.
Active namespace is "default".
# change the active namespace even if it doesn't exist
$ kubens not-found-namespace --force
Context "test" set.
Active namespace is "not-found-namespace".
---
$ kubens not-found-namespace -f
Context "test" set.
Active namespace is "not-found-namespace".
No comments