Issue#
After kubeadm init (or after adding a new worker), the node stays NotReady. CoreDNS and new pods stay in Pending or ContainerCreating.
kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-cp01 NotReady control-plane 12m v1.31.2
kubectl describe node shows:
Ready False KubeletNotReady container runtime network not ready: NetworkReady=false
reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized
Cause#
The kubelet only marks a node Ready when the container runtime reports a working CNI network. That requires two things on every node:
- A CNI config file in
/etc/cni/net.d/, normally written by the CNI DaemonSet such as Flannel or Calico. - The CNI plugin binaries (
bridge,loopback,portmap, etc.) in/opt/cni/bin/.
kubeadm does not install a network add-on. If no CNI was applied, or the binaries are missing on a node, you get this error.
Solution#
- Check what is on the affected node:
ls -l /etc/cni/net.d/
ls -l /opt/cni/bin/
sudo journalctl -u kubelet --since "10 min ago" | grep -i cni
- Check the pod CIDR the cluster was initialised with, because the CNI must match it:
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.podCIDR}{"\n"}{end}'
- If no CNI is installed, apply one. Flannel expects
10.244.0.0/16, which is the value passed withkubeadm init --pod-network-cidr=10.244.0.0/16:
sudo modprobe br_netfilter
echo br_netfilter | sudo tee /etc/modules-load.d/br_netfilter.conf
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl -n kube-flannel get pods -o wide
Note: If your pod CIDR is different, download the manifest and change
Networkin thekube-flannel-cfgConfigMap before you apply it.
- If the CNI pods are running but
/opt/cni/binis empty on a node, install the standard plugins on that node:
CNI_VERSION=v1.5.1
sudo mkdir -p /opt/cni/bin
curl -fsSL "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" \
| sudo tar -xz -C /opt/cni/bin
- Make sure containerd looks in the same directories:
sudo containerd config dump | grep -E 'bin_dir|conf_dir'
- Restart the runtime and the kubelet:
sudo systemctl restart containerd
sudo systemctl restart kubelet
Verify#
kubectl get nodes
kubectl -n kube-system get pods -l k8s-app=kube-dns
kubectl run nettest --image=busybox:1.36 --restart=Never -- sleep 3600
kubectl get pod nettest -o wide
kubectl delete pod nettest
The node should be Ready, CoreDNS should be Running, and the test pod should get an IP from the pod CIDR.
Tip: Only install one CNI. Leftover files from a previous CNI in
/etc/cni/net.d/are read in lexical order and can override the one you expect. Remove stale configs and then restart containerd.