Context names
So you’re working on multiple clusters and they don’t have meaningful names :
$ kubectl config get-contexts
CURRENT NAME CLUSTER
* some-cluster some-cluster
some-other-cluster some-other-cluster
yet-another-cluser yet-another-cluser
You can rename your contexts to make them more meaningful and easier to switch between them. Use kubectl config rename-context :
$ kubectl config rename-context some-cluster dev-cluster
Context "some-cluster" renamed to "dev-cluster".
And now the context names are more meaningful and it’s more simple to switch :
$ kubectl config get-contexts
CURRENT NAME CLUSTER
* dev-cluster some-cluster
staging-cluster some-other-cluster
prod-cluster yet-another-cluser
$ kubectl config use-context staging-cluster
Switched to context "staging-cluster".
kubectx and kubens
kubectx and kubens are two tools can make it even more simple to switch between contexts and active namespace. Super easy to install and use :
$ kubectx
dev-cluster
staging-cluster
prod-cluster
$ kubectx staging-cluster
✔ Switched to context "staging-cluster".
$ kubens
default
some-namespace
yet-another-namespace
$ kubens some-namespace
✔ Active namespace is "some-namespace"
oh my zsh
If you’re using zsh, you should try oh my zsh. Be sure to activate the kubectl plugin to enable several shortcut commands :
$ kgns
NAME STATUS AGE
default Active 50d
some-namespace Active 37d
yet-another-namespace Active 19d
Kubernetes debugging
You can start a one-off pod in a cluster to execute commands from inside the cluster. Here is an example with Ubuntu :
$ kubectl run my-ubuntu -ti --rm --image=ubuntu -- /bin/bash
If you don't see a command prompt, try pressing enter.
root@my-ubuntu:/#
Keywords : Kubernetes