HPR3434: From 0 to K8s in 30 minutes




Hacker Public Radio show

Summary: Install CentOS or Debian on a Raspberry Pi. I'm using CentOS, but I'll admit that Debian is the easier option by far. Do this on 3 separate Pi units, each with the same specs. Set hostnames You must have unique hostnames for each Pi. Without unique hostnames, your cluster cannot function. There are several "kinds" of hostnames, so to avoid confusion I change all of them. I use a simple naming scheme: k for "kubernetes" + an integer, starting at 100 + c for "cluster": $ sudo hostname k100c $ sudo sysctl kernel.hostname=k100c $ sudo hostnamectl set-hostname k100c $ sudo reboot Do this for each Pi. At a minimum, you end up with Pi computers named k100c, k101c, and k102c. Set verbose prompts When working with many different hosts, it's helpful to have a very verbose prompt as a constant reminder of which host you're connected to. Add this to the ~/.bashrc of each Pi: export PS1='[\033[1;32m]! d t h:w n% [\033[00m]' Install a Pi finder script Install an LED blinker so you can find a specific Pi when you need one. This brilliant script is by Chris Collins for his article Use this script to find a Raspberry Pi on your network, which explains how to run it. #!/bin/bash set -o errexit set -o nounset trap quit INT TERM COUNT=0 LED="/sys/class/leds/led0" if ! [ $(id -u) = 0 ]; then echo "Must be run as root." exit 1 fi if [[ ! -d $LED ]] then echo "Could not find an LED at ${LED}" echo "Perhaps try '/sys/class/leds/ACT'?" exit 1 fi function quit() { echo mmc0 >"${LED}/trigger" } echo -n "Blinking Raspberry Pi's LED - press CTRL-C to quit" echo none >"${LED}/trigger" while true do let "COUNT=COUNT+1" if [[ $COUNT -lt 30 ]] then echo 1 >"${LED}/brightness" sleep 1 echo 0 >"${LED}/brightness" sleep 1 else quit break fi done Install K3s on your control plane K3s is Kubernetes for IoT and Edge computing. It's the easiest, cleanest, and most serious method of getting Kubernetes on an ARM device. You can try other solutions (Microk8s, Minikube, OXD, and so on), but the best support comes from k3s. First, you must install k3s on one Pi. You can use any of your Pi units for this, but I use host k100c because it's the first in the sequence, so it feels logical. [k100c]$ curl -sfL https://get.k3s.io -o install_k3s.sh [k100c]$ chmod 700 install_k3s.sh Read the script to ensure that it seems to do what you expect, and then: [k100c]$ ./install_k3s.sh After installation, you're prompted to add some arguments to your bootloader. Open /boot/cmdline.txt in a text editor and add cgroup_memory=1 cgroup_enable=memory to the end of it. console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p3 rootfstype=ext4 elevator=deadline rootwait cgroup_memory=1 cgroup_enable=memory Reboot: [k100c]$ sudo reboot Once the Pi is back up, verify that your node is ready: [k100c]$ k3s kubectl get node NAME STATUS ROLES AGE k100c Ready control-plane,master 42s This Pi is the "control plane", meaning it's the Pi