Kubernetes context per terminal session

If you are like me working with multiple kubernetes clusters it becomes really unhandy to work with them at the same time.

For a while I have been using ktx to manage that – however as mentioned above – at the moment of writing it sets context to be global.

So as a small workaround I have those 2 functions in my `.zshrc` file

k8ctx-switch() { 
# create a temp file for our config 
TEMP_CONFIG="$(mktemp "kubectx.$1")" 
kubectl config view --minify --flatten --context=$1 > $TEMP_CONFIG export KUBECONFIG="${TEMP_CONFIG}:${KUBECONFIG}" cat ${TEMP_CONFIG}

k8ctx-list() {
KUBECONFIG="${HOME}/.kube/config" kubectl config get-contexts

This is a MVP 🙂 to get multiple tabs opened with different k8s clusters to manage. Pretty handy 🙂