preface

This project was born out of mergeKubeConfig project, the original purpose of writing this project is to switch freely in a bunch of chaotic Kubeconfig. With the need to operate more and more Kubernetes cluster, switching between different clusters is also more and more troublesome, and the essence of the operation of Kubernetes cluster is no more than through KubeconFig access to Kubernetes cluster API Server, To manipulate various resources in Kubernetes, while Kubeconfig is nothing more than a YAMl file that holds the key to accessing a cluster, the original mergeKubeConfig was nothing more than a Python script that manipulated yaml files. As Golang learned more, he wanted to rewrite the project, and Kubecm was born.

kubecm

Kubecm is written by Golang and supports Mac Linux and Windows platforms. Delete Rename Switch provides a useful interactive operation.

  • Add: Adds a new onekubeconfig$HOME/.kube/config
  • Completion: indicates the automatic command completion function
  • Delete: Deletes an existing onecontextTo provide interactive and specified deletion modes
  • Merge: Will be in the specified directorykubeconfigMerge into onekubeconfigfile
  • Rename: specifies a renamecontext, provides interactive and specified renaming methods
  • Switch: interactive switchingcontext

The installation

Kubecm supports Mac Linux and Windows platforms and is easy to install:

MacOS

Use BREW or download binary executables directly

brew install sunny0826/tap/kubecmCopy the code

Linux

Download the binary executable

# linux x86_64
curl -Lo kubecm.tar.gz https://github.com/sunny0826/kubecm/releases/download/v${VERSION}/kubecm_${VERSION}_Linux_x86_64.tar.gz
tar -zxvf kubecm.tar.gz kubecm
cd kubecm
sudo mv kubecm /usr/local/bin/Copy the code

Windows

Just download the binary executable and move the file to $PATH

Command line automatic completion

Kubecm provides the same automatic completion of the kubectl completion command (bash/ ZSH support)

For example, ZSH is added to $HOME/.zshrc

source <(kubecm completion zsh)Copy the code

Then use the source command to make it effective

source $HOME/.zshrcCopy the code

After that, enter Kubecm and press TAB to see the contents of the command line auto-completion

Operating kubeconfig

Kubecm can realize KubeconFig view, add, delete, merge, rename and switch

To view

$HOME/. Kube /config context kubecmCopy the code

add

# add example.yaml to $HOME/.kube/config.yaml Kubecm add -f example. Yaml # kubecm add -f example. Yaml -n test kubecm add -f example. Yaml -n test example.yaml -cCopy the code

delete

Kubecm delete my-context kubecm delete my-contextCopy the code

merge

# merge kubeconfig in test directory Kubecm merge -f test -c kubecm merge -f test -c kubecm merge -f test -c kubeconfigCopy the code

rename

Kubecm rename -o dev -n test # rename current-context to dev kubecm rename -n dev -cCopy the code

Results show

conclusion

The original intention of kubecm project is to learn Golang and get familiar with the use of client-Go. With the in-depth use of Kubecm, many functions have been added intermittently, and a formal project has been developed. Generally speaking, they are all amateur projects developed according to their own preferences. Welcome to communicate and discuss through the ISSUE.