Kubectl plugin that manages kubernetes contexts. It will create context in <namespace/<cluster>
format. Contexts for non-existent namespaces will be deleted (e.g., after you delete namespace with created context).
To switch contexts you can use kubectx or fzf (see instructions below). Once you have contexts created you will no longer need to use kubectx
with kubens
when accessing namespace in different cluster.
Info: This plugin is not in krew-index but for convenience I added krew manifest as installlation option..
-
Install plugin
- using krew manifest in this repository
$ kubectl krew install --manifest=deploy/krew/plugin.yaml
or
- using
Makefile
$ make bin
- using krew manifest in this repository
-
Use plugin
$ kubectl updatecontext
Add these lines into your .bashrc
or .zshrc
#fzf inline alias
alias _inline_fzf="fzf --multi --ansi -i -1 --height=50% --reverse -0 --header-lines=1 --inline-info --border"
#kubernetes contexts switcher
kcs() {
local context="$(kubectl config get-contexts | _inline_fzf | awk '{print $1}')"
eval kubectl config set current-context "${context}"
}
Now use kcs
within your terminal.
$ kcs