最新版本地址查看
https://github.com/sunny0826/kubecm/releases/
1.安装(如果下载不下来,手动下载,再上传到服务器)
[root@ecs--001 config]# curl -Lo kubecm_0.15.3_Linux_x86_64.tar.gz https://github.com/sunny0826/kubecm/releases/download/v0.15.3/kubecm_0.15.3_Linux_x86_64.tar.gz
[root@ecs--001 config]# tar -zxvf kubecm_0.15.3_Linux_x86_64.tar.gz
[root@ecs--001 config]# mv kubecm /usr/local/bin/
[root@ecs--001 config]# kubecm
Manage your kubeconfig more easily.
██ ██ ██ ██ ██████ ███████ ██████ ███ ███
██ ██ ██ ██ ██ ██ ██ ██ ████ ████
█████ ██ ██ ██████ █████ ██ ██ ████ ██
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██████ ███████ ██████ ██ ██
Tips Find more information at: https://kubecm.cloud
Usage:
kubecm [command]
Available Commands:
add Add KubeConfig to $HOME/.kube/config
alias Generate alias for all contexts
clear Clear lapsed context, cluster and user
completion Generates bash/zsh completion scripts
create Create new KubeConfig(experiment)
delete Delete the specified context from the kubeconfig
help Help about any command
list List KubeConfig
merge Merge the KubeConfig files in the specified directory
namespace Switch or change namespace interactively
rename Rename the contexts of kubeconfig
switch Switch Kube Context interactively
version Print version info
Flags:
--config string path of kubeconfig (default "/root/.kube/config")
-h, --help help for kubecm
Use "kubecm [command] --help" for more information about a command.
[root@ecs--001 config]#
2.文件合并
创建一个文件夹,把所有config拷贝过来,然后合并文件
[root@ecs--001 config]# mkdir kubecm_config
[root@ecs--001 config]# cp /root/.kube/* ./kubecm_config
[root@ecs--001 config]# kubecm merge -f kubecm_config
Loading KubeConfig file:kubecm_config/config
Add Context: config
Loading KubeConfig file:kubecm_config/config.124
👻 True
Rename: edge1█
Add Context: edge1
Loading KubeConfig file:kubecm_config/config.165
👻 True
Rename: edge4█
Add Context: edge4
Loading KubeConfig file:kubecm_config/config.edge2
👻 True
Rename: edge2█
Add Context: edge2
👻 True
「kubecm_config」 write successful!
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+===========+=======================+====================+===================================+==============+
| | config | cluster-b796g6fbkm | user-b796g6fbkm | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge1 | cluster-b4bmcm894b | user-b4bmcm894b | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge2 | cluster-btt95tm87c | user-btt95tm87c | https://6255668b-ae75-41b5-9ae | default |
| | | | | 4-f9d61a447457.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge4 | cluster-65hbbd6dbf | user-65hbbd6dbf | https://7e6b927f-a61b-4f2b-a86 | default |
| | | | | 3-906d63492126.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
[root@ecs--001 config]#
使用命令
切换集群
[root@ecs--001 ~]# kubecm switch
😸 Select:edge1
「/root/.kube/config」 write successful!
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+===========+=======================+====================+===================================+==============+
| | config | cluster-b796g6fbkm | user-b796g6fbkm | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| * | edge1 | cluster-b4bmcm894b | user-b4bmcm894b | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge2 | cluster-btt95tm87c | user-btt95tm87c | https://6255668b-ae75-41b5-9ae | default |
| | | | | 4-f9d61a447457.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge4 | cluster-65hbbd6dbf | user-65hbbd6dbf | https://7e6b927f-a61b-4f2b-a86 | default |
| | | | | 3-906d63492126.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
Switched to context 「edge1」
查看列表
[root@ecs--001 ~]# kubecm ls
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+===========+=======================+====================+===================================+==============+
| | config | cluster-b796g6fbkm | user-b796g6fbkm | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| * | edge1 | cluster-b4bmcm894b | user-b4bmcm894b | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge2 | cluster-btt95tm87c | user-btt95tm87c | https://6255668b-ae75-41b5-9ae | default |
| | | | | 4-f9d61a447457.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
| | edge4 | cluster-65hbbd6dbf | user-65hbbd6dbf | https://7e6b927f-a61b-4f2b-a86 | default |
| | | | | 3-906d63492126.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+--------------+
Cluster check succeeded!
Kubernetes version v1.14.3
Kubernetes master is running at https://4a2636ae-5064-4699-986a-9158759abcfe.local:8443
[Summary] Namespace: 9 Node: 4 Pod: 82
切换集群
[root@ecs--001 ~]# kubecm ns
🚀 Namespace: 1402902410003210241 is selected.
「/root/.kube/config」 write successful!
+------------+-----------+-----------------------+--------------------+-----------------------------------+------------------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+===========+=======================+====================+===================================+========================+
| | config | cluster-b796g6fbkm | user-b796g6fbkm | https://4a2636ae-5064-4699-986 | default |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+------------------------+
| * | edge1 | cluster-b4bmcm894b | user-b4bmcm894b | https://4a2636ae-5064-4699-986 | 1402902410003210241 |
| | | | | a-9158759abcfe.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+------------------------+
| | edge2 | cluster-btt95tm87c | user-btt95tm87c | https://6255668b-ae75-41b5-9ae | default |
| | | | | 4-f9d61a447457.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+------------------------+
| | edge4 | cluster-65hbbd6dbf | user-65hbbd6dbf | https://7e6b927f-a61b-4f2b-a86 | default |
| | | | | 3-906d63492126.local:8443 | |
+------------+-----------+-----------------------+--------------------+-----------------------------------+------------------------+
[root@ecs--001 ~]#
详细操作命令请查看https://asciinema.org/a/389595