一.系统环境

服务器版本 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: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1ERXdPVEE0TVRnd01Wb1hEVE15TURFd056QTRNVGd3TVZvd0ZURVRNQk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pKWGpyL0xKbGs3THVBcVBVT1VBdHBRTDZSbTArTXVQTGw0YkxQNFhOOTZOZit0NDlHdS9LeXBabXpIQkFOMWl0CkYrN0szeXVoamQ4VVNtUE14SVdPR2JEc05sTHMzTmJ5S3RpNgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
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: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJR0ZpNStHUTdGOGd3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBeE1Ea3dPREU0TURGYUZ3MHlNekF4TURrd09ERTRNRE5hTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXNMUVpScS9BeVF1aDlVdy8KN0craVJqekovdUFjbmtubU9VMHQ1OHNIcUw4b0ZXVlFyeUlDS3djdEtMcEp6RHBMOEZDWUtoejJSekY2VHJtawpzYVcvT2FMRmV2SjR2Y2NIbm1McGR1SWpram1TRnJ0L0R6VCsvSWdacGNlL21SRC9LR0tQUUxSQVVpUGx6NzdhClRvYU1pWGM5Ny9XZGp0Nk9ic091RGVsTnlteU4xRG5ONWJ2NWRFTkRaclh3VTFkQndhQjRXdnliTi9nVm02TUUKSjhRdXJDZ2V5d2swRjRtd3kwcGUyVldBd3Y1VHFxTmVzZ01pWHFacjZ2SjNSV285Z0tCeVhCODNBb1gwTlk4TQptY1JIWG44cWhPZ3hYTXhXUWM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WhKS2JlSgpMUU80amFvdVFEUkJIelJiczMwL083R051dXN1UGV0eTk5ODNJYXl2OWtXd045R2FJS3kzSmxRaWdzQ2Fva3NICjlYUEhyOFFqWXJkYWpSVnlkUDhaL0hycGdIRGYxckNOVGtXVjBZcExBb0dBSWFqUWN5WkZURnpKeWRzZ1Z2eVYKUjNpYjIwUXUzQ2Vrd0JoblRwaGNvY0dDNGlLNjBLcGZ0S01xRG1mbEdYVm5GU05HTkNNVENXQ0pkK0d0cDZOKwpNTFhIT3BuUDcydjdlN3RZTDZHY1dxYW1XbjMxbFVpUnNIMTRtYmg3T3ZJeWhDL2VuMjkxTWNqU1YydFFNWVZTCkpjSFh3a0pkVXJ5WXpBQS9IYWhNckVrQ2dZRUFoN3V1WjBrcXFUdmxEY3BzaE1pWmhSbGhwNDZSL2srdWtLbVcKTjJITlk1WGVUdFFDVnhpN3hxQWdLOEN3U0hWSC84YkdUZzFFZ3dnRHB5VURXcEJ1enhBNS9TWlQ3a1Q4OFhvKwptM05CcDZBNE82OUVaU2lvUDFoQndoUHdzT3RwK25hSDdpb0QxNDBMZXh0Q29UdjJqSk5LaEVsL3lEVUdidmEyCklqQmNwbjBDZ1lCZThNTERFK1RCKytYVHFUT29wWGhaL09vRVdlSEp2M2xwdGdmOWg0eVZja3NqVEtNMkpKcEsKNFJFYmJSdUdsY1hOUzg3bEh1dUtCZE9aVzR5Q1hMTCtzcGt4YkY0ZmlFQWFkaTFDOWhZSko3Y2kzZy9jdUxLcQpPdk9EdlhBK2dlRHVaMk9Gakh6RU1XcktKUm1Sd0N1QVdqRld5WndneU16dUp4WWRkRU1raWc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=

查看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: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJR0ZpNStHUTdGOGd3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBeE1Ea3dPREU0TURGYUZ3MHlNekF4TURrd09ERTRNRE5hTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSW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qQmNwbjBDZ1lCZThNTERFK1RCKytYVHFUT29wWGhaL09vRVdlSEp2M2xwdGdmOWg0eVZja3NqVEtNMkpKcEsKNFJFYmJSdUdsY1hOUzg3bEh1dUtCZE9aVzR5Q1hMTCtzcGt4YkY0ZmlFQWFkaTFDOWhZSko3Y2kzZy9jdUxLcQpPdk9EdlhBK2dlRHVaMk9Gakh6RU1XcktKUm1Sd0N1QVdqRld5WndneU16dUp4WWRkRU1raWc9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
- 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".

