其他分享
首页 > 其他分享> > rancher无法连接k8s自定义集群

rancher无法连接k8s自定义集群

作者:互联网

1,rancher2.5无法连接k8s自定义集群

误删自定义k8s集群cattle-cluster-agent,cattle-node-agent组件,或者错误更新rancher证书导致无法连接k8s的问题恢复

第一步.创建注册命令



获取到以下执行命令

curl --insecure -sfL https://172.30.1.159:8443/v3/import/5qk4w2lvgpvl2rtd7tcwm54wj56tj9gmlv4wrnrqsgrrff9f55rbg6.yaml | kubectl apply -f -

进入k8s master 01 节点执行以上命令,如没有下载kubectl配置文件则以下第二步创建kubectl config文件

第二步.创建kubectl config(有则跳过)

cp /etc/kubernetes/ssl/kubecfg-kube-node.yaml /root/.kube/config

若执行kubect无法操作k8s则创建以下自定义admin证书
创建admin.key

umask 077;openssl genrsa -out admin.key 2048
openssl  req -new -key admin.key -out admin.csr -subj "/CN=kube-admin/O=system:masters"
openssl x509 -req -days 999 -CA /etc/kubernetes/ssl/kube-ca.pem  -CAkey /etc/kubernetes/ssl/kube-ca-key.pem  -CAcreateserial -in ./admin.csr -out admin.pem

创建以下内容/root/.kube/config 将

apiVersion: v1
kind: Config
clusters:
- cluster:
    api-version: v1
    certificate-authority: /etc/kubernetes/ssl/kube-ca.pem
    server: "https://127.0.0.1:6443"
  name: "local"
contexts:
- context:
    cluster: "local"
    user: "kube-node-local"
  name: "local"
current-context: "local"
users:
- name: "kube-node-local"
  user:
    client-certificate: /etc/kubernetes/ssl/admin.pem
    client-key: /etc/kubernetes/ssl/admin.key

执行之前获取的注册命令

curl --insecure -sfL https://172.30.1.159:8443/v3/import/5qk4w2lvgpvl2rtd7tcwm54wj56tj9gmlv4wrnrqsgrrff9f55rbg6.yaml | kubectl apply -f -

等待cattle-cluster-agent启动完成即可在rancher管理k8s

标签:k8s,自定义,admin,ssl,key,rancher,kube,local
来源: https://www.cnblogs.com/wes1502/p/rancher-wu-fa-lian-jiek8s-zi-ding-yi-ji-qun.html