Managing Multiple Kube Config Files:
TLDR:
# Make the folder for the kubeconfigs mkdir -p $HOME/.kube/contexts # Grab ctx and put it in $PATH sudo curl -sSLk https://hireryan.today/wp-content/uploads/2021/11/kubectx -o /usr/local/bin/ctx sudo chmod 700 /usr/local/bin/ctx sudo chown $USER /usr/local/bin/ctx # Add this to your bash or zsh rc KUBECONFIG="" BASE_PATH=$HOME/.kube/contexts for i in `\ls $BASE_PATH`; do export KUBECONFIG="$KUBECONFIG:$BASE_PATH/$i" done # Or this. This one is made to remove cert data from from both aws and rancher generated configs. Made for mac, should be portable though. KUBECONFIG="" BASE_PATH=$HOME/.kube/contexts for i in `\ls $BASE_PATH | grep yaml$`; do sed -i.bak '/certificate-authority/d' "$BASE_PATH/$i" sed -i.bak '/\\$/,/"/g' "$BASE_PATH/$i" grep certificate-authority "$BASE_PATH/$i" >/dev/null if ! [ $? = 0 ]; then grep insecure-skip-tls-verify "$BASE_PATH/$i" >/dev/null if ! [ $? = 0 ]; then sed -i.bak '/cluster:/s/.*/&\ insecure-skip-tls-verify: true/' "$BASE_PATH/$i" fi fi export KUBECONFIG="$KUBECONFIG:$BASE_PATH/$i" rm -f "$BASE_PATH/$i.bak" done # optional - fzf for easy select brew install fzf # To install useful key bindings and fuzzy completion: $(brew --prefix)/opt/fzf/install
I’m pretty sure I stole the core idea of this from someone else’s blog, but something didn’t work, or it was too convoluted.
The last shell based version of kucectx was
https://github.com/ahmetb/kubectx/releases/tag/v0.8.0
Or here as a non zip version:
https://hireryan.today/wp-content/uploads/2021/11/kubens
https://hireryan.today/wp-content/uploads/2021/11/kubectx