k8s 踩坑记

Unable to connect to the server: x509

qlz@k8smaster:~/.kube$ kubectl get node
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")
qlz@k8smaster:~/.kube$ cd ..
qlz@k8smaster:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
cp: overwrite '/home/qlz/.kube/config'? y
qlz@k8smaster:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
qlz@k8smaster:~$ kubectl get node
NAME        STATUS   ROLES                  AGE     VERSION
k8smaster   Ready    control-plane,master   5m57s   v1.23.5

使用了sudo kubeadm reset重置master,尽管config文件还存在,其实每次初始化时生成的admin.conf都不一样,里面是包含了certificate-authority-data和client-certificate-data信息。这个就是导致这个报错的主要原因。所以当初始化后,会提示你

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

work节点NotReady

节点上

qlz@k8snode1:/etc/kubernetes$ sudo systemctl status  kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
     Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/kubelet.service.d
             └─10-kubeadm.conf
     Active: active (running) since Sun 2022-04-03 01:44:17 UTC; 1min 2s ago
       Docs: https://kubernetes.io/docs/home/
   Main PID: 905283 (kubelet)
      Tasks: 15 (limit: 9443)
     Memory: 33.5M
     CGroup: /system.slice/kubelet.service
             └─905283 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml --network-plugin=cni --pod-infra-container-image=k8s.gcr.io/pause:3.6

Apr 03 01:44:58 k8snode1 kubelet[905283]: I0403 01:44:58.887804  905283 cni.go:240] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
Apr 03 01:44:59 k8snode1 kubelet[905283]: E0403 01:44:59.194216  905283 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"
Apr 03 01:45:03 k8snode1 kubelet[905283]: I0403 01:45:03.888507  905283 cni.go:240] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
Apr 03 01:45:04 k8snode1 kubelet[905283]: E0403 01:45:04.205664  905283 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"
Apr 03 01:45:08 k8snode1 kubelet[905283]: I0403 01:45:08.889083  905283 cni.go:240] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
Apr 03 01:45:09 k8snode1 kubelet[905283]: E0403 01:45:09.217129  905283 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"
Apr 03 01:45:13 k8snode1 kubelet[905283]: I0403 01:45:13.891027  905283 cni.go:240] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
Apr 03 01:45:14 k8snode1 kubelet[905283]: E0403 01:45:14.229815  905283 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"
Apr 03 01:45:18 k8snode1 kubelet[905283]: I0403 01:45:18.893054  905283 cni.go:240] "Unable to update cni config" err="no networks found in /etc/cni/net.d"
Apr 03 01:45:19 k8snode1 kubelet[905283]: E0403 01:45:19.241789  905283 kubelet.go:2347] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized"

发现"Unable to update cni config" err="no networks found in /etc/cni/net.d"
从master 复制一份过去,全部重启,恢复

你可能感兴趣的:(k8s 踩坑记)