当前位置: 代码迷 >> 综合 >> Kubernetes启动报错 kubelet cgroup driver: “cgroupfs“ is different from dock
  详细解决方案

Kubernetes启动报错 kubelet cgroup driver: “cgroupfs“ is different from dock

热度:99   发布时间:2024-01-12 03:45:30.0

环境:

    docker:18.09.9

    kubernetes:1.17

错误信息:

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

错误原因:

    docker和k8s使用的cgroup不一致导致

解决办法:

    修改二者一致,统一使用systemd或者cgroupfs进行资源管理。由于k8s官方文档中指出使用cgroupfs管理docker和k8s资源,同时使用systemd管理节点上其他进程资源在服务器资源压力大时会出现不稳定,因此推荐修改docker和k8s统一使用systemd管理资源。

Cgroup drivers

When systemd is chosen as the init system for a Linux distribution, the init process generates and consumes a root control group (cgroup) and acts as a cgroup manager. Systemd has a tight integration with cgroups and will allocate cgroups per process. It’s possible to configure your container runtime and the kubelet to use cgroupfs. Using cgroupfs alongside systemd means that there will then be two different cgroup managers.

Control groups are used to constrain resources that are allocated to processes. A single cgroup manager will simplify the view of what resources are being allocated and will by default have a more consistent view of the available and in-use resources. When we have two managers we end up with two views of those resources. We have seen cases in the field where nodes that are configured to use cgroupfs for the kubelet and Docker, and systemd for the rest of the processes running on the node becomes unstable under resource pressure.

docker修改方法:

    在

cat > /etc/docker/daemon.json <<EOF
{"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

  重启docker:

systemctl restart docker

k8s修改方法:    

在 Master 节点上配置 kubelet 所需的 cgroup 驱动

使用 Docker 时,kubeadm 会自动为其检测 cgroup 驱动在运行时对 /var/lib/kubelet/kubeadm-flags.env 文件进行配置。 如果您使用了不同的 CRI, 您得把 /etc/default/kubelet 文件中的 cgroup-driver 位置改为对应的值,像这样:

KUBELET_EXTRA_ARGS=--cgroup-driver=<value>

这个文件将会被 kubeadm init 和 kubeadm join 用于为 kubelet 获取 额外的用户参数。

需要重启 kubelet:

systemctl daemon-reload
systemctl restart kubelet
  相关解决方案