Per-shell kubernetes contexts
kckn is a simple tool for managing per-shell Kubernetes contexts via
the KUBECONFIG
env var. Like
vital-software/kc, it “works
around the lack of a KUBECONTEXT environment
variable.”
PATH
-style (colon-separated) KUBECONFIG
values.. kc <cluster or cluster alias>
to set clusters; . kn <namespace or namespace alias>
to set namespaces; and. kc off
to revert changes made by kckn.You can define aliases to avoid typing the .
, e.g. alias
kc='. kc'
.
kc
and kn
scipts are on your PATH
.kc
and kn
both have bash completion support; to enable completion,
source this repo’s completion
file: source /path/to/kckn/completion
.
At the highest level, kckn generates ephemeral kubeconfigs whosecurrent-cluster
value is <one of your clusters>/<some namespace>
.
kckn starts by generating a small kubeconfig that defines a context
for your cluster/namespace/user combination. Then, kckn uses kubectl
to flatten that kubeconfig onto your base kubeconfig. The resulting
kubeconfig is written to a temporary file, and the path to that
temporary file becomes the value of your KUBECONFIG
shell
environment variable.
Several env vars can be used to add kckn information to your shell prompt:
env var | description |
---|---|
__KCKN |
<cluster>/<namespace> |
__KCKN_KUBE_CLUSTER |
<cluster> |
__KCKN_KUBE_NAMESPACE |
<namespace> |
env var | default value | description |
---|---|---|
KCKN_BASE_KUBECONFIG |
~/.kube/config |
path to your base kubeconfig file, which should contain all of the users and contexts that will be used in your cluster-namespace contexts |
KCKN_CLUSTER_ALIASES |
path to the simple file whose lines consist of <cluster alias> <cluster> pairs denoting short-names for cluste to be used with kc |
|
KCKN_NAMESPACE_ALIASES |
path to the simple file whose lines consist of <namespace alias> <namespace> pairs denoting short-names for namespaces to be used with kn |
|
KCKN_CLUSTER_USERS |
path to the simple file whose lines consist of <cluster> <user> pairs denoting which user is to be used with which cluster (by default, the user is assumed to be the same as the cluster name) |
|
KUBECONFIG
tools without