Skip to content

Docker cgroup driver configuration for Kubernetes

The Docker cgroup driver configuration is a critical system setting that ensures resource management compatibility between the container runtime and the Kubernetes kubelet^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md]. For a Kubernetes cluster to function correctly, the cgroup driver used by the kubelet must match the cgroup driver used by Docker^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md].

Problem Identification

A mismatch between these drivers is a common cause of cluster instability or startup failures^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md]. This specific issue manifests as error messages indicating that the kubelet is unhealthy, such as:

[kubelet-check] It seems like the [kubelet](<./kubelet.md>) isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error:
Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused.
^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md]

This occurs because the kubelet's attempt to interact with the container runtime fails due to differing resource management strategies (e.g., one is set to cgroupfs while the other expects systemd).

Configuration Procedure

To resolve this mismatch, Docker must be configured to use the systemd cgroup driver, which aligns with the default kubelet configuration on many Linux distributions^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md].

  1. Create or modify the Docker daemon configuration file: Open or create /etc/docker/daemon.json^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md].
  2. Set the execution options: Add the native.cgroupdriver key with the value systemd^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md].

    {
        "exec-opts": ["native.cgroupdriver=systemd"]
    }
    
    [400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md]

  3. Apply changes: Restart the Docker service to load the new configuration^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md].

    sudo systemctl restart docker
    
    [400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md]

Sources

^[400-devops__06-Kubernetes__k8s-learning__00.install__01.使用部署工具安装_Kubernetes.md]