A simple, easily extensible shell for navigating your kubernetes clusters
A shell wrapper for bash including aliases for kubectl that makes it easy to navigate between and execute commands on different kubernetes clusters and namespaces.
This script is designed to be as short and simple as possible and also easily extensible so you can make it your own without too much deep knowledge of bash.
Clone the repo and then make sure
k8shhas execute permissions:
chmod +x k8sh
Now you can execute k8sh!
Add to a PATH directory to execute anywhere.
k8sh will automatically look at your current kubectl configuration to determine your current kubernetes context and namespace.
k8sh automatically keeps track of the current context and namespace you are operating in. These are displayed when starting up k8sh and on the k8sh prompt.
To switch contexts:
To list available contexts:
To switch namespaces:
To list available namespaces:
NOTE: When changing the context, the change is made globally to kubectl as if you did a
kubectl config use-contextyourself. The namespace, however, is kept track of by k8sh. The standard
kubectlcommand is aliased to always include the namespace that is currently selected within k8sh.
As stated above, when inside of k8sh the standard
kubectlcommand is aliased to always include the namespace that is currently selected. k8sh also includes many other aliases to make accessing commonly used kubectl commands a snap.
k is an easy shorthand for
Shorthands for common actions
Instead of typing out
kubectl get pods/services/replicationcontrollers/etcyou can simply type the following aliases to get a list of those resources:
k(as well as
kubectl) commands support tab completion.
kcompletion requires bash-completion to be installed in order to function which in turn requires bash 4.1+.
Upgrading to Bash 4: https://itnext.io/upgrading-bash-on-macos-7138bd1066ba
Installing Bash Completion: https://davidalger.com/posts/bash-completion-on-os-x-with-brew/
On startup k8sh looks for a
.k8sh_extensionsfile in your home directory. If it is there, it loads it as an inline bash script so you can supply your own aliases and functions to execute within k8sh.
To force the extensions file to be reloaded while in a k8sh session you can run:
examples/k8sh_extensionsfor some examples of what extensions can do.