failed to run Kubelet: misconfiguration: kubelet cgroup driver: "systemd" is different from docker cgroup driver: "cgroupfs"

转载:https://www.dianjilingqu.com/341097.html

 

 要搞清楚这个问题,就需要先了解什么是cgroups

 

1、什么是cgroupfs ?

docker默认的Cgroup Driver是cgroupfs ,cgroupfs是cgroup为给用户提供的操作接口而开发的虚拟文件系统类型,可以向用户展示cgroup的hierarchy,通知kernel用户对cgroup改动,对cgroup的查询和修改只能通过cgroupfs文件系统来进行。

 

2、为什么要修改为使用systemd?

   Kubernetes 推荐使用 systemd 来代替 cgroupfs,  因为systemd是Kubernetes自带的cgroup管理器, 负责为每个进程分配cgroups, 但docker的cgroup driver默认是cgroupfs,这样就同时运行有两个cgroup控制管理器,当资源有压力的情况时,有可能出现不稳定的情况。

 

如果不修改配置,会在kubeadm init时有报错提示:

使用 journalctl -xeu kubelet 或者 journalctl -xeu kubelet -l 查看详细错误信息。

"Failed to run kubelet" err="failed to run Kubelet: misconfiguration: kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\""

 

根据报错信息发现,是因为 k8s 和docker 的 cgroup driver 不一致导致的,k8s 的是systemd,而docker是cgroupfs。

 

可以通过 docker info查看。

Cgroup Driver: cgroupfs

[root@localhost ~]# docker info 
Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 19.03.6
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 35bd7a5f69c13e1563af8a93431411cd9ecf5021
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-693.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.843GiB
 Name: localhost.localdomain
 ID: 5DIW:7H2E:EVKF:CCUM:WMMH:TX3G:XXL4:CRZX:YZ4F:FONC:YRES:WIKN
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

[root@localhost ~]#

 

解决方案:

所有master跟node节点的docker添加如下配置项。

cat /etc/docker/daemon.json

{

"exec-opts": ["native.cgroupdriver=systemd"]

}

然后重启docker,重新启动kubelet

 
posted @ 2022-07-22 23:45  php的自我修养  阅读(1027)  评论(0编辑  收藏  举报