Based on the following pages https://medium.com/thinkport/how-to-build-a-raspberry-pi-kubernetes-cluster-with-k3s-76224788576c
This tutorial will be built on my Pi Hat Cluster which consists of the following
PiMaster | Raspberry Pi 4 | Controller |
P1 | Raspberry Pi Zero 2 | Worker |
P2 | Raspberry Pi Zero 2 | Worker |
P3 | Raspberry Pi Zero 2 | Worker |
P4 | Raspberry Pi Zero 2 | Worker |
First we install K3 on the Controller node, PiMaster, after SSHing to the node, we download and install K3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | keith@pimaster:~ $ curl -sfL https://get.k3s.io | sh - [INFO] Finding release for channel stable [INFO] Using v1.26.3+k3s1 as release [INFO] Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.26.3+k3s1/sha256sum-arm64.txt [INFO] Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.26.3+k3s1/k3s-arm64 [INFO] Verifying binary download [INFO] Installing k3s to /usr/local/bin/k3s [INFO] Finding available k3s-selinux versions sh: 407: [: k3s-selinux-1.2-2.el8.noarch.rpm: unexpected operator [INFO] Creating /usr/local/bin/kubectl symlink to k3s [INFO] Creating /usr/local/bin/crictl symlink to k3s [INFO] Creating /usr/local/bin/ctr symlink to k3s [INFO] Creating killall script /usr/local/bin/k3s-killall.sh [INFO] Creating uninstall script /usr/local/bin/k3s-uninstall.sh [INFO] env: Creating environment file /etc/systemd/system/k3s.service.env [INFO] systemd: Creating service file /etc/systemd/system/k3s.service [INFO] Failed to find memory cgroup, you may need to add "cgroup_memory=1 cgroup_enable=memory" to your linux cmdline (/boot/cmdline.txt on a Raspberry Pi) [INFO] systemd: Enabling k3s unit Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service. [INFO] systemd: Starting k3s Job for k3s.service failed because the control process exited with error code. See "systemctl status k3s.service" and "journalctl -xe" for details. |
Like most people we get an error installing it, so we need to modify the /boot/cmdline.txt as per the instructions here. At this point you need to apply the ‘cgroup_memory=1 cgroup_enable=memory’ settings into /boot/cmdline.txt in all 5 raspberry pis’
Once we have rebooted and made all 4 nodes are up and running by ssh’ing into each of them, we can continue the installation by first checking that its running on pimaster
1 2 3 | keith@pimaster:~ $ sudo kubectl get nodes NAME STATUS ROLES AGE VERSION pimaster Ready control-plane,master 94s v1.26.3+k3s1 |
Or
1 2 3 | keith@pimaster:~ $ sudo k3s kubectl get nodes NAME STATUS ROLES AGE VERSION pimaster Ready control-plane,master 2m22s v1.26.3+k3s1 |
Everything looks good but before we install the client onto each of our worker nodes we need 2 pieces of information
1 2 3 4 5 | keith@pimaster:~ $ hostname -I | awk '{print $1}' 192.168.0.92 keith@pimaster:~ $ sudo cat /var/lib/rancher/k3s/server/node-token K104df75d483d2757840111b488af863f546661dbf242d0f2af3e13fc8b1f63bb5f::server:0cd01c6668e6d23ec79451792037ac23 |
Now on each of the worker nodes running the following command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | pi@p1:~ $ curl -sfL https://get.k3s.io | K3S_URL=https://192.168.0.92:6443 K3S_TOKEN=K104df75d483d2757840111b488af863f546661dbf242d0f2af3e13fc8b1f63bb5f::server:0cd01c6668e6d23ec79451792037ac23 sh - [INFO] Finding release for channel stable [INFO] Using v1.26.3+k3s1 as release [INFO] Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.26.3+k3s1/sha256sum-arm.txt [INFO] Skipping binary downloaded, installed k3s matches hash [INFO] Skipping installation of SELinux RPM [INFO] Skipping /usr/local/bin/kubectl symlink to k3s, already exists [INFO] Skipping /usr/local/bin/crictl symlink to k3s, already exists [INFO] Skipping /usr/local/bin/ctr symlink to k3s, already exists [INFO] Creating killall script /usr/local/bin/k3s-killall.sh [INFO] Creating uninstall script /usr/local/bin/k3s-agent-uninstall.sh [INFO] env: Creating environment file /etc/systemd/system/k3s-agent.service.env [INFO] systemd: Creating service file /etc/systemd/system/k3s-agent.service [INFO] systemd: Enabling k3s-agent unit Created symlink /etc/systemd/system/multi-user.target.wants/k3s-agent.service → /etc/systemd/system/k3s-agent.service. [INFO] No change detected so skipping service start pi@p1:~ $ |