π§ Table of Contents
- π Why K3s?
- π οΈ Requirements
- π₯οΈ Preparing the Raspberry Pi Nodes
- ποΈ Step-by-Step Guide to Using Raspberry Pi Imager
- π Connecting to Raspberry Pi 5 Boards
- π³ Installing Kubernetes on Raspberry Pi 5
- π Conclusion
π§ Why K3s?
If youβre looking to dive into Kubernetes with minimal hassle, K3s is the way to go! π K3s is a lightweight Kubernetes distribution, perfect for environments with limited resources like Raspberry Pi. It’s designed for IoT and edge computing, making it an ideal fit for ARM-based devices like the Raspberry Pi. π₯³
Why K3s?
- π‘ Optimized for ARM: Perfect for Raspberry Pi.
- π οΈ Easy Installation: No need to wrestle with complex setups.
- π Lightweight: Uses fewer resources, leaving more room for your apps!
While K3s is fantastic, alternatives like Kubeadm are also available. However, they may not be as efficient on resource-constrained devices like the Raspberry Pi.
π§ Requirements
Hardware:
- π Two or more Raspberry Pi 5 boards (older versions work too!)
- π Stable power supply for each board
- πΎ High-quality microSD cards (16GB+ recommended)
- π Network to connect Raspberry Pi nodes
Software:
- π§ Raspberry Pi OS
- π» Raspberry Pi Imager (or Etcher, Rufus)
- π SSH client for remote access
π₯οΈ Preparing the Raspberry Pi Nodes
First things firstβprepare your Raspberry Pi nodes. To make your life easier, consider a headless setup. This means you donβt need to connect a monitor, keyboard, or mouse. Everything can be done remotely! π§
Pro Tip: Use the Raspberry Pi Imager to simplify the setup process by enabling SSH and connecting to Wi-Fi during installation. This will save you tons of time later! β±οΈ
ποΈ Step-by-Step Guide to Using Raspberry Pi Imager
Here’s how to quickly set up your Raspberry Pi OS using Raspberry Pi Imager:
- π Download the Raspberry Pi Imager from the official website.
- π οΈ Install the Imager on your computer.
- π Select your Raspberry Pi model in the Imager to ensure you download the correct OS.
- πΎ Insert your microSD card and choose it in the Imager.
- π₯οΈ Customize your OS settings, such as Hostname and SSH, for a headless setup.
- β³ Write the OS to the microSD card and safely eject it.
- π Power up your Raspberry Pi with the flashed microSD card.
π Important: Ensure all your Raspberry Pi boards are connected to the same network, either via Ethernet or Wi-Fi.
π Connecting to Raspberry Pi 5 Boards
Once your Raspberry Pi is up and running, it’s time to connect! π
- π Find the IP Address of your Raspberry Pi using a network scanner or your routerβs interface.
- π» SSH into your Raspberry Pi using its IP address:
sudo ssh pi@<your_raspberry_pi_ip>
- π Assign Static IPs to your Raspberry Pi boards to prevent IP changes. You can either set this up via your router or by editing the
interfaces
file directly on the Pi.
Example for Wi-Fi (wlan0
):auto wlan0 iface wlan0 inet static address 192.168.1.101 netmask 255.255.255.0 gateway 192.168.1.254
π³ Installing Kubernetes on Raspberry Pi 5
Now, letβs get Kubernetes up and running! πββοΈ
- Enable cgroups by adding this to
/boot/firmware/cmdline.txt
:cgroup_memory=1 cgroup_enable=memory
- Install K3s on the master node:
sudo curl -sfL https://get.k3s.io | sh -
- Check K3s Status:
sudo systemctl status k3s
- Access kubectl (the Kubernetes command-line tool):
sudo kubectl get nodes
π Adding Worker Nodes
Scale your cluster by adding worker nodes! π€
- Connect the worker node to the same network as the master node.
- Run the installation script on the worker node, specifying the master node’s IP and token:
sudo curl -sfL https://get.k3s.io | K3S_URL=https://<master_node_ip>:6443 K3S_TOKEN=<your_token> sh -
- Verify the worker node is added:
sudo kubectl get nodes
π Conclusion
Congratulations! π Youβve successfully set up a Kubernetes cluster on Raspberry Pi 5 using K3s. From prepping the hardware to configuring the cluster, you’ve done it all. This setup is perfect for deploying and managing containerized applications on a Raspberry Pi, giving you a compact yet powerful development environment.
π Want to learn more? Check out our resources on Kubernetes and Raspberry Pi for more advanced tips and tricks! π