Setting up a K3s cluster on Raspberry Pi is a popular home lab project, offering a lightweight Kubernetes distribution suitable for resource-constrained devices. Here's a general guide based on the search results, covering the essential steps:
1. Hardware and Software Prerequisites:
Raspberry Pi(s): You'll need at least one Raspberry Pi. A Raspberry Pi 4 or 5 with 4GB or 8GB of RAM is recommended, especially for larger workloads[1][2].
MicroSD Card or SSD: A high-quality microSD card (32GB or larger) or an SSD via USB for booting[1].
Power Supply and Network Connection: Stable power supply and a network connection for each Pi[1].
Computer with SSH Client: Access to a terminal or SSH client on your PC to connect to the Raspberry Pi(s)[1].
Raspberry Pi OS: Download the latest 64-bit version of Raspberry Pi OS[3][4].
Raspberry Pi Imager: Use the Raspberry Pi Imager (or similar tool like Etcher) to flash the OS image onto the SD card[3][4].
2. Prepare the Raspberry Pi(s):
Flash the OS: Use the Raspberry Pi Imager to write the Raspberry Pi OS image to your SD card. During this process, you can configure settings like hostname, enable SSH for headless setup, and set a password[3][4].
Boot and Connect: Insert the SD card into the Pi and connect it to power and your network. You should be able to connect via SSH[3][5].
Update System: Update the system packages on your Raspberry Pi(s) to ensure everything is current[1][6][7].
Enable Cgroup Support: K3s requires cgroup support. Edit the cmdline.txt file and add cgroup_memory=1 cgroup_enable=memory to the end of the line. Ensure all parameters remain on a single line[1][4].
bash
sudo nano /boot/cmdline.txt
Disable Swap: Disable swap, as it's required for Kubernetes.
Reboot: Reboot the Raspberry Pi for the changes to take effect[1].
bash
sudo reboot
Assign Static IP Addresses (Recommended): Configure static IP addresses for your Raspberry Pi(s) to ensure consistent network access to your cluster.
Set up Password-less SSH (Optional but Recommended): Generate an SSH key pair on your local machine and copy the public key to your Raspberry Pi(s) for easier access[3][2][8].
3. Install K3s:
Install K3s Server (Control Plane): On the Raspberry Pi designated as your control plane (master node), download and run the official K3s installation script. By default, this sets up a single-node cluster[1][9].
bash
curl -sfL https://get.k3s.io | sh -
Verify Installation: Check if the K3s service is active and running.
bash
sudo systemctl status k3s
4. Add Worker Nodes (Optional):
If you have additional Raspberry Pis, you can add them as worker nodes to expand your cluster.
Ensure the worker nodes are on the same network as the master node and have gone through the preparation steps (OS setup, updates, cgroup, swap disabled)[4].
On the master node, get the node token[9].
bash
sudo cat /var/lib/rancher/k3s/server/node-token
On each worker node, run the K3s installation script, providing the master node's IP address and the token.
bash
curl -sfL https://get.k3s.io | K3S_URL=https://<master_node_ip>:6443 K3S_TOKEN=<token> sh -
Verify the worker nodes have joined the cluster from the master node.
bash
kubectl get nodes
5. Configure Kubectl Access from Your Local Machine:
Copy the Kubeconfig file from the master node to your local machine. This file contains the credentials to connect to your cluster[3][2][8].
Set the KUBECONFIG environment variable on your local machine to include the copied config file.
You can now use kubectl commands from your local machine to interact with your K3s cluster[1][4][6].
6. Optional Advanced Configuration:
Persistent Storage: Configure persistent storage using an external SSD or network storage like NFS[1].
Ingress Controller: K3s defaults to Traefik, but you can install other ingress controllers like Nginx if you prefer[1][7].
Monitoring: Deploy monitoring tools like Prometheus and Grafana[1].
Kubernetes Dashboard: Install the Kubernetes dashboard to visualize your cluster[9][7].
MetalLB: Configure MetalLB for load balancing in your home lab[9][6].
This guide provides a comprehensive overview of installing K3s on a Raspberry Pi for a home lab. Remember to consult the linked sources for more detailed instructions and troubleshooting tips.