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.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cli
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
CHANGELOG.md Added 0.2.0 release notes Apr 29, 2018
Gopkg.lock Upgraded survey Apr 29, 2018
Gopkg.toml
Makefile 0.1.0 Jan 1, 2018
README.md
kubensx.go Renamed config-ns to ns-list Apr 29, 2018

README.md

kubensx Latest Version Build Status

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

asciicast

In short, instead of

kubectl config get-clusters
kubectl config view -o=go-template --template=$'{{range $u := .users}}{{$u.name}}\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).

Installation

macOS / Linux

curl -sSL https://github.com/shyiko/kubensx/releases/download/0.2.0/kubensx-0.2.0-$(
    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 https://github.com/shyiko/kubensx/releases/download/0.2.0/kubensx-0.2.0-$(
    bash -c '[[ $OSTYPE == darwin* ]] && echo darwin || echo linux'
  )-amd64.asc -o kubensx.asc
curl -sS https://keybase.io/shyiko/pgp_keys.asc | gpg --import
gpg --verify kubensx.asc /usr/local/bin/kubensx

macOS: gpg can be installed with brew install gnupg

Windows

Download executable from the Releases page.

Usage

# 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 account@possibly-gmail.com:us-west1/default
# prefer fuzzy?
$ kubensx use -z us1/dfl
Switched to account@possibly-gmail.com:us-west1/default

# switch to previous context
$ kubensx use -

# print current context
$ kubensx current
minikube:minikube/default

# 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 account@possibly-gmail.com:us-west1/default

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

$ kubensx use west/default --force
Switched to account@possibly-gmail.com:us-west1/default

Tab completion

# bash
$ source <(kubensx completion bash)

# zsh
$ source <(kubensx completion zsh)

Development

PREREQUISITE: go1.9+.

git clone https://github.com/shyiko/kubensx $GOPATH/src/github.com/shyiko/kubensx
cd $GOPATH/src/github.com/shyiko/kubensx
make fetch

go run kubensx.go

Legal

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.