可以先使用以下命令查看k8s的启动日志:
systemctl status kubelet
或使用以下命令查看最近的k8s日志:
journalctl -xeu kubelet
可能性一:
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-15-1024x103.png)
所以在初始化前修改/etc/containerd/config.toml的镜像地址参数:
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-16.png)
[plugins."io.containerd.grpc.v1.cri"] sandbox_image = "registry.aliyuncs.com/k8sxio/pause:3.6"
然后重启containerd:
systemctl restart containerd
可能性二:
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-11-1024x294.png)
查看/var/log/messages的最后日志:
May 7 14:34:26 k8s-master01 kubelet: E0507 14:34:26.071077 16320 eviction_manager.go:254] "Eviction manager: failed to get summary stats" err="failed to get node info: node \"k8s-master01\" not found" May 7 14:34:26 k8s-master01 kubelet: E0507 14:34:26.096124 16320 kubelet.go:2394] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized" May 7 14:34:26 k8s-master01 kubelet: E0507 14:34:26.160241 16320 kubelet.go:2469] "Error getting node" err="node \"k8s-master01\" not found" May 7 14:34:26 k8s-master01 kubelet: E0507 14:34:26.262056 16320 kubelet.go:2469] "Error getting node" err="node \"k8s-master01\" not found" May 7 14:34:26 k8s-master01 kubelet: E0507 14:34:26.362486 16320 kubelet.go:2469] "Error getting node" err="node \"k8s-master01\" not found" May 7 14:34:26 k8s-master01 kubelet: E0507 14:34:26.463165 16320 kubelet.go:2469] "Error getting node" err="node \"k8s-master01\" not found"
这是由于还没有安装网络插件flannel引起的。
可能性三:kubernates与docker的cgroup驱动不一致
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-7-1024x948.png)
查看/var/log/messages的最后日志:
Aug 23 18:17:21 localhost kubelet: E0823 18:17:21.059626 9490 server.go:294] "Failed to run kubelet" err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\"" Aug 23 18:17:21 localhost systemd: kubelet.service: main process exited, code=exited, status=1/FAILURE Aug 23 18:17:21 localhost systemd: Unit kubelet.service entered failed state. Aug 23 18:17:21 localhost systemd: kubelet.service failed.
从日志看出来,是因为hubernates与docker的cgroup驱动不一致引起的,那么我们只需要将两者的cgroup驱动设置为一直即可。(官方推荐systemd)
我们可以用以下指令确认一下docker的启动方式:
docker system info|grep -i driver
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-8.png)
修改docker的cgroup驱动的方法
一、找到docker的配置文件/etc/docker/daemon.json并修改添加如下参数(没有找到则新建一个):
"exec-opts": ["native.cgroupdriver=systemd"]
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/db5c96a5dc180571e464649c26e60382_v2-95e2e936aa71891321c3c38ed9dae7be_1440w-1024x370.jpg)
二、重启docker,并再次检查docker的驱动是否已经变更:
systemctl restart docker docker system info|grep -i driver
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-9.png)
修改kubernates的cgroup驱动为systemd
有两个文件:
一、/etc/sysconfig/kubelet
增加参数–cgroup-driver=systemd:
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-10-1024x70.png)
二、修改10-kubeadm.conf文件(使用该指令查找:find / -name ’10-kubeadm.conf’)
增加参数–cgroup-driver=systemd:
![](http://blog.sway.com.cn/wp-content/uploads/2023/05/image-10-1024x70.png)
然后重启kubernates服务即可:
systemctl restart kubelet
最后,重置kubeamdm并再次执行k8s初始化指令即可:
kubeadm reset