I want to introduce you two useful tools for kubernetes development, github link with detail.
Note: this is not an official Google product.
kubectx
kubectx
helps you switching between clusters back and forth.
Install
Since kubectx/kubens are written in Bash, you should be able to install them to any POSIX environment that has Bash installed.
1 | git clone https://github.com/ahmetb/kubectx /opt/kubectx |
Make sure kubectx script is executable:
1 | [root@myk8s1 ~] ls /opt/kubectx/ -ltr |
Create symlinks to kubectx/kubens from somewhere in your PATH, like /usr/local/bin
1 | ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx |
Usage
You should first understand how to switch among different clusters by using configuration files. please investigate this link, actually kubectx
is built on top of it.
For example, I have one cluster on AWS and one cluster on Fyre, in each cluster there is a ~/.kube/config
file, rename it as config.aws
and config.fyre
and put them to another client machine ~/.kube/
folder with kubectl installed.
1 | [root@centctl1 .kube]# ls -ltr |
Append config files to environment variable KUBECONFIG
, you can add export to .bashrc
file.
1 | export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config.aws:$HOME/.kube/config.fyre |
Now if you run kubectx
you will see there are 2 contexts:
1 | [root@centctl1 .kube] kubectx |
Jump to kubernetes-admin@kubernetes
:
1 | [root@centctl1 .kube] kubectx kubernetes-admin@kubernetes |
Jump back:
1 | [root@centctl1 .kube] kubectx - |
It is the same as you run below commands:
1 | kubectl config view |
kubens
kubens
helps you switch between Kubernetes namespaces smoothly, so you don’t need to add -n <namespace>
in every command.
Install
Download the same Github repository as kubectx
, add symlinks:
1 | ln -s /opt/kubectx/kubens /usr/local/bin/kubens |
Usage
1 | [root@myk8s1 ~] kubens |