k3s on Raspberry Pi 4 & 5: cgroups, MetalLB, and Real-World Setup


estimated read time: 3 minutes

Preparing the Raspberry Pis

Installing Raspberry Pi OS

  1. Download the Raspberry Pi Imager tool — video tutorial
  2. Visit https://www.raspberrypi.com/software/
  3. Choose to install the x64 version of Raspberry Pi OS

Raspberry Pi Imager OS version selection

  1. Enable SSH

Enabling SSH in Raspberry Pi Imager settings

  1. Set the sudo username and password

Setting password in Raspberry Pi Imager

  1. Configure the hostname

Configuring hostname in Raspberry Pi Imager

  1. Configure Wi-Fi (if not using Ethernet)

Configuring Wi-Fi in Raspberry Pi Imager

  1. Burn the image to the Pi and repeat for each device

K3s Installation

Installing Ansible on Linux / WSL / macOS

Skip this section if you’ve already got Ansible installed and configured. If not, the easiest method I’ve found is via pip.

Your package manager will depend on your operating system—in my case, I’m using Ubuntu:

sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip
sudo python3 -m pip install ansible

Alternatively, if you’d prefer not to install Ansible globally, you can create a local virtual environment:

cd ~
mkdir ansible
cd ./ansible
python -m venv ./local
source ./local/bin/activate
python3 -m pip install ansible

This creates a local directory containing Ansible and its dependencies. The source command attaches it to your current terminal session’s path. Note that you’ll need to run source ./local/bin/activate for each new terminal session.

Installing K3s via Ansible

  1. Clone the k3s-ansible repository
  2. Update the hosts.ini file with your master node (or master and workers if you have multiple Pis)
  3. Run the playbook:
ansible-playbook site.yml

Installing and Configuring kubectl

Once the Ansible script has completed, you’ll need to copy the kubeconfig file from the master node. The easiest way to do this is via SCP:

mkdir ~/.kube
scp pi@<master_node_ip>:/home/pi/.kube/config ~/.kube/config

Next, install kubectl:

sudo apt-get update
sudo apt-get install -y ca-certificates curl apt-transport-https
sudo curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl

For alternative installation methods, see the Kubernetes documentation.

Once installed, verify kubectl is working:

kubectl get pods -n kube-system

Alternative Management Tools

For those who prefer a more visual management experience, here are some excellent GUI and terminal tools:

Rancher

K9s


Pi Cluster Series