一.系统环境
服务器版本 | docker软件版本 | CPU架构 |
---|---|---|
CentOS Linux release 7.4.1708 (Core) | Docker version 20.10.12 | x86_64 |
二.前言
在生产环境中可能不止有一套kubernetes(k8s)集群,我们可以使用kubeconfig文件管理多套kubernetes(k8s)集群,使用 kubeconfig 文件,你可以组织集群、用户和命名空间。你还可以定义上下文,以便在集群和命名空间之间快速轻松地切换。
关于Kubernetes(k8s)集群的安装部署,可以查看博客《Centos7 安装部署Kubernetes(k8s)集群》https://www.cnblogs.com/renshengdezheli/p/16686769.html
三.kubeconfig文件
用于配置集群访问的文件称为“kubeconfig 文件”。 这是引用配置文件的通用方法,并不意味着有一个名为 kubeconfig 的文件。
使用 kubeconfig 文件来组织有关集群、用户、命名空间和身份认证机制的信息。 kubectl 命令行工具使用 kubeconfig 文件来查找选择集群所需的信息,并与集群的 API 服务器进行通信。
默认情况下,kubectl 在 $HOME/.kube 目录下查找名为 config 的文件。 你可以通过设置 KUBECONFIG 环境变量或者设置 --kubeconfig参数来指定其他 kubeconfig 文件。
kubeconfig文件由3部分组成:clusters,users,contexts。clusters是kubernetes(k8s)集群信息,users是连接kubernetes(k8s)集群的用户信息,contexts上下文综合了clusters信息和users信息。
四.kubernetes(k8s)多集群切换
默认的kubeconfig文件为:~/.kube/config 文件
[root@k8scloude1 ~]# ls .kube/
cache config kubens
[root@k8scloude1 ~]# ls .kube/kubens/
kubernetes-admin@kubernetes
[root@k8scloude1 ~]# ll -h .kube/config
-rw------- 1 root root 5.5K 1月 10 14:54 .kube/config
查看kubeconfig的配置
[root@k8scloude1 ~]# cat .kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1ERXdPVEE0TVRnd01Wb1hEVE15TURFd056QTRNV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FRhbTNTV2tyelZ6VQpKWGpyL0xKbGs3THVBcVBVT1VBdHBRTDZSbTArTXVQTGw0YkxQNFhOOTZOZit0NDlHdS9LeXBabXpIQkFOMWl0CkYrN0szeXVoamQ4VVNtUE14SVdPR2JEc05sTHMzTmJ5S3RpNgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
server: https://192.168.110.130:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
namespace: kube-system
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJR0ZpNStHUTdGOGd3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBeE1Ea3dPREU0TURGYUZ3MHlNekF4TURrd09ERTRNRE5hTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXNMUVpScS9BeVF1aDlVdy8KN0craVJqekovdUFjbmtubU9VMHQ1OHNIcUw4b0ZXVlFyeUlDS3djdEtMcEp6RHBMOEZDWUtoejJSekY2VHJtawpzYVcvT2FMRmV2SjR2Y2NIbm1McGR1SWpram1TRnJ0L0R6VCsvSWdacGNlL21SRC9LR0tQUUxSQVVpUGx6NzdhClRvYU1pWGM5Ny9XZGp0Nk9ic091RGVsTnlteU4xRG5ONWJ2NWRFTkRaclh3VTFkQndhQjRXdnliTi9nVm02TUUKSjhRdXJDZ2V5d2swRjRtd3kwcGUyVldBd3Y1VHFxTmVzZ01pWHFacjZ2SjNSV285Z0tCeVhCODNBb1gwTlk4TQptY1JIWG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VUVLWFBsOGZsc1hjZWhKS2JlSgpMUU80amFvdVFEUkJIelJiczMwL083R051dXN1UGV0eTk5ODNJYXl2OWtXd045R2FJS3kzSmxRaWdzQ2Fva3NICjlYUEhyOFFqWXJkYWpSVnlkUDhaL0hycGdIRGYxckNOVGtXVjBZcExBb0dBSWFqUWN5WkZURnpKeWRzZ1Z2eVYKUjNpYjIwUXUzQ2Vrd0JoblRwaGNvY0dDNGlLNjBLcGZ0S01xRG1mbEdYVm5GU05HTkNNVENXQ0pkK0d0cDZOKwpNTFhIT3BuUDcydjdlN3RZTDZHY1dxYW1XbjMxbFVpUnNIMTRtYmg3T3ZJeWhDL2VuMjkxTWNqU1YydFFNWVZTCkpjSFh3a0pkVXJ5WXpBQS9IYWhNckVrQ2dZRUFoN3V1WjBrcXFUdmxEY3BzaE1pWmhSbGhwNDZSL2srdWtLbVcKTjJITlk1WGVUdFFDVnhpN3hxQWdLOEN3U0hWSC84YkdUZzFFZ3dnRHB5VURXcEJ1enhBNS9TWlQ3a1Q4OFhvKwptM05CcDZBNE82OUVaU2lvUDFoQndoUHdzT3RwK25hSDdpb0QxNDBMZXh0Q29UdjJqSk5LaEVsL3lEVUdidmEyCklqQmNwbjBDZ1lCZThNTERFK1RCKytYVHFUT29wWGhaL09vRVdlSEp2M2xwdGdmOWg0eVZja3NqVEtNMkpKcEsKNFJFYmJSdUdsY1hOUzg3bEh1dUtCZE9aVzR5Q1hMTCtzcGt4YkY0ZmlFQWFkaTFDOWhZSko3Y2kzZy9jdUxLcQpPdk9EdlhBK2dlRHVaMk9Gakh6RU1XcktKUm1Sd0N1QVdqRld5WndneU16dUp4WWRkRU1raWc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
查看kubeconfig格式
[root@k8scloude1 ~]# kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://192.168.110.130:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
namespace: kube-system
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
编写一个kubeconfig文件来管理两套k8s集群
[root@k8scloude1 ~]# cp .kube/config config2
[root@k8scloude1 ~]# cat config2
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1ERXdPVEE0TVRnd01Wb1hEVE15TURFd056QTRNVGd3TVZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTEZyCkRxb2YyV2twdDJ1a2xSWnljRHQyQ2xmYnNXdTBhb256NW1rTG5IaThlZFdJbkdWR09tMllxV0x2V20yRGFrYWYKSk9oNmtRU0wyYjBXZjBRbnZaMklIQ0hBYm5lTmI0NEpIaHVTL2MxU285d2VNQm5GNk9ZRjU2Qkk4dnlSamJhZgoyVXBQSUhNZTlYcitmZTYvRHRmTGFwOERkSFlCWGFPWlpZcDZIaGEyU1JWSjg4cmJRbzJuWnV6Ykl5bWdMUnpSCnpwdE9TRVpBa1JUMzRkZmF4bm0yM3hVNG9vSnRDRWhjZVNjZ3QvZ0szOFRXMmJkRmIzU1c2UWdNc0FFOG4yVXQKaDR4c203TDVla29kTHU1N2VmWHhNZTVKTU5yTXBIL0h5M3BHSlpab0NYbG5rbm9ML2EzdTBHKzgzak8zcXRzWgp0M004TDdDcTc5Qm5BQW41aS8wQ0F3RUFBYU5DTUVBd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZNTWd0NGZKTWhDa0s2NGF1WWNML1VlUEs5OVBNQTBHQ1NxR1NJYjMKRFFFQkN3VUFBNElCQVFDcFVtSittNk9nNFZuQjBSNWpxd05EakJxZ0pQVWtONHB1MFFURlg1WWs4NGFOMnQvYgpKWTFTQ3hnR2h5Q1JERVA1U0NUMXZrdHRqaFpVVnArZjdZUnE3V1BXK0JQcWE3Nm5TUlEydUkxRHoxVDhZSGNnCi9CRkNadWIwQVZ4Y0Z1RTdSb1NkbjFDOTlqaERjUCtIRW9zRFl6dUYzZmo4QzlCMkl6d3ZIaHpaUDAvVlZSRDcKay9wWk5ub3hRdHNoWHdvVnhYS1BacHNGMHhvL1ppcUVoa2ZIYURMVC9MZE5qYXhyTjNOcFRhbTNTV2tyelZ6VQpKWGpyL0xKbGs3THVBcVBVT1VBdHBRTDZSbTArTXVQTGw0YkxQNFhOOTZOZit0NDlHdS9LeXBabXpIQkFOMWl0CkYrN0szeXVoamQ4VVNtUE14SVdPR2JEc05sTHMzTmJ5S3RpNgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
server: https://192.168.110.130:6443
name: cluster1
- cluster:
certificate-authority-data:这里写第二个集群的密钥
server: https://cluster2_ip:6443
name: cluster2
contexts:
- context:
cluster: cluster1
namespace: default
user: admin1
name: admin1@cluster1
- context:
cluster: cluster2
namespace: default
user: admin2
name: admin2@cluster2
current-context: admin1@cluster1
kind: Config
preferences: {}
users:
- name: admin1
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJR0ZpNStHUTdGOGd3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBeE1Ea3dPREU0TURGYUZ3MHlNekF4TURrd09ERTRNRE5hTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0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aEVsL3lEVUdidmEyCklqQmNwbjBDZ1lCZThNTERFK1RCKytYVHFUT29wWGhaL09vRVdlSEp2M2xwdGdmOWg0eVZja3NqVEtNMkpKcEsKNFJFYmJSdUdsY1hOUzg3bEh1dUtCZE9aVzR5Q1hMTCtzcGt4YkY0ZmlFQWFkaTFDOWhZSko3Y2kzZy9jdUxLcQpPdk9EdlhBK2dlRHVaMk9Gakh6RU1XcktKUm1Sd0N1QVdqRld5WndneU16dUp4WWRkRU1raWc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
- name: admin2
user:
client-certificate-data:这里写第二个集群的用户公钥
client-key-data:这里写第二个集群的用户私钥
查看全局上下文,看有几套集群
[root@k8scloude1 ~]# kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* kubernetes-admin@kubernetes kubernetes kubernetes-admin kube-system
切换k8s集群
[root@k8scloude1 ~]# kubectl config use-context kubernetes-admin@kubernetes
Switched to context "kubernetes-admin@kubernetes".