k8s kubectl生成kube-config文件

配置kube配置文件

  设置集群参数

  kubectl config set-cluster kubernetes --certificate-authority=/etc/kubernetes/ssl/ca.pem --server=https://192.168.1.71:6443

  cat ~/.kube/config  

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /etc/kubernetes/ssl/ca.pem
    server: https://192.168.1.71:6443
  name: kubernetes
contexts: []
current-context: ""
kind: Config
preferences: {}
users: []

  设置客户端认证参数 指定用户名和key

  kubectl config set-credentials admin --client-certificate=/etc/kubernetes/ssl/kubelet-1-71.pem --client-key=/etc/kubernetes/ssl/kubelet-1-71.key

  设置上下文参数

  kubectl config set-context kubernetes --cluster=kubernetes --user=admin

  设置默认上下文

  kubectl config use-context kubernetes

  cat ~/.kube/config  

apiVersion: v1
clusters:
- cluster:
    certificate-authority: /etc/kubernetes/ssl/ca.pem
    server: https://192.168.1.71:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: admin
  name: kubernetes
current-context: kubernetes
kind: Config
preferences: {}
users:
- name: admin
  user:
    as-user-extra: {}
    client-certificate: /etc/kubernetes/ssl/kubelet-1-71.pem
    client-key: /etc/kubernetes/ssl/kubelet-1-71.key

 

  当然也可以直接修改上面文件

转载于:https://www.cnblogs.com/S--S/p/10887309.html

你可能感兴趣的:(k8s kubectl生成kube-config文件)