现象:
首先是master节点,执行kubectl get nodes 报错,在对master节点恢复后,恢复方法如下:
sudo kubeadm certs renew all --config=./kubeadm-init-config.yaml
后,发现worker节点依然是not ready状态:
kiosk@k8s-master:~$ k get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane 425d v1.24.1
k8s-worker1 NotReady <none> 425d v1.24.1
k8s-worker2 NotReady <none> 425d v1.24.1
同时在worker节点上查看kubelet状态,不是active状态,经过试验,发现调整了worker节点的时间,前置2个月,kubelet状态就正常了。
判定是worker节点没有更新证书。
在worker节点上执行:
kubeadm certs renew all
并不能解决问题。
但问题已经聚焦,在是证书过期问题没有解决。
于是考虑在master节点上,生成worker节点的kubelet.conf文件,复制过去。具体操作如下:
root@k8s-master:/home/kiosk# kubeadm init phase kubeconfig kubelet --node-name k8s-worker1 --config ./kubeadm-config.yaml --kubeconfig-dir /home/kiosk/tmp
[kubeconfig] Writing "kubelet.conf" kubeconfig file
解释一下:
- --node-name k8s-worker1是指定worker节点,
- --config ./kubeadm-config.yaml,这个需要到集群创建时,使用的kubeadm-config.yaml文件所在位置
- --kubeconfig-dir /home/kiosk/tmp 意思是生成一个配置文件到tmp目录下,并不是初始化集群
接着拷贝到worker1节点:
root@k8s-master:/home/kiosk/tmp# scp ./kubelet.conf 192.168.147.129:/etc/kubernetes/
在worker1节点上查看:
root@k8s-worker1:/etc/kubernetes# systemctl restart kubelet
//重启下服务
root@k8s-worker1:/etc/kubernetes# ls /var/lib/kubelet/pki/
kubelet-client-2022-08-16-12-45-49.pem kubelet-client-2023-10-15-16-13-31.pem kubelet-client-current.pem kubelet.crt kubelet.key
root@k8s-worker1:/etc/kubernetes# ll /var/lib/kubelet/pki/
total 24
drwxr-xr-x 2 root root 4096 Oct 15 16:13 ./
drwxr-xr-x 8 root root 4096 Aug 16 2022 ../
-rw------- 1 root root 1118 Aug 16 2022 kubelet-client-2022-08-16-12-45-49.pem
-rw------- 1 root root 1114 Oct 15 16:13 kubelet-client-2023-10-15-16-13-31.pem
lrwxrwxrwx 1 root root 59 Oct 15 16:13 kubelet-client-current.pem -> /var/lib/kubelet/pki/kubelet-client-2023-10-15-16-13-31.pem
## 链接到新pem文件了
-rw-r--r-- 1 root root 2271 Aug 16 2022 kubelet.crt
-rw------- 1 root root 1679 Aug 16 2022 kubelet.key
## 查看证书
root@k8s-worker1:/etc/kubernetes# openssl x509 -in /var/lib/kubelet/pki/kubelet-client-current.pem -noout -text |grep Not
Not Before: Oct 15 16:08:31 2023 GMT
Not After : Oct 14 16:08:31 2024 GMT
再次查看kubelet服务:
root@k8s-worker1:/etc/kubernetes# 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 2023-10-15 16:13:56 UTC; 14min ago
Docs: https://kubernetes.io/docs/home/
Main PID: 6413 (kubelet)
Tasks: 15 (limit: 4534)
Memory: 37.7M
CPU: 26.264s
在master节点上查看:
root@k8s-master:/home/kiosk/tmp# k get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane 425d v1.24.1
k8s-worker1 Ready <none> 425d v1.24.1
k8s-worker2 NotReady <none> 425d v1.24.1
同理,操作worker2节点。