Kubesel (kubeconfig selector) is your modern approach to working with kubectl configuration in a multi-cluster, multi-namespace environment. Quickly and easily change your active kubectl context, namespace, and cluster through a single program.
Designed from the ground up using the KUBECONFIG environment variable,
kubesel creates and manages a unique kubeconfig file for each shell session.
If you change your cluster in one pane, it won't affect the other pane where
you were planning on running kubectl delete.
Table of Contents:
go install github.com/eth-p/kubeselnix profile install github:eth-p/kubeselFor kubesel to set contexts/namespaces per shell, it needs to be able to
generate and manage a kubeconfig file associated with specific instances
of the shell. To do this, kubesel init creates a shell script that
will generate the file and update the KUBECONFIG environment variable.
While you can run the command manually, it is highly recommended to set
up your .profile/.rc files to automatically run it whenever a new
interactive shell is created. Doing it this way eliminates the risk of multiple
shells accidentally sharing the same kubesel-managed kubeconfig file.
Note
The KUBECONFIG environment variable should be set before kubesel init
is run.
Bash
Add this to ~/.bash_profile:
if [[ $- = *i* ]]; then
source <(kubesel init bash)
fiZsh
Add this to ~/.zshrc:
source <(kubesel init zsh)Fish
Add this to ~/.config/fish/config.fish:
if status is-interactive
kubesel init fish | source
end- Per-shell context (cluster, user, and namespace).
- Supports bash, zsh, and fish.
- Shell completions.
- Fuzzy matching contexts/clusters/users/namespaces.
- A fzf interface for picking contexts/clusters/users/namespaces.
- Preserves OIDC authentication refresh tokens.
- Shell-scripting friendly
listsubcommand. - Manual pages.
- Fancy ANSI colors! (optional)
Change Cluster, User, or Namespace:
kubesel cluster my-cluster # use this cluster
kubesel user my-user # use this user
kubesel namespace my-namespace # use this namespaceChange Cluster, User, and Namespace:
# Use the cluster, user, and namespace from this context.
kubesel context my-context
kubesel context my-context -n # keep the current namespaceView Contexts, Clusters, Users, or Namespaces:
kubesel list clusters
kubesel list contexts
kubesel list users
kubesel list namespacesThe kubesel list command supports changing its output format with --output.
Supported formats are:
listfor just the names in an unsorted listtablefor a tablecolfor columnscol=COL1,COL2for specific columnscol=*for all columns
If you keep each cluster in a different kubeconfig file, you can have kubesel automatically include them during initialization:
ls ~/.kube/configs
# prod.yaml
# staging.yaml
# dev.yaml
# kind-myapp.yaml
# Use the `--add-kubeconfigs` flag to include them with a glob pattern.
kubesel init --add-kubeconfigs='~/.kube/configs/*.yaml'https://github.com/ahmetb/kubectx
- ✅ Shell completions.
- ✅ Fuzzy-finding.
⚠️ Changes affect all shells.
https://github.com/Ramilito/kubesess
- ✅ Per-shell cluster/namespace/context.
- ✅ Fuzzy-finding.
⚠️ Does not support OIDC refresh tokens.
https://github.com/eth-p/fish-kubeswitch
- ✅ Per-shell cluster/namespace/context.
- ✅ Shell completions.
⚠️ Only supports fish shell.⚠️ Wraps kubectl as a shell function.
no_init_completions
Removes shell completion loading from thekubesel initscripts.