Installing a k3s cluster on raspberry pi's.

Published on Sep 1, 2024, by TradeTinkerer

In this article we will describe how to create a highly available Kubernetes cluster using k3s.

For the cluster to be highly available we will need at least 3 master nodes, but other odd numbers of master nodes would also work.

Before we can install k3s we have to prepare some things on the Raspberry Pi’s.

Preparing the raspberry pi’s

For our cluster we will be using Ubuntu Server 24.04 LTS on Raspberry Pi 5’s.

Ubuntu is already installed on the Raspberry Pi’s.

Most of the commands should also work on Debian.

Updating Ubuntu / Debian

The first thing we do is update the OS, by running the following two commands, on all nodes:

// Terminal
sudo apt update
sudo apt upgrade

Updating the hosts file

Next, we update the hosts file (again on all nodes) so all the k3s nodes can consistently resolve each others IP addresses.

// /etc/hosts
192.168.10.1 tt-k3s-01
192.168.10.2 tt-k3s-02
192.168.10.3 tt-k3s-03
192.168.10.4 tt-k3s-04
192.168.10.5 tt-k3s-05
192.168.10.6 tt-k3s-06

Installing k3s

On the first node run the following command (Replace the SECRET with your own secret.):

// Terminal on the first node
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - server 
    --cluster-init 
    --tls-san=tt-k3s-01 
    --disable local-storage

On all the additional master nodes run the following command:

// Terminal on all additional master nodes
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - server 
    --cluster-init 
    --tls-san=tt-k3s-<Number of the master node> 
    --disable local-storage

You can check if all the nodes are running with the following command:

// Terminal on any of the master nodes
sudo kubectl get nodes

This should give you output similar to:

NAME        STATUS   ROLES                       AGE     VERSION
tt-k3s-01   Ready    control-plane,etcd,master   22m     v1.30.4+k3s1
tt-k3s-02   Ready    control-plane,etcd,master   9m18s   v1.30.4+k3s1
tt-k3s-03   Ready    control-plane,etcd,master   7m48s   v1.30.4+k3s1

On all additional agent nodes run the following command:

// Terminal on all agent nodes
curl -sfL https://get.k3s.io | K3S_TOKEN=SECRET sh -s - agent --server https://<IP address or hostname of server>:6443