How to Use Kubernetes on Raspberry Pi: Setup and Basics
To use
Kubernetes on a Raspberry Pi, install a lightweight Kubernetes distribution like k3s or microk8s on your Pi devices. Then, initialize the cluster on one Pi and join other Pis as worker nodes using the provided join commands.Syntax
Here is the basic syntax to install and set up Kubernetes on Raspberry Pi using k3s:
curl -sfL https://get.k3s.io | sh -: Installs k3s on the Pi.sudo k3s kubectl get nodes: Checks the status of nodes in the cluster.sudo k3s agent --server https://: Joins a worker node to the cluster.:6443 --token
Each part is a command to install, check, or join nodes in the Kubernetes cluster.
bash
curl -sfL https://get.k3s.io | sh - sudo k3s kubectl get nodes sudo k3s agent --server https://<server-ip>:6443 --token <node-token>
Example
This example shows how to install k3s on a Raspberry Pi master node and join a worker node.
First, run this on the master Pi:
bash
curl -sfL https://get.k3s.io | sh -
sudo k3s kubectl get nodesOutput
NAME STATUS ROLES AGE VERSION
raspberrypi Ready control-plane,master 1m v1.27.4+k3s1
Example
Then, on the worker Pi, join the cluster using the token and IP from the master node:
bash
sudo k3s agent --server https://192.168.1.100:6443 --token K107f1a2b3c4d5e6f7g8h9i0jklmnopqrstuCommon Pitfalls
- Architecture mismatch: Raspberry Pi uses ARM CPU, so use ARM-compatible Kubernetes versions like
k3sormicrok8s. - Network issues: Ensure all Pis are on the same network and ports like 6443 are open.
- Token errors: Use the exact token from the master node when joining workers.
- Insufficient resources: Raspberry Pis have limited CPU and RAM; avoid heavy workloads.
bash
## Wrong: Using x86 Kubernetes version curl -sfL https://get.kubernetes.io | sh - # This will fail on ARM ## Right: Use k3s for ARM curl -sfL https://get.k3s.io | sh -
Quick Reference
| Command | Purpose |
|---|---|
| curl -sfL https://get.k3s.io | sh - | Install k3s Kubernetes on Raspberry Pi |
| sudo k3s kubectl get nodes | List nodes in the Kubernetes cluster |
| sudo k3s agent --server https:// | Join a worker node to the cluster |
| sudo systemctl status k3s | Check k3s service status |
| sudo k3s kubectl get pods -A | List all pods in all namespaces |
Key Takeaways
Use lightweight Kubernetes like k3s or microk8s for Raspberry Pi ARM architecture.
Install Kubernetes on the master Pi first, then join worker Pis with the correct token and IP.
Ensure all Pis are on the same network and required ports are open for communication.
Avoid heavy workloads due to Raspberry Pi's limited CPU and memory.
Check node and service status regularly to troubleshoot cluster issues.