0
0
Iot-protocolsHow-ToIntermediate · 4 min read

Raspberry Pi Project: Build a Kubernetes Cluster Easily

You can build a Kubernetes cluster using multiple Raspberry Pi devices by installing a lightweight Kubernetes distribution like k3s. This project involves setting up each Pi as a node, configuring networking, and deploying containerized apps to practice cloud-native skills.
📐

Syntax

To set up a Kubernetes cluster on Raspberry Pi, you mainly use k3s, a lightweight Kubernetes version. The basic commands include:

  • curl -sfL https://get.k3s.io | sh -: Installs k3s on a node.
  • k3s agent --server https://:6443 --token : Joins a node to the cluster.
  • kubectl get nodes: Lists all nodes in the cluster.

Each part helps you install, join nodes, and manage the cluster.

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

# On master node, get token:
sudo cat /var/lib/rancher/k3s/server/node-token

# On worker node, join cluster:
k3s agent --server https://<master-ip>:6443 --token <node-token>

# Check nodes:
kubectl get nodes
💻

Example

This example shows how to install k3s on a Raspberry Pi master node and join a worker node to form a simple Kubernetes cluster.

bash
# On Raspberry Pi Master Node
curl -sfL https://get.k3s.io | sudo sh -

# Get the node token
sudo cat /var/lib/rancher/k3s/server/node-token

# On Raspberry Pi Worker Node
curl -sfL https://get.k3s.io | K3S_URL=https://<master-ip>:6443 K3S_TOKEN=<node-token> sudo sh -

# On Master Node, check nodes
kubectl get nodes
Output
NAME STATUS ROLES AGE VERSION master Ready control-plane,master 5m v1.26.3+k3s1 worker1 Ready <none> 2m v1.26.3+k3s1
⚠️

Common Pitfalls

Common mistakes include:

  • Using incompatible Raspberry Pi models or OS versions that don't support k3s.
  • Not setting static IPs or proper hostnames, causing node connection failures.
  • Ignoring firewall or network settings blocking Kubernetes ports.
  • Running k3s install commands without sudo, leading to permission errors.

Always verify network connectivity and use supported Raspberry Pi OS versions like Raspberry Pi OS Lite.

bash
## Wrong: Running install without sudo
curl -sfL https://get.k3s.io | sh -

## Right: Use sudo for permissions
curl -sfL https://get.k3s.io | sudo sh -
📊

Quick Reference

Summary tips for Raspberry Pi Kubernetes cluster:

  • Use Raspberry Pi 3 or newer for better performance.
  • Install Raspberry Pi OS Lite (64-bit recommended).
  • Set static IP addresses for all nodes.
  • Use k3s for lightweight Kubernetes.
  • Check node status with kubectl get nodes.
  • Secure your cluster with proper tokens and firewall rules.

Key Takeaways

Use k3s to install a lightweight Kubernetes cluster on Raspberry Pi devices.
Set static IPs and ensure network connectivity between all Raspberry Pi nodes.
Run installation commands with sudo to avoid permission issues.
Verify cluster health using kubectl commands after setup.
Choose Raspberry Pi 3 or newer and Raspberry Pi OS Lite for best results.