K8s automatic setup causing kubelet.service fail to start after reboot

This is a bug report of the bundle cloud-native-basic,
about the k8s automatic setup script /usr/share/clr-k8s-examples/setup_system.sh

Kubelet require disabling swap to start. setup_system.sh does disable swap when running, however, it fails to disable swap permanently. Swap is re-enabled after reboot:

cat /proc/swaps
Filename				Type		Size		Used		Priority
/var/swapfile           file		65532		0		-2

This causes kubelet.service to fail, after setup via setup_system.sh, after a reboot: (from journalctl)

kubelet[1280]: F0126 04:57:17.725711    1280 server.go:265] failed to run Kubelet: running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false. /proc/swaps contained: [Filename                                Type                Size                Used                Priority /var/swapfile                           file                65532                0                -2]

Should I post it also to the github repo ?

2 Likes

The problem is in function disable_swap:
It detects only /dev/, by doing this (line#32, line#35)

sudo grep '^/dev/\([0-9a-z]*\).*' /proc/swaps | wc -l)
sed -n -e 's#^/dev/\([0-9a-z]*\).*#dev-\1.swap#p' /proc/swaps

so it fails to detect the swapfile /var/swapfile.

However, line#140 sudo swapoff -a does disable swap temporarily.

So place try to detect also swap files in setup_system.sh.

The best way to disable swap permanently is to use systemctl

sudo systemctl mask swap.target

This change is in the latest version of the setup_system.sh script.

1 Like