As I might have mentioned, I like self-hosting. I have the knowledge, and I want to have the convenience; and what is more convenient than cloud self-hosting? You can deploy and try your projects, wipe them, have your infra at your fingertips. Lovely. For this end, Kubernetes is critical.
I chose k3s from SUSE Linux (my first distro, by the way) because it runs well on Raspberry Pi, and my infra is made of that. I also love that I do not have to install Docker manually anymore.
1
curl -sfL https://get.k3s.io | sh -
1 GB is not enough
I tried having the main server on an old Raspberry Pi with 1 GB, but k3s complained. Most disappointing.
msg=”failed to find memory cgroup (v2)”
The first thing that looks like an issue is that the memory cgroups are not installed by default in Raspbian. Not sure why they are disabled, as I think that is common for users to want their mini cluster, but meh.
Memory cgroup is critical for containerization. It was enough to enable the memory cgroup, and all started as expected. I followed this comment on GitHub.
In /boot/cmdline.txt
, add
1
cgroup_memory=1 cgroup_enable=memory
then reboot
and working k8s cluster.
Cluster Config
I have two Raspberry Pis, and one is going to be the server, and the other the agent. The new one is going to be the agent, so on the server called kracken
, I am going to
1
2
systemctl stop k3s.service
k3s server &
and reboot to start in server mode. Such mode is the default for the installation of k3s. Now for me, kracken
is in server mode.
The next step is just to install k3s
on the other node, called lehvniathan
, and set it as an agent. To do that, one needs to edit /etc/systemd/system/k3s.service
and set the correct token from kracken
. Let me repeat that one needs to copy the token from the server to the client, so the agent can collaborate.
On the server, the token is:
1
cat /var/lib/rancher/k3s/server/token
On the agent, we need to modify /etc/systemd/system/k3s.service
:
1
2
3
4
[Service]
...
ExecStart=/usr/local/bin/k3s \
server \
to:
1
2
3
4
[Service]
...
ExecStart=/usr/local/bin/k3s \
agent --server https://kracken:6443 --token <token>
and reboot both for good measure. On the server, you should get:
1
k3s kubectl get node
1
2
3
4
5
6
7
root@kracken:/home/bruno# k3s kubectl get node
NAME STATUS ROLES AGE VERSION
lehvniathan Ready <none>
50m v1.26.5+k3s1
kracken Ready control-plane,master 56m v1.26.5+k3s1
root@kracken:/home/bruno#
Congratulations! The base cluster with two nodes is up, and it is easy to add more. Sometime in the future, I will put a UI on it