kubectl-manage-multiple-k8s-cluster
本文最后更新于:2024年8月9日 晚上
Usually when we execute
kubectl
command it will load default k8s configuration from$HOME/.kube/config
But what if we have multiple k8s cluster, How we gonna manage them at same time ?
if we have on-premise k8s and azure k8s:
- KUBECONFIG
1 |
|
- kubecm
https://github.com/sunny0826/kubecm1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49[root@node1 ~]# wget https://github.com/sunny0826/kubecm/releases/download/v0.21.0/kubecm_v0.21.0_Linux_x86_64.tar.gz
[root@node1 ~]# tar -zxvf kubecm_v0.21.0_Linux_x86_64.tar.gz
[root@node1 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@node1 ~]# mv kubecm /usr/local/sbin
[root@node1 ~]# kubecm merge -f k8s-configs/ -c
Loading kubeconfig file: [k8s-configs//aksconfig k8s-configs//k8sconfig]
Context Add: aksconfig
Context Add: k8sconfig
[root@node1 ~]# kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
aks aks clusterUser_azarclab_aks arc
* onpremises kubernetes kubernetes-admin
[root@node1 ~]# kubecm version
Version: 0.21.0
GoOs: linux
GoArch: amd64
[root@node1 ~]# kubecm list
+------------+--------------+-----------------------+--------------------+-----------------------------------+--------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+==============+=======================+====================+===================================+==============+
| | aksconfig | cluster-9hdtmk5k4h | user-9hdtmk5k4h | https://xxxxxxxxxxxxxxxx.hcp.e | arc |
| | | | | astus.azmk8s.io:443 | |
+------------+--------------+-----------------------+--------------------+-----------------------------------+--------------+
| * | k8sconfig | cluster-c5bdhf8kc6 | user-c5bdhf8kc6 | https://10.157.21.24:6443 | default |
+------------+--------------+-----------------------+--------------------+-----------------------------------+--------------+
Cluster check succeeded!
Kubernetes version v1.20.7
Kubernetes master is running at https://10.157.21.24:6443
[Summary] Namespace: 8 Node: 3 Pod: 40
[root@node1 ~]# kubectl config use-context
aks onpremises
[root@node1 ~]# kubectl config use-context aks
Switched to context "aks".
[root@node1 ~]# kubecm list
+------------+--------------+-----------------------+--------------------+-----------------------------------+--------------+
| CURRENT | NAME | CLUSTER | USER | SERVER | Namespace |
+============+==============+=======================+====================+===================================+==============+
| | aksconfig | cluster-9hdtmk5k4h | user-9hdtmk5k4h | https://xxxxxxxxxxxxxxxx.hcp.e | arc |
| | | | | astus.azmk8s.io:443 | |
+------------+--------------+-----------------------+--------------------+-----------------------------------+--------------+
| * | k8sconfig | cluster-c5bdhf8kc6 | user-c5bdhf8kc6 | https://10.157.21.24:6443 | default |
+------------+--------------+-----------------------+--------------------+-----------------------------------+--------------+
Cluster check succeeded!
Kubernetes version v1.20.7
Kubernetes master is running at https://10.157.21.24:6443
[Summary] Pod: 40 Namespace: 8 Node: 3
kubectl-manage-multiple-k8s-cluster
https://git.msft.vip/2022/09/16-kubectl-manage-multiple-k8s-cluster/