Most people will start explaining to you what is K3s and what is the benefit of it, I am not most people, so if you want to familiarize yourself with it, I would recommend that you head over to their website and read the documentation.

Raspberry Pi

Hardware Requirements

Raspberry Pi 4 Specifications

While K3s does not require much, you will need to have your PI cluster ready, for example, as you can see in the image below, which is my setup, I am using:

  1. 3 RPIs gen 4 model B (4gb ram)
  2. 3 memory cards (64gb)
  3. 3 USB-c charging cables.

You can always choose whatever mounting solution for your RPIs and if you want to go to more extreme sense, you can get yourself a nice 3 ethernet cables and a hub so you connect your RPIs via ethernet instead of wifi, in my case, I am satisfied with my wifi connection.

Software Requirements

I'll assume that you have installed the latest version of Raspberry Pi OS and configure it as you like, if not, I recommend that you do so just keep in mind that its best to have the Raspberry Pi OS Lite (64bit) version, at the end you will be using your RPIs via terminal/cmd so no need for the graphical user interface.

Preparation

To be able to install K3s on your RPIs you will need to make a small modification, you will need to edit the boot/cmdline.txt file and add the following to it:

cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory

Basically, you will have to turnoff your RPI and take off the memory card and use your computer to edit that file, as from what I know you cant do that on your RPI.

Once you did for every single RPI you have, you are ready to go.

K3s

{{ .Site.Title }}

As any agent/server software, K3s runs in two modes, either a Server or an Agent. If you need to know more about the architecture you can read the docs here.

I know its a bit annoying to tell you to read the docs in other places, but I prefer to focus on the task which is setting you the PI cluster using K3s, and not teaching you about K3s.

The final results will be a Single Server Setup with an Embedded DB which is good for learning and experimenting K3s.

Server Installation

Installing K3s is a matter of just running a simple shell script from the command line, now, if you are running your PI as a root user (which I don't encourage), it will go like an easy sail, but if you are like me and you like to run your nodes as regular user you will face a small issue, which can be easily fixed by a small parameter.

Remember, you need to elect one of your nodes as the server node the other two will be your agents.

To be able to run the server as non-root user, at least this is how I've understand it, I need to make sure that the write more for my kubeconfig file is 644 . So the installation command would be:

curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=latest sh -s - --write-kubeconfig-mode 644

While it is not recommended to use the latest channel, I like to live on edge ? .

Once everything is finished, and you got no error you can check and confirm that K3s is running by issuing the command:

sudo systemctl status k3s.service

Now, before we jump to install the agents, we need to make sure to write down the server token, which can be found inside the following file:

sudo cat /var/lib/rancher/k3s/server/node-token

Keep this token safe, you will need it.

Before we start installing the agents, remember to edit the /etc/hosts file and identify each node you have, in each and every RPI you own (the one you want to install K3s on), something like

# remember to change the ips to your correct RPI ips
192.168.68.110  master
192.168.68.111  worker-1
192.168.68.112  worker-2

Agent Installation

You need to repeat those steps on the other two RPIs.

You already have the Token and you already know the IP of the K3s server, all you have to do is to run the following command:

curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=latest K3S_URL=https://192.168.68.110:6443 K3S_TOKEN=<REPLACE_WITH_YOUR_TOKEN> sh -

Validating your Setup

From your server node you can run the following command

$ kubectel get nodes

NAME       STATUS   ROLES                  AGE   VERSION
worker-1   Ready    <none>                 1h    v1.25.4+k3s1
worker-2   Ready    <none>                 1h    v1.25.4+k3s1
master     Ready    control-plane,master   1h    v1.25.4+k3s1

For sure the version/age would be different, but the concept is the same.

With that you now have your own K3s up and running, and ready for you to start toying around.