修改CentOS Cgroup Driver的正确方法

kubelete跟Docker的Cgroup Driver不一致,需要修改Docker的Cgroup类型为systemd

1、在/etc/docker/key.json配置开头新增

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

[root@node01 docker]# cat key.json
{"exec-opts":["native.cgroupdriver=systemd"],"crv":"P-256","d":"6vYyNZZOHM739G5fm4tL4UMgIHH6XrBqOnsLtq7gYjs","kid":"O35W:NIXI:ETG5:R4LN:ARL6:JRAV:YRKI:ZLA5:CAU5:MQPG:DQUN:VYS7","kty":"EC","x":"qBbmTxFygpvIIne9uEKx5XD8hq7C4C5tgAOkDsKeSM4","y":"5WqYN2ohTWE_BLia10Fr1ZEA-Zi879ZUc8Sopzl_WLs"}

2、在/etc/docker/daemon.json配置末尾新增

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

[root@node01 docker]# cat daemon.json
{

   "registry-mirrors": [
     "https://a8qh6yqv.mirror.aliyuncs.com",
     "http://hub-mirror.c.163.com"
   ],
   "exec-opts":["native.cgroupdriver=systemd"]
}

3、重启Docker服务配置生效

[root@node01 docker]# systemctl restart docker

[root@node01 docker]# docker info | grep -i cgroup

Cgroup Driver: systemd

需要注意的点:

在修改 daemon.json 配置文件时可能出现如下错误:

[root@node01 docker]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@node01 docker]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Fri 2021-11-12 22:39:02 PST; 18s ago
     Docs: https://docs.docker.com
  Process: 3132 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
 Main PID: 3132 (code=exited, status=1/FAILURE)

Nov 12 22:39:02 node01 systemd[1]: Failed to start Docker Application Container Engine.
Nov 12 22:39:02 node01 systemd[1]: Unit docker.service entered failed state.
Nov 12 22:39:02 node01 systemd[1]: docker.service failed.
Nov 12 22:39:02 node01 systemd[1]: docker.service holdoff time over, scheduling restart.
Nov 12 22:39:02 node01 systemd[1]: Stopped Docker Application Container Engine.
Nov 12 22:39:02 node01 systemd[1]: start request repeated too quickly for docker.service
Nov 12 22:39:02 node01 systemd[1]: Failed to start Docker Application Container Engine.
Nov 12 22:39:02 node01 systemd[1]: Unit docker.service entered failed state.
Nov 12 22:39:02 node01 systemd[1]: docker.service failed.
[root@node01 docker]# docker ps -a
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

其错误原因为修改 daemon配置文件时,配置中英文字符输入错误,修改后会正确。

 

posted @ 2021-11-13 15:10  wangSir1  阅读(742)  评论(0编辑  收藏  举报