Issue#
After a reboot, a node shows NotReady, or kubeadm init/kubeadm join fails. The kubelet keeps restarting, and its logs show this error:
journalctl -u kubelet -n 20 --no-pager
"command failed" err="failed to run Kubelet: running with swap on is not supported, please disable swap or set --fail-swap-on flag to false"
Cause#
By default the kubelet runs with failSwapOn: true. It will not start if any swap device is active. Running swapoff -a fixes it only until the next reboot. After that, swap comes back from one of these sources:
- an entry in
/etc/fstab - a systemd
.swapunit, which systemd generates automatically from the GPT swap partition type - zram, which is enabled by default on some distributions
Solution#
- Check which swap devices are active:
swapon --show
- Turn off swap immediately:
sudo swapoff -a
- Comment out the swap entries in
/etc/fstabso they don't come back on boot. The.baksuffix keeps a backup copy:
sudo sed -i.bak '/\sswap\s/ s/^\([^#]\)/#\1/' /etc/fstab
grep swap /etc/fstab
- List the swap units that systemd manages, then mask any that are still active. Use the unit names from your own output:
systemctl --type swap --all
sudo systemctl mask dev-sda3.swap
- If swap comes from zram, disable that too. Use whichever command matches your setup:
# systemd zram-generator (Fedora, Ubuntu 24.04+ with zram)
sudo systemctl mask systemd-zram-setup@zram0.service
# Debian/Ubuntu zram-tools
sudo systemctl disable --now zramswap.service
- Restart the kubelet:
sudo systemctl restart kubelet
Tip: If you need to keep swap, recent Kubernetes versions on cgroup v2 support it through the
NodeSwapfeature. Add the settings below to/var/lib/kubelet/config.yamland restart the kubelet. WithLimitedSwap, only Burstable pods can use swap.
failSwapOn: false
memorySwap:
swapBehavior: LimitedSwap
Verify#
Confirm that no swap is active. The first command should print nothing, and the Swap: line should show 0B:
swapon --show
free -h | grep -i swap
Confirm that the kubelet is running and the node is Ready:
systemctl is-active kubelet
kubectl get nodes
Reboot the node once and run swapon --show again. If it still prints nothing, the fix is permanent.