Kubernetes实战(十二)-使用kubeconfig文件管理多套kubernetes(k8s)集群

2023-12-15 09:37:10

1 概述

在生产环境中可能不止有一套kubernetes(k8s)集群,面对多套集群,运维人员可以使用kubeconfig文件管理多套kubernetes(k8s)集群,使用 kubeconfig 文件,可以组织集群、用户和命名空间,还可以定义上下文,以便在集群和命名空间之间快速轻松地切换。

2?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信息。

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJek1USXhNVEV6TVRVeE5Wb1hEVE16TVRJd09ERXpNVFV4TlZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTkdaCmR5N0J6Q1ZOYVZmeXJvN1k3Qm1JZ2lla3ZtSWpjUFpUdWp1UXlNMk43clZiQS9IcWh2eGQ2cmZtczM5a2IvSnYKOVpScWp5MUlGRTdsc3B5L1ZyL2F5TEYyMG0waDdsQnRTMlRrUXVHRkRzTUtQVWFsNVZIeU1rU05jbHd3NlpQVQpIMGhmSUZibHVlc2lxeTZBMlFad1NQT2FmZ3BGMmRyb2hFY242M0RiMzc0end3eERqVmRyS2g3cjF2RU85c0J6CjBkVGQ4UHVZdVFmL1R4ckk2M3JITFJRekViWXV0b3dlUzA0bTJKbUF1d2Y3bFVmQ3B4clNLWDlhb3FqRWZzTzEKN3U0Q3UvTG9kM2FENVFSZEJpeGNtdEYyeUV4VC9yaHgzckV5MDk3eHU5YzlVQVh0UVlxSXpTWTFLdTkvY1ZYUwozWkQ1MWtWR29RVVBMMU5WMHFFQ0F3RUFBYU5DTUVBd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZGb2N1RENoSUZjWmw2QmE0dTVQL0FUVnprOGJNQTBHQ1NxR1NJYjMKRFFFQkN3VUFBNElCQVFCMytBSitEa0hRa1IyOGJtYi9jbDA5WGtBQm0xdXE0cnVHTGVyazVIYUFWVnZWSThIVApiU3ByVWtXQno4OFJJa0JQQTNRdkNwUEt5YjdhbVk3QnpUekc4bmgwVGdUZXpoc2tWVjVoalc3VEYxSVp4WlhBCllCOThiQ0h6Zlo4ZUpoOW9DYjZKSkkyTUczYVVoN2pmZENsaHUzVUwvbGI3L0I5U0M3K2FFTUVJZHFPM0xydVkKbnZQRnVNeWpmdEhoNmVrY2x6VWptcGRtRFhLV3UzRExtYmRLWFg0TXpVRDNuSHkxWTdrekJISjJFUmpRbXlycgptSHh5c09vb2I4d1RIYmtQaFNic0x0ZVlDWFRER0tsd05OUytkSks4UVZjMTc4SFlURXJ1d3FYY2FRYkpFc1lICnBacGtDQ1lwRGJLMmp6Z0UzVnRFWnhCSkw5UW56dXV5eWVZaAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    server: https://10.220.43.203:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubern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uaVh5Ly9oS0Z2d09wYUR4MTVNWHRjWENRNG1NTDdEeFV3MUdhQXhQQlBQdVpWCmJxbWpnNTNRRlpNVUdnNGxKSHVDNmVrQ2dZRUF6Ry9KeWZqa282bkVGSHBFY2ZMN3hvVTg2NTEveENUMmVjNnQKYXVnZWJjYmhObTUwSjJRRkxLZUdQZzFrcnJNaHhYV2YxZno1MDRFdzBPVmJnWE9nckNndVBPMzRXT2loeXRLZgpmdXBuVDdxdGRUQUhaZ0ZVTGQxbmJwQjhiL3duR2Z5Qmk0RlRyb1NGcjlRb01oeW9jTmhyUUd2NGUrSStBTzVxCjg2NXlpVlVDZ1lFQXN1QWtlL01nMndKMnhLUzhWdE9rUHArSGpReVhFeW9mM09STGRPSEtXcFFoZzl0WGdZZjUKRmJVVW1WME5KQ3RqUm9tMnkrRHk1bCtsSTQ3UjlBWkRLRHVYTTg4b2NIY1FkR0FhdjZ3c1JMSmpmbkpsaVU3bgp5WFhZaVVVZUQyaUljVTlFa25aZU14MGVIQkFvOEdPQ3hWakZlWEl5ODF6aHNkN3BqZnNJWDhVPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=

