This is the third day of my participation in Gwen Challenge

1 introduction

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.

2 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

3 the installation

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

3.1 MacOS

Use BREW or download binary executables directly

brew install sunny0826/tap/kubecm
Copy the code

The 3.2 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

3.3 Windows

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

4 Command 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/.zshrc
Copy the code

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

5 operating kubeconfig

5.1 check the

$HOME/. Kube /config context kubecm ls {17:29}~ ➭ kubecm ls +------------+-----------+-----------------------+--------------------+------------------------------+--------------+ | CURRENT | NAME | CLUSTER | USER | SERVER | Namespace | + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + | | LDF | cluster - f2mk9984gk | user - f2mk9984gk | | https://172.20.2.118:6443 default | +------------+-----------+-----------------------+--------------------+------------------------------+--------------+ | * | zstack | cluster - th9975gt2t | user - th9975gt2t | | https://10.234.2.11:6443 default | +------------+-----------+-----------------------+--------------------+------------------------------+--------------+ Cluster check succeeded! Kubernetes master is running at https://10.234.2.11:6443 Contains Components: [Scheduler controller-manager etcd-0]Copy the code

5.2 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

5.3 delete

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

5.4 combined

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

6 demonstrate