Skip to content

Instantly share code, notes, and snippets.

@jimangel
Last active April 19, 2022 19:08
Show Gist options
  • Save jimangel/21568c757b2b374cabb8cc53e6c9125f to your computer and use it in GitHub Desktop.
Save jimangel/21568c757b2b374cabb8cc53e6c9125f to your computer and use it in GitHub Desktop.
Change kubelet / docker cgroup driver

Fixes errors in Kubernetes v1.22+:

  • kubelet cgroup driver: \"cgroupfs\" is different from docker cgroup driver: \"systemd\""
  • kubelet cgroup driver: \"systemd\" is different from docker cgroup driver: \"cgroupfs\""

By setting both to use systemd as preferred by kubeadm.

Kubeadm: remove the automatic detection and matching of cgroup drivers for Docker. For new clusters if you have not configured the cgroup driver explicitly you might get a failure in the kubelet on driver mismatch (kubeadm clusters should be using the systemd driver). Also remove the IsDockerSystemdCheck preflight check (warning) that checks if the Docker cgroup driver is set to systemd. Ideally such detection / coordination should be on the side of CRI implementers and the kubelet. Please see the page on how to configure cgroup drivers with kubeadm manually

#####################################
# for kublet
#####################################

# update the config file
sudo sed -i "s/cgroupDriver: cgroupfs/cgroupDriver: systemd/g" /var/lib/kubelet/config.yaml

# restart kubelet
service kubelet restart

# ensure it started
service kubelet status

# debug with journalctl
journalctl -u kubelet -n 100

#####################################
# for Docker
#####################################

# create a daemon.json config file
cat << EOF | sudo tee -a /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF

# restart Docker
sudo systemctl restart docker

# check the output to confirm success
sudo docker info | grep Cgroup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment