A zsh plugin to switch via KUBECONFIG env variable between kubectl config files located in ~/.kube/
I have different kubectl config files in my ~/.kube
directory and I swtich to them by terminal window for different profile.
kubectl-config-switch (kcs) help you moving between them with fzf. The last used config is always a ENTER away.
- Load the plugin with your favourite zsh plugin manager or simply source the kubectl-config-switcher.plugin.zsh file
- use the
kcs
command and it will ask which profile to choose withfzf
- you can do a
kcs -l
to simply just list the profiles - you can do a
kcs -L
to set it to the last kubeconfig that was chosen previously.
- fzf
- kubectl
- some kubernetes config files in
~/.kube
named as~/.kube/config.${PROFILE_NAME}
the KCS_PROFILE
env variable is exported so you can show it nicely in your prompt, for example with powerlevel9/10k add this to your configuration :
typeset -g POWERLEVEL9K_KUBECONTEXT_DEFAULT_CONTENT_EXPANSION='%F{13}${${${:-$KCS_PROFILE}:-$P9K_KUBECONTEXT_CLUSTER}}%f'
POWERLEVEL9K_KUBECONTEXT_DEFAULT_CONTENT_EXPANSION+='/%F{3}${${:-$P9K_KUBECONTEXT_NAMESPACE}:-default}%f'
it will look like this :