从 k8s 的主节点下载 config 文件,这个 config 文件就可以管理集群。
config111
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: xxx
server: https://10.237.11.4:6443
name: k8s-11
contexts:
- context:
cluster: k8s-11
user: k8s-11-admin
name: k8s-11-admin@k8s-11
current-context: k8s-11-admin@k8s-11
kind: Config
preferences: {}
users:
- name: k8s-11-admin
user:
client-certificate-data: xxxx
client-key-data: xxxx
|
config222
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: xxx
server: https://10.237.26.4:6443
name: k8s-dev
contexts:
- context:
cluster: k8s-dev
user: k8s-dev-admin
name: k8s-dev-admin@k8s-dev
current-context: k8s-dev-admin@k8s-dev
kind: Config
preferences: {}
users:
- name: k8s-dev-admin
user:
client-certificate-data: xxxx
client-key-data: xxxx
|
接下来执行合并命令,其实最好写到 zshrc 中
1
2
|
KUBECONFIG=~/.kube/config111:~/.kube/config222 kubectl config view --merge --flatten >> ~/.kube/config
export KUBECONFIG=~/.kube/config
|
注意问题,用户名一定要不一样,否则会报错。