Share with together

独乐乐不如众乐乐

博客园 首页 新随笔 联系 订阅 管理

错误描述:

[root@k8s-master ~]# kubectl get nodes
Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes")

一般是:k8s master 初始化操作不完整导致,完整过程如下:

[root@k8s-master ~]# kubeadm reset

 

[root@k8s-master ~]# kubeadm init --apiserver-advertise-address=192.168.58.138 --kubernetes-version v1.23.5 --pod-network-cidr=192.168.0.0/16

  

看到如下提示信息后要继续执行:

 

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.58.138:6443 --token ngpadd.js4es78t13mi9cjd \
--discovery-token-ca-cert-hash sha256:a72b70060492ad11c2034db603c6d58b069d18a7aa44cd8903ccb383ffdb342a

  

如果当前是 root 用户,执行如下:

[root@k8s-master ~]# export KUBECONFIG=/etc/kubernetes/admin.conf

  

如果当时是非root用户,执行如下:

[root@k8s-master ~]#mkdir -p $HOME/.kube
[root@k8s-master ~]#sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@k8s-master ~]#sudo chown $(id -u):$(id -g) $HOME/.kube/config

  

再次执行:

[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane,master 106m v1.23.5
k8s-node1 Ready <none> 97m v1.23.5

  

 问题解决,希望能帮到您!

posted on 2022-04-08 11:34  寒枫  阅读(3655)  评论(0编辑  收藏  举报