Skip to content

Instantly share code, notes, and snippets.

@jon-ruckwood
Created June 1, 2021 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-ruckwood/30c07fa7735802d9c4ea118a21dfe957 to your computer and use it in GitHub Desktop.
Save jon-ruckwood/30c07fa7735802d9c4ea118a21dfe957 to your computer and use it in GitHub Desktop.
Tips and tricks for Kubernetes

Kubernetes Tips & Tricks

Easier handling of multiple configurations

  1. Place configs under ~/.kube/contexts, i.e.
$ tree ~/.kube/contexts
/Users/jon/.kube/contexts
├── config-dev
├── config-prod
└── config-uat
  1. Set KUBECONFIG to include all files (separating each path using :)
echo 'export KUBECONFIG="$(ls -d ${HOME}/.kube/contexts/* | paste -sd ':' -)"' >>! ~/.zshenv
  1. Open a new session, check each cluster is resolved:
kubectl config get-clusters
NAME
dev
prod
uat

Easier switching between contexts

  1. Install krew, see - https://github.com/kubernetes-sigs/krew
  2. Use krew to install ctx (essentially this is kubectx):
$ kubectl krew install ctx
  1. List current contexts...
$ kubectl ctx
dev
prod
uat
  1. Switch context...
$ kubectl ctx uat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment