Home

Awesome

<!-- omit in toc --> <p align="center"> <a href="https://github.com/DevOpsHiveHQ/kubech" style="display: block; padding: 1em 0;"> <img width="128px" alt="KubeZero Logo" border="0" src="./img/kubech-logo.svg"/> </a> </p> <h1 align="center">Kubech</h1> <p align="center"> Set kubectl contexts/namespaces per shell/terminal to manage multi Kubernetes clusters at the same time, like kubectx/kubens but per shell/terminal. </p> <!-- omit in toc -->

ToC

Why

Features

Install

Clone this repo, then source kubech in your shell config file.

git clone https://github.com/DevOpsHiveHQ/kubech ~/.kubech

Bash

echo 'source ~/.kubech/kubech' >> ~/.bashrc
echo 'source ~/.kubech/completion/kubech.bash' >> ~/.bashrc

Zsh

Completion for zsh with oh-my-zsh enabled.

echo 'source ~/.kubech/kubech' >> ~/.zshrc
ln -s ~/.kubech/completion/kubechn.zsh ~/.oh-my-zsh/completions/_kubechn.zsh
ln -s ~/.kubech/completion/kubechc.zsh ~/.oh-my-zsh/completions/_kubechc.zsh

Please make sure autoload -U compinit && compinit is added to ~/.zshrc if not please execute below command.

echo  'autoload -U compinit && compinit' >> ~/.zshrc

Usage

NOTE:
  - The command "kubech" is just a meta for other commands. So kubech does nothing by itself.
  - Also short names like "kchc/kchn/kchu" are available.

VARS:
  KUBECONFIG_SRC_DIR     : Set directory with extra kubectl config files to read in kubech commands.
                           This allow to have multiple config files in addition to
                           the one at "\$HOME/.kube/config".
                           Default: "$HOME/.kube/config.src.d"
  KUBECONFIG_DEST_DIR    : Set directory for temporary kubectl config files. The files
                           in this directory are auto-generated by kubech commands
                           and you don't need to interact with them or even change that var.
                           Default: "$HOME/.kube/config.dest.d"
  KUBECH_NAMESPACE_CHECK : Method used to check if namespace exists before switching to it.
                           The default lists all namespaces which can be slow in large
                           clusters. After kubernetes 1.22+ all namespaces have a label
                           that can be used to speed this up. Set to "label" to enable this.
                           Available options: "list", "label".
                           Default: "list"

USAGE:
  kubechc             : List all contexts
  kubechc <CONTEXT>   : Switch to context <CONTEXT>
  kubechn             : List all namespaces
  kubechn <NAMESPACE> : Switch to namespace <NAMESPACE>
  kubechu             : Unset the active context. This is just a safty net
                        to avoid applying config by mistake to the wrong cluster.

List available contexts

$ kubechc
k8s_cluster01
k8s_cluster02

Switch context

No need to write the full name, press tab for auto complete.

$ kubechc k8s_cluster01

List available namespaces

$ kubechn
default
kube-public
kube-system
monitoring

Switch namespace

No need to write the full name, press tab for auto complete.

$ kubechn monitoring

Notes

To-do