Deploying k0s to alpine
There's a couple of extra things that need to be done before you can run the k0s installer on an alpine host:
Start by enabling cgroups v2 and reboot:
#enable cgroups2
echo "rc_cgroup_mode=\"unified\"" >> /etc/rc.conf
reboot
Now start the cgroups service and add it to the startup scripts:
rc-service cgroups start
rc-update add cgroups
Now finally we need to ensure that k0s can access the node's "machine ID":
apk add dbus
rc-service dbus start
rc-update add dbus
That's it! That's the minimum needed to have k0s deployed to an alpine host.
As a bonus if you'd like to enable eBPF features as well then perform the following:
Edit the /etc/init.d/sysfs
file and add the following to the bottom of the mount_misc
section:
# setup kernel support for bpf file system
if [ -d /sys/fs/bpf ] && ! mountinfo -q /sys/fs/bpf; then
if grep -qs bpf /proc/filesystems; then
ebegin "Mounting eBPF filesystem"
mount -n -t bpf -o ${sysfs_opts} bpffs /sys/fs/bpf
eend $?
fi
fi
If you were deploying k0s with cilium instead of the default kube-router/kube-proxy combo you'll want to add the following after the mount
command above:
mount --make-shared /sys/fs/bpf
mount --make-shared /run/cilium/cgroupv2
So the full block will look like:
# setup kernel support for bpf file system
if [ -d /sys/fs/bpf ] && ! mountinfo -q /sys/fs/bpf; then
if grep -qs bpf /proc/filesystems; then
ebegin "Mounting eBPF filesystem"
mount -n -t bpf -o ${sysfs_opts} bpffs /sys/fs/bpf
mount --make-shared /sys/fs/bpf
mount --make-shared /run/cilium/cgroupv2
eend $?
fi
fi
Once you've done this you can activate these settings quickly by running /etc/init.d/sysfs restart
UPDATE 2024-08-25:
Another approach we're trialling is adding an openrc service. This means the two mount --make-shared
options above get removed from /etc/init.d/sysfs
and put into a new file: /etc/local.d/shared-mount.start
:
#!/bin/sh
# Make the mount point shared
mount --make-shared /sys/fs/bpf
mount --make-shared /run/cilium/cgroupv2
Then we make the file executable, add it to rc and start it up:
chmod +x /etc/local.d/shared-mount.start
rc-update add local default
rc-service local restart
This approach looks like it will be needed until the following PR makes its way into alpine, and then we can just set this up with /etc/fstab
. The fstab once this is in alpine should look something like this:
# file: /etc/fstab
none /sys/fs/bpf cgroup2 defaults,rshared 0 0
none /run/cilium/cgroupv2 cgroup2 defaults,rshared 0 0