Kubernetes on Raspberry Pi 4

Setting up the Raspberry Pi 4

Download the Raspberry Pi Imager to flash the microSD card or USB disk with the Raspberry Pi OS.

  • Change the advanced settings, specifically don’t forget to change the following:
    • Wifi
    • Username and password

Install Kubernetes (K3s)

Step 1 (cgroup)

Standard Raspbian Buster installations do not start with cgroups enabled. K3S needs cgroups to start the systemd service. cgroups can be enabled by appending cgroup_memory=1 cgroup_enable=memory to /boot/cmdline.txt

Step 2 (k3s master)

curl -sfL https://get.k3s.io | sh -

Step 3 (k3s node)

Source: https://sahansera.dev/building-your-own-private-kubernetes-cluster-on-a-raspberry-pi-4-with-k3s/

On the master to get security token:

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

On the agent:

curl -sfL https://get.k3s.io | K3S_NODE_NAME="node01" K3S_URL="" K3S_TOKEN="token from above step" sh -

On the master to verify:

kubectl get nodes

Kubernetes Remote Console (kubectl)

On the master node:

sudo cat /etc/rancher/k3s/k3s.yaml

On the PC edit .kube/config

kubectl config use-context pi

Kubernetes Monitoring (Prometheus)

Install Lens

Right click on cluster > Settings > Lens Monitoring

Check prometheus Check kube-state-metrics Check node-exporter

Kubernetes Storage (Longhorn)

Source: https://docs.k3s.io/storage

kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml

Dashboard: port-forward

Automatic System Updates

Source: https://haydenjames.io/how-to-enable-unattended-upgrades-on-ubuntu-debian/


sudo apt update && sudo apt upgrade
sudo apt install unattended-upgrades
sudo apt install apt-listchanges

Change settings at:

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

Automatic Kubernetes Updates


Dynamic DNS

Script: https://github.com/K0p1-Git/cloudflare-ddns-updater

crontab -e
*/5 * * * * /bin/bash /home/pi/cloudflare-ddns-updater/cloudflare.sh

Router Port Forwarding

GitHub Actions Automated Deployment

Source: https://nicwortel.nl/blog/2022/05/27/continuous-deployment-to-kubernetes-with-github-actions

Configure Private Docker Registry

JetBrains Containers:

kubectl create secret docker-registry regcred --docker-server=<SPACE>.registry.jetbrains.space/p/<PROJECT>/containers --docker-username=<USERNAME> --docker-password=<PASSWORD> --docker-email=<EMAIL> --namespace <NAMESPACE>

Github Container Registry:

kubectl create secret docker-registry regcred --docker-server=ghcr.io --docker-username=<USERNAME> --docker-password=<PASSWORD> --docker-email=<EMAIL> --namespace <NAMESPACE>