kube config配置

半日闲 2020年07月21日 40次浏览

日常工作中使用k8s,因为各种环境的问题,不同的人员需要配置不同的k8s用户以及不同的namespace,使用kube config就可以比较方便的解决这个问题,kube config命令读取的是~/.kube/下的配置文件

配置默认操作的namesapce为自定义的,而不是default
  1. 查看kube config文件
[root@node2 ~]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://10.0.52.192:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: lxl-carrier
current-context: lxl-carrier
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
  1. 设置默认的namespacelxl-carrier
kubectl config set contexts.lxl-carrier.namespace lxl-carrier
  1. 查看kube config文件
[root@node2 ~]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://10.0.52.192:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    namespace: lxl-carrier
    user: kubernetes-admin
  name: lxl-carrier
current-context: lxl-carrier
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED