k8s多集群切换

kubeconfig文件类如:

current-context: federal-context
apiVersion: v1
clusters:
- cluster:
    api-version: v1
    server: http://cow.org:8080
  name: cow-cluster
- cluster:
    certificate-authority: path/to/my/cafile
    server: https://horse.org:4443
  name: horse-cluster
- cluster:
    insecure-skip-tls-verify: true
    server: https://pig.org:443
  name: pig-cluster
contexts:
- context:
    cluster: horse-cluster
    namespace: chisel-ns
    user: green-user
  name: federal-context
- context:
    cluster: pig-cluster
    namespace: saw-ns
    user: black-user
  name: queen-anne-context
kind: Config
preferences:
  colors: true
users:
- name: blue-user
  user:
    token: blue-token
- name: green-user
  user:
    client-certificate: path/to/my/client/cert
    client-key: path/to/my/client/key

通过命令kubectl config get-contexts查看config中的环境


yaml中,current-context指定当前环境,通过kubectl config use-context {NAME}可以切换

其余主要由3部分组成:clusters、contexts、users

clusters包含各集群端点数据,包含完整apiserver的url以及证书等

k8s多集群切换_第1张图片

users用于向 kubernetes 集群进行身份验证的客户端凭据。

k8s多集群切换_第2张图片

contexts定义集群环境,包括使用的user以及进入的cluster,用name来标识。

k8s多集群切换_第3张图片

你可能感兴趣的:(docker,kubernetes)