Skip to content

Phase 4 — Deploying to Kubernetes on Raspberry Pi

Phase 3 left the application running in Docker Compose on a single machine. Phase 4 takes that same application and deploys it to a real Kubernetes cluster — two Raspberry Pi nodes, persistent storage backed by a Synology NAS, GitOps management through Flux CD, and a full observability stack running Prometheus and Grafana.

Everything runs on physical hardware in the home lab. No managed Kubernetes service, no cloud provider doing the heavy lifting.


The cluster runs on two Raspberry Pi boards connected via Ethernet on a dedicated VLAN, managed from an Arch Linux VM on Proxmox.

  • cp-01 — Raspberry Pi 5 (8GB RAM) — Control Plane
  • wrk-01 — Raspberry Pi 4 (4GB RAM) — Worker Node
  • sre-mgmnt-01 — Arch Linux VM — Management machine running kubectl, Helm, and the Flux CLI

The management machine is the only place cluster commands are run from. Neither Pi node is touched directly after initial setup.


Full Kubernetes requires approximately 1.5GB of RAM just for the control plane. On a 4GB Raspberry Pi that leaves almost nothing for application workloads.

K3s is a CNCF-certified Kubernetes distribution that reduces the control plane footprint to around 400MB. Every kubectl command, every YAML manifest, every concept transfers directly to full Kubernetes. The only difference is lighter internal tooling and a single binary install.

The same reasoning applied to the GitOps tool. ArgoCD requires approximately 500MB. Flux requires 160MB. On constrained hardware, those choices compound.


Kubernetes can provision storage locally on each node — data lives on the Pi’s SD card, tied to that specific node. That is fine until a pod needs to move. If the node goes down or Kubernetes reschedules the pod, the data stays behind.

The solution was the Synology CSI driver — a Kubernetes storage plugin that provisions iSCSI LUNs directly on the Synology NAS. When a pod moves from cp-01 to wrk-01, the CSI driver detaches the LUN from one node and reattaches it to the other. The pod starts with all its data intact, on a different physical machine, in seconds.

The NAS also provides RAID 1 mirroring and 4.5TB of capacity, compared to the ~50GB on the Pi SD cards. Storage now scales independently of the cluster hardware.


The development machine runs x86-64. The Raspberry Pi cluster runs ARM64. Docker images built on one architecture will not run on the other — they crash immediately with exec format error.

The fix is docker buildx with QEMU emulation. A single build command produces a multi-platform image published to Docker Hub as one manifest tag. Docker Hub automatically serves the correct architecture to whichever platform pulls it.

Terminal window
docker buildx build \
--platform linux/amd64,linux/arm64 \
--tag christie62/humor-memory-game-backend:latest \
--push \
-f backend/Dockerfile ./backend

This is the same pattern used in professional CI/CD pipelines for edge and IoT deployments. It is not a workaround — it is the standard approach for multi-architecture builds.


Docker Compose describes the entire application in one file. Kubernetes distributes that description across separate manifest files, each with a distinct concern.

The mapping is direct. A Docker Compose image: becomes a Deployment. A ports: mapping becomes a Service. A named volume: becomes a PersistentVolumeClaim. A .env file becomes a ConfigMap for non-sensitive values and Secrets for sensitive ones — with one critical difference: Secrets are never stored in Git.

Thirteen manifest files cover the full application stack — namespace, ConfigMap, PVCs, Deployments, Services, and an Ingress reference for a future phase. Each file is documented in two versions: an annotated version explaining every field, and a clean production copy.

The same principle that drove the two-repository pattern in Phase 3 applies here. Application source code lives in sjchristie/humor-memory-game. Kubernetes infrastructure lives in christie62/humor-memory-game-kubernetes. Two concerns, two repositories, two audiences.


Several issues surfaced during deployment. None were obvious without reading the relevant systems carefully.

The PostgreSQL pod would not start — stuck in ContainerCreating. The events log showed configmap "postgres-init-sql" not found. A volume mount in the manifest referenced a ConfigMap that did not exist. Removing the unnecessary volume reference resolved it immediately.

The iSCSI permission errors were consistent across both Prometheus and Grafana. iSCSI LUNs format as ext4 and mount as root-owned. Prometheus runs as UID 65534, Grafana as UID 472 — both non-root. Neither could write to the mount point. The fix was an initContainer in each deployment that runs as root, sets correct ownership, and exits before the main container starts. This pattern is now documented and reused across any non-root container that needs Synology iSCSI storage.

Prometheus returned HTTP 403 on every node metrics endpoint. K3s requires nonResourceURLs permissions — /metrics and /metrics/cadvisor — in the Prometheus ClusterRole. Without them, the RBAC policy silently blocks scraping. Adding those two lines to the ClusterRole fixed all targets immediately.

NetworkManager was assigning DHCP addresses alongside the static IPs configured via systemd-networkd. The Pi nodes ended up with two IP addresses on the same interface. Pod networking depends on stable, predictable node IPs — the ghost DHCP address was causing intermittent routing failures. Purging NetworkManager and leaving systemd-networkd as the sole network manager resolved it permanently.

