TET USER // 001ONLINE
user

DATALINKS

Location:

Europe or remote

City

Berlin

Age:

37 Years

Freelance:

Available

Language:

German, English

TECH // CORE

Agile Team Lead / Kanban / Scrum

90%

Java/Kotlin

90%

Spring Boot

90%

AWS

70%

Postgresql

70%

ElasticSearch

70%

Python

60%

ReactJs / NextJs

50%

EXTRA // TAGS

GoLang

Architecture

Microservices

Gradle

GIT Knowledge

Android

Download My CV

Kubernetes Cluster mit dem Raspberry Pi (2/3/4) mit K3s

Robin Henniges
#hashtag

This guide demonstrates how to set up a Raspberry Pi cluster using Kubernetes. My setup involves six Raspberry Pis:

  • 2x Raspberry Pi 2 ARMv7
  • 2x Raspberry Pi 3 ARMv8
  • 2x Raspberry Pi 4 ARMv8

Important Note: The Raspberry Pi 2 Model B V1.2 is compatible due to its 64-bit core. The Raspberry Pi 2 Model B V1 is not compatible as it has a 32-bit core. The BCM2837 chip, developed for the Raspberry Pi Foundation, offers better performance even in 32-bit mode compared to the BCM2836. Therefore, only the RPi 2 Model B V1.2 will work.

Step 1: Hardware Setup

Additional Hardware Required:

  • 1 GBit 8-port switch
  • Network cables in various colors
  • 6-port USB Anker charger with suitable USB cables
  • Acrylic Raspberry Pi stack
  • 64GB MicroSD cards

Step 2: Operating System Installation

  1. Download and install the Raspberry Pi Imager from the official website.
  2. For each Pi, select the appropriate model:
    • Choose Raspberry Pi OS Lite (64-Bit) as the image.
    • Select the SD card.
    • Click "Next" and then "Edit Settings" to assign a name (e.g., Pi2-purple, Pi2-blue, etc.), set a username, and password.
  3. Click "Yes" and wait for the SD card to be ready. Insert it into the Raspberry Pi and repeat for each device.

Step 3: Configuring Raspberry Pis

  1. Connect to each Pi via SSH (IP address can be found in your router settings).

  2. Edit the network configuration:

    sudo nano /etc/dhcpcd.conf
    

    Add:

    interface eth0
    static ip_address=192.168.178.200/24
    static routers=192.168.178.254
    

    Save and exit by pressing Control + X.

  3. Alternatively, assign a static IP via your router. The IP range for the cluster is 192.168.178.200-192.168.178.206.

  4. Disable swap:

    sudo swapoff -a
    

    To permanently disable swap:

    sudo nano /etc/dphys-swapfile
    CONF_SWAPSIZE=0
    

    Save and exit.

  5. Configure cgroups:

    sudo nano /boot/firmware/cmdline.txt
    

    Append to the first line:

    cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory
    

    Save and exit.

  6. Reboot the system:

    sudo reboot
    

Step 4: Installing Kubernetes with K3s

Installing the Kubernetes Master Node:

  1. Choose the most powerful Raspberry Pi as the master node. In this example, it's Raspberry Pi4-red with IP 192.168.178.200.

  2. Connect via SSH and run:

    curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server --disable=traefik --flannel-backend=host-gw --tls-san=192.168.178.200 --bind-address=192.168.178.200 --advertise-address=192.168.178.200 --node-ip=192.168.178.200 --cluster-init" sh -
    
  3. After installation, the master node starts automatically. The configuration file is located at /etc/rancher/k3s/k3s.yaml.

  4. Retrieve the node token needed to add worker nodes:

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

Installing Kubernetes Worker Nodes:

  1. Connect to the first Raspberry Pi designated as a worker node via SSH (e.g., 192.168.178.201).
  2. Execute the following command, replacing PUT-THE-TOKEN-HERE with the actual token:
    curl -sfL https://get.k3s.io | K3S_URL=https://192.168.178.200:6443 K3S_TOKEN="PUT-THE-TOKEN-HERE" sh -
    
  3. Repeat the process for all remaining Raspberry Pis.

Conclusion

Congratulations, your Raspberry Pi Kubernetes cluster is now set up! For further steps, consider configuring Lens for cluster management or enrolling in a beginner's course on Kubernetes.

Citations: [1] https://everythingdevops.dev/step-by-step-guide-creating-a-kubernetes-cluster-on-raspberry-pi-5-with-k3s/ [2] https://anthonynsimon.com/blog/kubernetes-cluster-raspberry-pi/ [3] https://blog.alexellis.io/self-hosting-kubernetes-on-your-raspberry-pi/ [4] https://rpi4cluster.com/k3s-design-goals/ [5] https://solved.scality.com/solved/how-i-made-a-kubernetes-cluster-with-five-raspberry-pis/ [6] https://blog.hypriot.com/post/setup-kubernetes-raspberry-pi-cluster/ [7] https://ubuntu.com/tutorials/how-to-kubernetes-cluster-on-raspberry-pi [8] https://ikarus.sg/kubernetes-with-k3s/

logo

Follow me on social media

CONTACT

E-Mail :

mail at robinhenniges.com

ADDRESS

Gotenstr. 11
10829 Berlin

© 2023. All Rights Reserved.