System Administration & Network Administration
docker kubernetes containerd
Updated Tue, 20 Sep 2022 21:53:13 GMT

Force kubernetes to use containerd when docker is installed


I have Kubernetes nodes with both docker and containerd installed. I need docker on the node to run CI pipelines and builds. How can I make Kubernetes use the recommended containerd instead of docker? Existing documentation recommands to remove docker from the system, which is not desirable for my case.

Is there a way to force Kubernetes to use containerd as a container runtime instead of docker when both are installed?




Solution

Tested on Ubunut 20.04, a simple and clean way to enable containerd runtime was to add this content to /etc/systemd/system/kubelet.service.d/20-use-containerd.conf:

Environment="KUBELET_EXTRA_ARGS=--container-runtime remote --container-runtime-endpoint=unix:///var/run/containerd/containerd.sock"

This adds some extra arguments to the kubelet service, to enable containerd instead of relying on docker-shim by default.

It is recommanded to restart the node, or at least stop kubelet, docker and containerd for the switch, as a simple kubelet restart will try to run the containers via containerd while they are still running using docker.