Both backend pods entered a continuous restart cycle — fifteen restarts within 96 minutes. The liveness and readiness probes were both hitting /api/health at high frequency, each probe triggering a live database connection. Under that load the connection pool exhausted, the health check failed, Kubernetes terminated the pod, and the cycle started again. The fix was reducing probe frequency — liveness from every 10 seconds to every 30, readiness from every 5 seconds to every 15 — with longer initial delay buffers. The mechanism designed to detect failures was itself causing them.

The backend was returning relation "games" does not exist on every database query despite the tables being present. The gameuser role was looking in its own private schema rather than the public schema where the initialisation SQL had created the tables. In Docker Compose the permissive initialisation environment masked this — in Kubernetes’s stricter role isolation it became a hard failure. A single ALTER ROLE gameuser SET search_path TO public resolved it immediately. The permanent fix embeds this in the database initialisation SQL so it runs automatically on any clean redeploy.


Once the application was running, the manual kubectl apply workflow was replaced with GitOps. Flux watches the christie62/humor-memory-game-kubernetes repository and reconciles any drift between Git and the live cluster.

Two safety settings are used during Phase 4. suspend: true means Flux watches for changes but does not apply them automatically — reconciliation is triggered manually with flux reconcile. prune: false means Flux will not delete resources that disappear from Git. Both settings will be reversed in Phase 5 when the CI/CD pipeline is introduced.

Drift detection works immediately. Manually scaling a deployment down and running flux reconcile restores it to the count defined in Git within seconds. Rollback is git revert and a push — no kubectl rollout undo, no manual state management.


The monitoring stack runs in a dedicated namespace with its own iSCSI-backed storage. Deleting the monitoring namespace to free RAM does not lose metrics history or dashboard configuration — both survive on the NAS and reattach on redeploy.

Prometheus scrapes five jobs: itself, both cluster nodes via kubelet, container metrics via cAdvisor, Kubernetes object state via kube-state-metrics, and the backend application pod via annotation-based discovery. The backend pod opts in to scraping with three annotations in its Deployment manifest — no additional Prometheus configuration required.

Grafana provisions two dashboards automatically from ConfigMaps on startup. The Pi K3s Cluster Overview covers node CPU and memory, pod status across all namespaces, container resource usage, deployment replica counts, and PVC storage. The Humor Memory Game dashboard focuses on the application — pod health, CPU and memory per service, restart counts, and storage.

The dashboards are built manually in the Grafana UI first — panel by panel, query by query — then exported as JSON and embedded into version-controlled ConfigMaps. That sequence matters: building manually first means understanding what each PromQL query actually measures before committing it to infrastructure.


Ten documents cover the complete Phase 4 implementation, living in the docs/ folder of the Kubernetes repository:

Document Purpose
SRE_SETUP_GUIDE.md Management machine setup — kubectl, k9s, SSH keys
INTRODUCTION_TO_KUBERNETES.md Kubernetes concepts and Docker Compose to Kubernetes mapping
PREPARING_THE_RASPBERRY_PIS.md OS flashing, static IP, cgroups, containerd configuration
INSTALLING_K3S.md K3s installation, kubeconfig, Synology CSI driver, Helm
DEPLOYING_THE_APPLICATION.md All 13 manifests with annotated and production copy versions
MONITORING_PROMETHEUS.md Prometheus deployment, RBAC, scrape configuration, kube-state-metrics
MONITORING_GRAFANA.md Grafana deployment, manual dashboard build walkthrough, JSON export
GITOPS_WITH_FLUX.md Flux installation, Kustomize overlays, GitOps workflow
TROUBLESHOOTING_AND_OPERATIONS.md Diagnostic workflow, maintenance procedures, known issues
BUG_001_CATEGORIES_NULL_VALIDATION.md Frontend/backend contract mismatch — categories null vs empty array
BUG_002_BACKEND_PROBE_DEATH_SPIRAL.md Probe death spiral — aggressive health checks exhausting database connection pool
BUG_003_POSTGRES_SEARCH_PATH.md PostgreSQL search_path mismatch — gameuser role unable to find public schema tables

  • Self-hosted Kubernetes cluster built and managed on physical ARM64 hardware
  • Multi-platform Docker image builds for mixed-architecture environments
  • Persistent storage across node failures using iSCSI and the Synology CSI driver
  • GitOps workflow with drift detection and Git-based rollback
  • Prometheus and Grafana observability stack with RBAC-scoped metrics collection
  • Infrastructure as code — all cluster state defined declaratively in version-controlled manifests
  • Diagnosing and resolving infrastructure issues across networking, storage, RBAC, and container runtime layers

Phase 5 covers CI/CD — automating the build, test, and deploy pipeline so that a push to the application repository triggers a multi-platform image build, pushes to Docker Hub, updates the Kubernetes manifest, and deploys to the cluster through Flux with no manual steps.

← Phase 3 — Containerising the Application with Docker and Docker Compose


Repository: christie62/humor-memory-game-kubernetes
Documentation: docs/