K3s Raspberry Pi 5 Cluster Architecture

The Raspberry Pi 5 serves as a powerhouse in the single-board computer landscape, establishing itself as an ideal hardware foundation for deploying lightweight Kubernetes distributions such as K3s. For users constructing a home lab or implementing edge computing clusters, K3s provides a streamlined and efficient mechanism for managing containerized workloads. This orchestration framework allows for the deployment of applications that can scale dynamically and recover automatically; if a pod fails, Kubernetes handles the rescheduling of that pod onto remaining active nodes, ensuring high availability and resilience.

Integrating K3s on Raspberry Pi 5 hardware enables users to gain hands-on experience with container orchestration, infrastructure management, and automation. Practical applications for such a cluster include self-hosting services like Pi-hole for network-wide advertisement blocking or Home Assistant for the management of smart home devices. While larger refurbished compute nodes like Lenovo ThinkCentres or HP EliteDesks offer significant power, the Raspberry Pi 5 provides a portable, lightweight alternative that is easy to transport—even in carry-on luggage—without sacrificing the ability to experiment with the cloud-native ecosystem.

Hardware Infrastructure and Specifications

The physical foundation of a K3s cluster determines the stability and performance of the containerized workloads. When selecting hardware for a Raspberry Pi 5 deployment, specific considerations regarding memory and storage are paramount.

The Raspberry Pi 5 requires a minimum of 4GB of RAM to function as a K3s node, although 8GB is highly recommended for those intending to run larger, more resource-intensive workloads. This memory capacity is critical because Kubernetes and its associated agents consume a baseline amount of system resources before any application pods are deployed.

Storage medium selection is one of the most critical decisions in the infrastructure phase. While a high-quality microSD card of 32GB or larger is a viable starting point, it is not optimal for long-term production or high-load environments. K3s utilizes etcd, which is a write-intensive database. SD cards and eMMC storage typically cannot handle the sustained IO load generated by etcd, leading to potential performance degradation or premature hardware failure. Therefore, the use of an external SSD via USB is strongly recommended to ensure optimal speed and endurance.

The networking architecture for a multi-node cluster typically involves connecting multiple Raspberry Pi 5 units through a network switch, which then connects to a central router. This topology ensures low-latency communication between the control plane and worker nodes.

Component Minimum Requirement Recommended Specification
RAM 4GB 8GB
Storage 32GB microSD External SSD (USB)
OS Raspberry Pi OS (64-bit) Raspberry Pi OS (64-bit)
Network Stable Ethernet/WiFi Wired Switch Connection

Server Sizing and Scalability

The capacity of a K3s cluster to manage agent nodes is directly tied to the CPU and RAM available on the server (control-plane + etcd) node. This relationship defines the scaling limits of the environment.

Under standard workload conditions, a server with 2 CPUs and 4GB of RAM can support between 0 and 350 agents. Increasing the resources to 4 CPUs and 8GB of RAM extends this limit to a range of 351 to 900 agents. For larger enterprise-grade or highly complex home labs, a server with 8 CPUs and 16GB of RAM can manage 901 to 1800 agents, while 16+ CPUs and 32GB of RAM allow for 1800+ agents.

In scenarios requiring high availability (HA), where three server nodes are utilized in a configuration, the scaling capacity increases by approximately 50%. For example, a three-server setup where each node has 4 vCPU and 8GB of RAM can scale to approximately 1200 agents.

To maintain cluster stability during the expansion process, it is recommended to join agent nodes in batches of 50 or fewer. This prevents the CPU from becoming overwhelmed by the spike in resource usage that occurs during the node join process. Additionally, if a user intends to expand the cluster beyond 255 nodes, the default cluster-cidr must be modified.

System Preparation and OS Configuration

Before the installation of K3s, the underlying Raspberry Pi OS must be optimized to support the specific requirements of Kubernetes.

The first phase of software preparation involves updating the system to ensure all current packages are at their latest versions. This is achieved through the following commands:

sudo apt update -y

Following the update, essential utilities for downloading and executing scripts must be present on the system. Users should ensure curl and wget are installed:

sudo apt install -y curl wget

A critical requirement for Kubernetes is cgroup support. Without the proper enabling of cgroup memory management, the K3s service will fail to initialize. This requires editing the boot configuration file of the Raspberry Pi.

Users must access the cmdline.txt file located in the boot directory:

sudo nano /boot/firmware/cmdline.txt

At the end of the existing line, the following parameters must be added. It is vital that these parameters remain on the same line as the existing text:

cgroup_memory=1 cgroup_enable=memory

Once these changes are saved, the system must be rebooted to apply the kernel parameters:

sudo reboot

K3s Installation Process

K3s is designed for fast installation on resource-limited devices. The installation is typically performed via a one-liner script that automates the deployment of the K3s binary and the necessary service configurations.

To install K3s as a server (which also acts as the control plane and creates a single-node cluster), the following command is executed:

curl -sfL https://get.k3s.io | sh -

This script performs several actions, including the installation of the k3s.service, which ensures the Kubernetes environment starts automatically upon boot.

Once the installation script completes, the operational status of the service should be verified:

sudo systemctl status k3s

If the service is listed as active and running, the control plane is successfully deployed.

Cluster Configuration and Management

After the installation, the user must verify the health of the cluster and configure the environment for easier management of the Kubernetes API.

K3s installs kubectl by default. To verify that the node is correctly recognized and in a Ready state, the following command is used:

