Last active
August 2, 2022 02:46
-
-
Save naingyeminn/902d586138f6400d3c4ef5d357758067 to your computer and use it in GitHub Desktop.
Switch K8S cluster context easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# run `kubeswitch` to list the contexts from .kube/config and set current context | |
# run `source <(kubeswitch)` to use the selected context in active shell environment only | |
# or add `alias kswitch='source <(kubeswitch)'` in ~/.bashrc | |
unset KUBECONFIG | |
select context in $(kubectl config get-contexts -o name); do | |
kubectl config use-context $context &> /dev/null | |
kubectl config view --minify --context $context --flatten > ${HOME}/.kube/$context.conf | |
chmod 600 ${HOME}/.kube/$context.conf | |
echo "export KUBECONFIG=${HOME}/.kube/$context.conf" | |
break | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment