Sphere
Log in Join

kubeadm init fails with 'container runtime is not running' on Ubuntu 22.04

I was rebuilding a staging cluster on a Tuesday because someone had "cleaned up" a node and removed /etc/kubernetes. Three Ubuntu 22.04 VMs, kubeadm 1.29.2, containerd installed from the Docker apt repo. The control plane had come up fine six weeks earlier, so I expected this to take twenty minutes. It took most of the afternoon.

## The error I kept getting

[preflight] Running pre-flight checks
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: time="2024-03-12T09:41:22Z" level=fatal msg="validate service connection: CRI v1 runtime API is not implemented for endpoint \"unix:///var/run/containerd/containerd.sock\": rpc error: code = Unimplemented desc = unknown service runtime.v1.RuntimeService"
[PREFLIGHT] Some fatal errors occurred:

The bit that threw me was "runtime API is not implemented". That sounds like a version mismatch, so I spent half an hour comparing containerd versions between this node and the one that still worked. Both were 1.7.13. No mismatch.

## What I checked first, uselessly

I restarted containerd. I checked the socket existed. I even reinstalled containerd.io, which is the kind of thing you do when you are tired and not thinking. systemctl status containerd showed active and running, and /var/run/containerd/containerd.sock was there. The crictl info command was the first thing that actually told me something:

$ crictl info
{
"status": {
"conditions": [
{
"type": "RuntimeReady",
"status": false,
"reason": "runtimenotready",
"message": ""
}
]
}
}

RuntimeReady false with an empty message. Not helpful on its own, but it confirmed the problem was in containerd and not in kubeadm or the kernel modules.

## The actual cause

The package install had dropped a default /etc/containerd/config.toml with this near the top:

disabled_plugins = ["cri"]

I still don't know why that file was there. The other node had no config.toml at all, which is why it worked. Somebody had run containerd config default > /etc/containerd/config.toml once and left the stock output in place. The stock output disables CRI because Docker built containerd for their own use first, and kubeadm needs exactly the plugin that got disabled.

## The fix

Generate a fresh config and flip the cgroup driver, since Ubuntu 22.04 uses systemd and kubelet defaults to systemd too:

sudo mv /etc/containerd/config.toml /etc/containerd/config.toml.bak
sudo containerd config default | sudo tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
sudo systemctl restart containerd
crictl info | grep -A2 RuntimeReady

After that crictl info came back with "status": true and kubeadm init got past preflight. It still complained about the kubelet service not being enabled, which is a warning, not a problem.

## Joining the workers

The two workers had the same config.toml problem. I copied the fixed file over, restarted containerd, and joined them with the token from the control plane. One worker came up immediately. The other sat in NotReady because I had forgotten to load br_netfilter:

sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
overlay
EOF

Then kubectl get nodes showed all three Ready. If you are hitting the CRI error, check config.toml before you start reinstalling things. It is almost always that one line.