3?kubernetes(k8s)多集群切换?

默认的kubeconfig文件为:~/.kube/config 文件。

$ ls .kube/
cache  config

编写一个kubeconfig文件来管理两套k8s集群。

$ cp .kube/config config2
$ cat config2 
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1ERXdPVEE0TVRnd01Wb1hEVE15TURFd056QTRNVGd3TVZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTEZyCkRxb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NtUE14SVdPR2JEc05sTHMzTmJ5S3RpNgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    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: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJR0ZpNStHUTdGOGd3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBeE1Ea3dPREU0TURGYUZ3MHlNekF4TURrd09ERTRNRE5hTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXNMUVpScS9BeVF1aDlVdy8KN0craVJqekovdUFjbmtubU9VMHQ1OHNIcUw4b0ZXVlFyeUlDS3djdEtMcEp6RHBMOEZDWUtoejJSekY2VHJtawpzYVcvT2FMRmV2SjR2Y2NIbm1McGR1SWpram1TRnJ0L0R6VCsvSWdacGNlL21SRC9LR0tQUUxSQVVpUGx6NzdhClRvYU1pWGM5Ny9XZGp0Nk9ic091RGVsTnlteU4xRG5ONWJ2NWRFTkRaclh3VTFkQndhQjRXdnliTi9nVm02TUUKSjhRdXJDZ2V5d2swRjRtd3kwcGUyVldBd3Y1VHFxTmVzZ01pWHFacjZ2SjNSV285Z0tCeVhCODNBb1gwTlk4TQptY1JIWG44cWhPZ3hYTXhXUWM2SEI1cE81QnFPUnY3MUE0NC9t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JIelJiczMwL083R051dXN1UGV0eTk5ODNJYXl2OWtXd045R2FJS3kzSmxRaWdzQ2Fva3NICjlYUEhyOFFqWXJkYWpSVnlkUDhaL0hycGdIRGYxckNOVGtXVjBZcExBb0dBSWFqUWN5WkZURnpKeWRzZ1Z2eVYKUjNpYjIwUXUzQ2Vrd0JoblRwaGNvY0dDNGlLNjBLcGZ0S01xRG1mbEdYVm5GU05HTkNNVENXQ0pkK0d0cDZOKwpNTFhIT3BuUDcydjdlN3RZTDZHY1dxYW1XbjMxbFVpUnNIMTRtYmg3T3ZJeWhDL2VuMjkxTWNqU1YydFFNWVZTCkpjSFh3a0pkVXJ5WXpBQS9IYWhNckVrQ2dZRUFoN3V1WjBrcXFUdmxEY3BzaE1pWmhSbGhwNDZSL2srdWtLbVcKTjJITlk1WGVUdFFDVnhpN3hxQWdLOEN3U0hWSC84YkdUZzFFZ3dnRHB5VURXcEJ1enhBNS9TWlQ3a1Q4OFhvKwptM05CcDZBNE82OUVaU2lvUDFoQndoUHdzT3RwK25hSDdpb0QxNDBMZXh0Q29UdjJqSk5LaEVsL3lEVUdidmEyCklqQmNwbjBDZ1lCZThNTERFK1RCKytYVHFUT29wWGhaL09vRVdlSEp2M2xwdGdmOWg0eVZja3NqVEtNMkpKcEsKNFJFYmJSdUdsY1hOUzg3bEh1dUtCZE9aVzR5Q1hMTCtzcGt4YkY0ZmlFQWFkaTFDOWhZSko3Y2kzZy9jdUxLcQpPdk9EdlhBK2dlRHVaMk9Gakh6RU1XcktKUm1Sd0N1QVdqRld5WndneU16dUp4WWRkRU1raWc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
- name: admin2
  user:
    client-certificate-data:这里写第二个集群的用户公钥 
    client-key-data:这里写第二个集群的用户私钥

查看全局上下文,看有几套集群。

$ kubectl config get-contexts 
CURRENT   NAME                          CLUSTER      AUTHINFO           NAMESPACE
*         kubernetes-admin@kubernetes   kubernetes   kubernetes-admin   

切换k8s集群。

$ kubectl config use-context kubernetes-admin@kubernetes
Switched to context "kubernetes-admin@kubernetes".

文章来源:https://blog.csdn.net/ygq13572549874/article/details/134938947
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。