Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active January 14, 2024 20:28
Show Gist options
  • Save ruanbekker/fcc906bdcb2fed5937f7ce73a97e1001 to your computer and use it in GitHub Desktop.
Save ruanbekker/fcc906bdcb2fed5937f7ce73a97e1001 to your computer and use it in GitHub Desktop.
Install k3s on Alpine Linux
$ apk add --no-cache curl
$ echo "cgroup /sys/fs/cgroup cgroup defaults 0 0" >> /etc/fstab

$ cat > /etc/cgconfig.conf <<EOF
mount {
  cpuacct = /cgroup/cpuacct;
  memory = /cgroup/memory;
  devices = /cgroup/devices;
  freezer = /cgroup/freezer;
  net_cls = /cgroup/net_cls;
  blkio = /cgroup/blkio;
  cpuset = /cgroup/cpuset;
  cpu = /cgroup/cpu;
}
EOF

$ sed -i 's/default_kernel_opts="pax_nouderef quiet rootfstype=ext4"/default_kernel_opts="pax_nouderef quiet rootfstype=ext4 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory"/g' /etc/update-extlinux.conf

$ update-extlinux
$ reboot
$ apk add --no-cache cni-plugins --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
$ export PATH=$PATH:/usr/share/cni-plugins/bin
$ echo -e '#!/bin/sh\nexport PATH=$PATH:/usr/share/cni-plugins/bin' > /etc/profile.d/cni.sh
$ apk add iptables
$ wget https://github.com/rancher/k3s/releases/download/v1.17.4%2Bk3s1/k3s
$ mv k3s /usr/bin/
$ chmod +x /usr/bin/k3s

or

$ curl -sfL https://get.k3s.io | sh -
$ kubectl get nodes
NAME     STATUS   ROLES    AGE     VERSION
server   Ready    master   3m40s   v1.17.4+k3s1

# token: /var/lib/rancher/k3s/server/node-token
@cacharle
Copy link

cacharle commented Nov 1, 2023

It mostly worked for me except that I had to use cgroup v2 instead of v1 (only v2, not both version at the same time).

I had to modify the line in /etc/fstab to:

cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0

and in /etc/rc.conf I have:

rc_cgroup_mode="unified"
rc_cgroup_controllers="cpuset cpu io memory hugetlb pids"
rc_controller_cgroups="YES"

mostly from the Gentoo wiki page

The k3s FAQ states it aswell: https://docs.k3s.io/advanced#known-issues-with-rootless-mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment