Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Last active January 14, 2024 20:28
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • 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
@dyipon
Copy link

dyipon commented Sep 16, 2020

apk add --no-cache cni-plugins --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing command gives:
fetch http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
cni-plugins (missing):
required by: world[cni-plugins]"

testing should be community: "--repository=http://dl-cdn.alpinelinux.org/alpine/edge/community"

@ruanbekker
Copy link
Author

Thanks so much @dyipon, gist has been updated

@ky-bd
Copy link

ky-bd commented Jul 5, 2023

Cgroup V2 can be enabled in Alpine, and no need for manual V1 mount point and kernel cmdline options: https://liet.me/2022/07/08/enable-cgroups-v2-in-alpine-linux/

Mount rootfs as shared: mount --make-rshared /

Also some packages might need installed to replace commands provided by busybox, since some k3s components don't play well with them. Here are some I discovered:

  • findutils (find)
  • util-linux (mount, umount, etc., maybe needed by some CSI plugins)
  • dbus (for machine-id)
  • iproute2 (bridge, though it seems already provided by cni-plugins)

@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