sudo kubectl get nodes

To avoid the constant use of sudo and to streamline the interaction with the cluster, the K3s kubeconfig file should be copied to the user's home directory. This process involves creating a directory for Kubernetes configurations and copying the YAML file:

mkdir -p ~/.kube

sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config

sudo chown $(id -u):$(id -g) ~/.kube/config

With the kubeconfig properly placed in the home directory, users can interact with the cluster using standard kubectl commands:

kubectl get nodes

Expanding the Cluster with Worker Nodes

One of the primary advantages of Kubernetes is the ability to distribute workloads across multiple nodes. To add a Raspberry Pi as a worker (agent) node, a security token must be retrieved from the server node.

The node token is stored in a specific file on the master node:

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

Once this token is copied, the user must navigate to the worker node and run the installation script. This command requires the URL of the master node (on port 6443) and the previously retrieved token:

curl -sfL https://get.k3s.io | K3S_URL=https://<SERVER_IP>:6443 K3S_TOKEN=<NODE_TOKEN> sh -

Networking and Connectivity

Proper networking is essential for the communication between the control plane and the worker nodes.

The K3s server must ensure that port 6443 is accessible to all nodes in the cluster. This port is the primary gateway for the Kubernetes API.

For internal node-to-node communication, K3s utilizes the Flannel backend. Depending on the configuration, different UDP ports must be open:

  • When using the Flannel VXLAN backend, UDP port 8472 must be accessible.
  • When using the Flannel WireGuard backend, UDP port 51820 must be accessible (and port 51821 if IPv6 is enabled).

The nodes should not listen on any other ports unless specifically required by the deployed applications.

Advanced Automation and Infrastructure as Code

For those managing larger clusters or wishing to implement a reproducible environment, automation tools like Ansible are highly effective.

Using an Ansible approach, the deployment is managed via a hosts.ini inventory file that describes the masters and nodes. Configuration variables, such as the ansible_user, are defined in inventory/group_vars/all.yml. To execute the deployment, the following command is used:

ansible-playbook site.yml -i inventory/hosts.ini

To connect to an Ansible-managed cluster from a remote workstation, the kubeconfig must be transferred via secure copy:

scp pirate@turing-master:~/.kube/config ~/.kube/config-turing-pi

The user then sets the KUBECONFIG environment variable to point to this specific configuration:

export KUBECONFIG=~/.kube/config-turing-pi

kubectl get nodes

One of the significant advantages of using Ansible is the ability to perform a cluster-wide reset. If the configuration becomes corrupted or the user wishes to start fresh, a reset playbook can be executed:

ansible-playbook reset.yml -i inventory/hosts.ini

Furthermore, Ansible allows for the graceful shutdown of all nodes in a cluster simultaneously, rather than logging into each Raspberry Pi individually to run the shutdown command.

Troubleshooting Common Issues

During the installation and operation of K3s on Raspberry Pi, users may encounter specific errors.

If the k3s.service fails to start, users should examine the system logs for specific error messages:

journalctl -u k3s -e

In cases where kubectl is not found, users should either use the sudo k3s kubectl prefix or ensure that the kubeconfig has been properly set up in the ~/.kube/config path.

If the token file is missing, it is an indication that the user is attempting to retrieve the token from a worker node rather than the master node.

Network errors often stem from incorrect cgroup settings in cmdline.txt or restrictive firewall rules that block the required ports (6443, 8472, 51820).

Problem Solution
k3s.service fails to start Check logs: journalctl -u k3s -e
kubectl not found Use sudo k3s kubectl or set up kubeconfig
Token file missing Confirm you are on the master node
Network errors Check cgroup settings and firewalls

Analysis of K3s on Raspberry Pi 5

The deployment of K3s on the Raspberry Pi 5 represents a shift in how home labs and edge computing environments are constructed. By leveraging the ARM-based architecture of the Pi 5, users can implement a full-scale Kubernetes orchestration layer with minimal power consumption and a small physical footprint.

The transition from SD cards to NVMe SSDs is the most impactful hardware upgrade available. Because etcd is write-intensive, the move to SSDs does not just increase speed; it fundamentally changes the reliability of the cluster. The IO load of etcd on an SD card represents a primary point of failure in these systems.

From a scalability perspective, the K3s server sizing guide indicates that the Raspberry Pi 5's 8GB variant is the sweet spot for most enthusiasts, allowing for the management of up to 900 agents. This capacity is far beyond the needs of typical home automation or development environments, meaning the hardware will not be the bottleneck for the foreseeable future.

The use of Ansible for the lifecycle management of the cluster—from installation to reset and shutdown—highlights the transition from manual "tinkering" to a professional Infrastructure-as-Code (IaC) workflow. This allows users to treat their hardware as disposable (cattle, not pets), as the entire cluster state can be wiped and redeployed in minutes via the reset.yml and site.yml playbooks.

Ultimately, the combination of K3s and Raspberry Pi 5 provides a low-barrier entry point into the world of cloud-native computing. It allows for the practical application of high-availability concepts, pod rescheduling, and container orchestration without the need for expensive cloud subscriptions or bulky server hardware.

Sources

  1. Installing K3s on the Raspberry Pi 5: A Step-by-Step Guide
  2. K3S on Raspberry Pi 5
  3. KevsRobots Learning Platform
  4. K3s Installation Requirements
  5. Installing K3s on Turing Pi Raspberry Pi Cluster

Related Posts