Skip to content
Simpler Cluster/User/Namespace switching for Kubernetes (featuring interactive mode and wildcard/fuzzy matching)
Go Shell Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
context Made it possible to use kubensx in the absence of "namespaces" access… Apr 29, 2018
spec 0.1.0 Jan 1, 2018
.editorconfig Initial Jan 1, 2018
.gitattributes Initial Jan 1, 2018
.gitignore Initial Jan 1, 2018
.travis.yml Bumped go version to 1.9 Jan 15, 2018 Added 0.2.0 release notes Apr 29, 2018
Gopkg.lock Upgraded survey Apr 29, 2018
Makefile 0.1.0 Jan 1, 2018
kubensx.go Renamed config-ns to ns-list Apr 29, 2018

kubensx Latest Version Build Status

Simpler Cluster/User/Namespace switching for Kubernetes
(featuring interactive mode and wildcard/fuzzy matching (among other things)).


In short, instead of

kubectl config get-clusters
kubectl config view -o=go-template --template=$'{{range $u := .users}}{{$}}\n{{end}}'
kubectl get --cluster=<cluster> --user=<user> namespaces
kubectl config set-context <context_name> --cluster=<cluster> --user=<user> --namespace=<namespace>
kubectl config use-context <context_name>

context can be changed with kubensx use user:cluster/namespace or simply kubensx use (interactive).


macOS / Linux

curl -sSL$(
    bash -c '[[ $OSTYPE == darwin* ]] && echo darwin || echo linux'
  )-amd64 -o kubensx && chmod a+x kubensx && sudo mv kubensx /usr/local/bin/

Verify PGP signature (optional but recommended):

curl -sSL$(
    bash -c '[[ $OSTYPE == darwin* ]] && echo darwin || echo linux'
  )-amd64.asc -o kubensx.asc
curl -sS | gpg --import
gpg --verify kubensx.asc /usr/local/bin/kubensx

macOS: gpg can be installed with brew install gnupg


Download executable from the Releases page.


# change <user>:<cluster>/<namespace> (interactive)
$ kubensx use
# change <namespace> only (interactive)
$ kubensx use -n

# switch to <user>:<cluster>/<namespace> 
$ kubensx use minikube:minikube/default
# switch to a different <namespace> within current <cluster> (<user> stays the same)
$ kubensx use kube-public

# context matching is wildcard-ish by default, which means you don't have to type the whole thing
# if there are two or more options available - you'll be asked to select one
$ kubensx use west/def
Switched to
# prefer fuzzy?
$ kubensx use -z us1/dfl
Switched to

# switch to previous context
$ kubensx use -

# print current context
$ kubensx current

# list <user>s
$ kubensx ls -u
# list <cluster>s
$ kubensx ls -c
# list <namespace>s (inside current <cluster>)
$ kubensx ls -n

(for more information see kubensx --help)

User <-> Cluster assoc[iation]

By default, any <user> can be used with any <cluster>.
If you want to restrict (assoc[iate]) certain user(s) to some of the clusters use

$ kubensx assoc

For example: if you have a "minikube" user which you only use in the context of local "minikube" cluster, you may want to kubensx assoc minikube:minikube (<user>:<cluster>) so that "minikube" wouldn't be shown among the users for any cluster other than "minikube" (when kubesec useing).

Access Control

If a user is not allowed to list namespaces, you can either provide a list of namespaces known to that user with ns-list

$ kubensx ns-list
# make default, kube-system and kube-public namespaces known to current user in us-west1 cluster
$ kubensx ns-list us-west1/{default,kube-system,kube-public}
$ kubensx use west/def
Switched to

or use --force(-f) to suppress namespace validation (namespace will have to be provided --exact|ly)

$ kubensx use west/default --force
Switched to

Tab completion

# bash
$ source <(kubensx completion bash)

# zsh
$ source <(kubensx completion zsh)



git clone $GOPATH/src/
cd $GOPATH/src/
make fetch

go run kubensx.go


All code, unless specified otherwise, is licensed under the MIT license.
Copyright (c) 2018 Stanley Shyiko.

You can’t perform that action at this time.