k8s多集群切换:使用kubeconfig文件管理多套kubernetes(k8s)集群的更多相关文章

  1. Kubernetes(K8S) kubesphere 安装

    安装KubeSphere最好的方法就是参考官方文档,而且官方文档是中文的. 官网地址:https://kubesphere.com.cn/ https://github.com/kubesphere/ ...

  2. 【葵花宝典】lvs+keepalived部署kubernetes(k8s)高可用集群

    一.部署环境 1.1 主机列表 主机名 Centos版本 ip docker version flannel version Keepalived version 主机配置 备注 lvs-keepal ...

  3. Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列之部署master/node节点组件(四)

    0.前言 整体架构目录:ASP.NET Core分布式项目实战-目录 k8s架构目录:Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列目录 1.部署master组件 ...

  4. K8S 使用Kubeadm搭建高可用Kubernetes(K8S)集群 - 证书有效期100年

    1.概述 Kubenetes集群的控制平面节点(即Master节点)由数据库服务(Etcd)+其他组件服务(Apiserver.Controller-manager.Scheduler...)组成. ...

  5. 使用kubectl管理Kubernetes(k8s)集群:常用命令,查看负载,命名空间namespace管理

    目录 一.系统环境 二.前言 三.kubectl 3.1 kubectl语法 3.2 kubectl格式化输出 四.kubectl常用命令 五.查看kubernetes集群node节点和pod负载 5 ...

  6. Kubernetes(k8s) docker集群搭建

    原文地址:https://blog.csdn.net/real_myth/article/details/78719244 一.Kubernetes系列之介绍篇   •Kubernetes介绍 1.背 ...

  7. Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列之自签TLS证书及Etcd集群部署(二)

    0.前言 整体架构目录:ASP.NET Core分布式项目实战-目录 k8s架构目录:Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列目录 一.服务器设置 1.把每一 ...

  8. Kubernetes(k8s)集群安装

    一:简介 二:基础环境安装 1.系统环境 os Role ip Memory Centos 7 master01 192.168.25.30 4G Centos 7 node01 192.168.25 ...

  9. 5.基于二进制部署kubernetes(k8s)集群

    1 kubernetes组件 1.1 Kubernetes 集群图 官网集群架构图 1.2 组件及功能 1.2.1 控制组件(Control Plane Components) 控制组件对集群做出全局 ...

  10. Centos7 安装部署Kubernetes(k8s)集群

    目录 一.系统环境 二.前言 三.Kubernetes 3.1 概述 3.2 Kubernetes 组件 3.2.1 控制平面组件 3.2.2 Node组件 四.安装部署Kubernetes集群 4. ...

随机推荐

  1. Go 语言中切片的使用和理解

    切片与数组类似,但更强大和灵活.与数组一样,切片也用于在单个变量中存储相同类型的多个值.然而,与数组不同的是,切片的长度可以根据需要增长和缩小.在 Go 中,有几种创建切片的方法: 使用[]datat ...

  2. 【FAQ】HarmonyOS SDK 闭源开放能力 —Push Kit

    1.问题描述 升级到4.0.0.59版本后,通过pushService.getToken获取华为的token时报如下错误:Illegal application identity. 解决方案 Mate ...

  3. Prometheus之自定义标签

    前言: 我们一般通过grafana导入Dashboard模板用来展示数据,但是有时候需要自己定义展示项目,这时需要自己在Prometheus重新自定义标签,并在grafana进行应用. 1.Prome ...

  4. mongodb基础整理篇————设计[四]

    前言 简单整理一下mongodb的设计. 正文 设计三步曲: 第一步:建立基础文档模型 例子: 1对1建模: 1 对多建模: N对N模型: 第二步: 根据读写况细化 遇到的问题: 解决: 查询连表: ...

  5. Python中2种常用数据可视化库:Bokeh和Altair

    本文分享自华为云社区<探究数据可视化:Bokeh vs. Altair>,作者:柠檬味拥抱. 在数据科学和数据分析领域,数据可视化是一种强大的工具,可以帮助我们更好地理解数据.发现模式和趋 ...

  6. 力扣231(java)-2的幂(简单)

    题目: 给你一个整数 n,请你判断该整数是否是 2 的幂次方.如果是,返回 true :否则,返回 false . 如果存在一个整数 x 使得 n == 2x ,则认为 n 是 2 的幂次方. 示例 ...

  7. HarmonyOS NEXT应用开发之图片缩放效果实现

    介绍 图片预览在应用开发中是一种常见场景,在诸如QQ.微信.微博等应用中均被广泛使用.本模块基于Image组件实现了简单的图片预览功能. 使用说明: 双指捏合缩放图片大小 双击图片进行图片的大小切换 ...

  8. DTCC 2020 | 阿里云梁高中:DAS之基于Workload的全局自动优化实践

    简介: 第十一届中国数据库技术大会(DTCC2020),在北京隆重召开.在12.23日性能优化与SQL审计专场上,邀请了阿里巴巴数据库技术团队高级技术专家梁高中为大家介绍DAS之基于Workload的 ...

  9. 创新推出 | Serverless 场景排查问题利器:函数实例命令行操作

    ​简介: 实例命令行功能的推出希望能消除用户使用 Serverless 的"最后一公里",直接将真实的函数运行环境展现给用户,此后 Serverless 将不再是一个"黑 ...

  10. 【详谈 Delta Lake 】系列技术专题 之 Streaming(流式计算)

    ​简介: 本文翻译自大数据技术公司 Databricks 针对数据湖 Delta Lake 的系列技术文章.众所周知,Databricks 主导着开源大数据社区 Apache Spark.Delta ...