使用kubecm管理k8s多集群环境

最新版本地址查看

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安逸的程序猿

意思不意思那是你的意思我没意思

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值