homek8s/README.md

133 lines
7.9 KiB
Markdown
Raw Normal View History

# HomeK8s
Kubeadm cluster ("Sirius DevOps" homelab), delivered by Flux CD from this repo.
All manifests, components and pod placements below were read from the live cluster
on 2026-10-28 (`kubectl` and `curl`, not from memory).
Deeper write-up: [`docs/cluster-overview.md`](docs/cluster-overview.md) (current-state
snapshot — when it disagrees with `kubectl`, `kubectl` wins).
## Cluster
| Node | WireGuard IP | Arch | Roles | Notes |
|------|--------------|------|-------|-------|
| `siriussec` | `10.10.0.2` | amd64 | control-plane, gateway, worker | API server (`https://10.10.0.2:6443`). No taints — default scheduling. Labelled `node-role.kubernetes.io/gateway=true`. Every public workload and every `local-path` PVC lives here. |
| `rpi` | `10.10.0.1` | arm64 | traffic, worker | WG hub + cloudflared + dnsmasq. Labelled `dedicated=network`, taint `dedicated=network:PreferNoSchedule`. arm64: amd64 images cannot run here. |
| `linode` | `10.10.0.5` | amd64 | none | Linode VPS, remote WG hub (`10.20.0.1`) reached through the Pi. Same `dedicated=network` label/taint as `rpi`. **Volatile** — retired once, rejoined 2026-10-26; confirm with `kubectl get nodes` before relying on it. |
Kubernetes `v1.36.4`, containerd. `siriussec` boots `linux-lts` (the Cilium BPF probe
fails on the rolling 7.x kernel).
## Networking
- **CNI: Cilium**, native routing over WireGuard — `routing-mode=native`,
`ipv4-native-routing-cidr=10.244.0.0/16`, `auto-direct-node-routes=true`, no VXLAN,
kube-proxy replaced (`kube-proxy-replacement=true`). Pod traffic between nodes is
routed by WireGuard `AllowedIPs`, so a pod CIDR must be in some peer's AllowedIPs.
- **Public ingress** (only path):
`Internet -> CF TLS -> cloudflared on rpi -> http://10.10.0.2:8080 -> Gateway gateway-system/public -> HTTPRoute -> Service`.
The origin is **`http://10.10.0.2:8080`** and nothing else. `127.0.0.1:8080` on the Pi
has no listener; the Pi's own Envoy answers 503 after 5 s. Envoy is a hostNetwork
DaemonSet selecting `node-role.kubernetes.io/gateway=true`, and **`siriussec` is the
only node allowed to carry that label** (two labelled nodes = random 5 s 503s). The
Gateway listener must sit on the node running the backend pods, which is why all
public workloads are pinned to `siriussec`.
- **Internal (WireGuard-only) services**: `Gateway internal/internal` on port 8081
(Grafana) and `Gateway internal/hubble-ui` on 8084 (Hubble UI). Reached on the bare
IP, no `Host` header, no hosts file: `http://10.10.0.2:8081/` and
`http://10.10.0.2:8084/`. Each bare-IP service needs its own Gateway object
(Cilium merges hostname-less routes per Gateway). Host firewall (`nftables` on
siriussec) is the real boundary, not the Gateway.
- **Internal DNS**: dnsmasq on `rpi`, `10.10.0.1:53` — authoritative for
`lab.internal`; `grafana.lab.internal` and `hubble.lab.internal` both resolve to
`10.10.0.2`.
- **Storage**: `local-path` (default, siriussec `/opt/local-path-provisioner`) plus
`local-static` for hostPath PVs pinned to the Pi (the arm64 runner dind volumes).
## Services running
| What | Namespace | Reachable at | Node |
|------|-----------|--------------|------|
| Forgejo (git + registry UI) | `forgejo` | `https://forgejo.siriusdevops.com` | siriussec |
| Forgejo Postgres (CNPG `pg`) | `forgejo` | in-cluster `pg-rw:5432` | siriussec |
| Runner `forgejo-runner-amd64` (dind) | `forgejo` | labels `docker-amd64`, `amd64` | siriussec |
| Runner `forgejo-runner-arm64` (dind) | `forgejo` | labels `docker-arm64`, `arm64`, `docker` | rpi |
| Runner `forgejo-runner-deploy-arm64` (dind) | `forgejo` | label `deploy-arm64` | rpi |
| CronJob `forgejo-runner-prune` | `forgejo` | `17 4 * * *`, prunes every dind | rpi |
| Site + contact API `siriusdevops-*` | `siriusdevops` | `https://siriusdevops.com`, `www.` | siriussec |
| Site + contact API `piedmont-*` | `piedmont` | `https://piedmonthomesvc.com`, `www.` | siriussec |
| Site + contact API + portal `sirius-growth-*` | `sirius-growth` | `https://siriusgrowthsolutions.com`, `www.` (`/api/portal` to the portal) | siriussec |
| Portal Postgres (CNPG `portal`) | `sirius-growth` | in-cluster `portal-rw:5432` | siriussec |
| Prometheus | `monitoring` | in-cluster `kube-prometheus-stack-prometheus:9090` | siriussec |
| Grafana | `monitoring` | WG-only `http://10.10.0.2:8081/` (`grafana.lab.internal`) | siriussec |
| kube-state-metrics, blackbox-exporter, node-exporter (3 nodes) | `monitoring` | in-cluster / scrape targets | mixed |
| Cilium agent + `cilium-envoy` + operator, CoreDNS, Hubble relay/UI | `kube-system` | Hubble UI WG-only `http://10.10.0.2:8084/` | siriussec (+ agents on all) |
| CNPG operator | `cnpg-system` | cluster-internal | siriussec |
| Flux controllers + `etcd-io-guard` (I/O guard DaemonSet) | `flux-system`, `node-io` | cluster-internal | siriussec |
| local-path provisioner | `local-path-storage` | cluster-internal | siriussec |
Also in the tunnel ingress but **not** backed by a route: `paaas.siriusdevops.com`
returns 404 (a hostname in the tunnel with no HTTPRoute is 404, not a broken tunnel).
**On the Pi as Docker containers, not in the cluster** (`docker ps` on rpi):
| Container | Port |
|-----------|------|
| `registry` (`registry:2`) | `10.10.0.1:5000` + `127.0.0.1:5000` — CI image pushes |
| `garage` (`dxflrs/garage`) | S3 API `10.10.0.1:3900` (unsigned GET = 403, i.e. alive) |
wgportal is installed on the Pi but **not running**; WG peers are edited in
`/etc/wireguard/*.conf` and `wg set` when it is down.
## Workload placement rules
- amd64 images and **every public workload** -> `siriussec`
(`nodeSelector: {kubernetes.io/hostname: siriussec}`). On `rpi` they die with
`exec format error`.
- Traffic / light pods -> `nodeSelector: {dedicated: network}` (rpi or linode,
`PreferNoSchedule` so it is a preference, not a pin).
- Storage: `local-path` only provisions on **siriussec**. A PVC consumed by a pod on
another node must use a static `local-static` PV (see
`apps/base/forgejo/runner-dind-storage.yaml`).
- Cluster DBs: CloudNativePG, 1 instance, `local-path`, `siriussec`.
## Adding an app
1. `apps/base/<app>/`: namespace, workload, Service, HTTPRoute.
2. HTTPRoute `parentRefs` -> `gateway-system/public`; add a `ReferenceGrant` if the
route lives in another namespace. Add the Deployment/Service in the **same commit**
as the route (a route with no backend returns 503).
3. One line in `apps/home/kustomization.yaml`.
4. Commit, push to `master`, then force Flux to fetch before assuming it applied:
```bash
kubectl -n flux-system annotate gitrepository flux-system reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite
kubectl -n flux-system annotate kustomization apps reconcile.fluxcd.io/requestedAt="$(date +%s)" --overwrite
```
A new public hostname also needs one entry in the existing Cloudflare tunnel
(`sirius home`) — do not create a second tunnel.
## Flux layout
Flux watches `master` every 1m and runs six Kustomizations, all `Ready=True`:
`flux-system` (`./clusters/homek8s`), `infrastructure` (`./infrastructure/home`),
`apps` (`./apps/home`), `databases` (`./infrastructure/databases/base`),
`monitoring` (`./monitoring/controllers/home`), `gateway-api-crds`
(`./infrastructure/networking/gateway-api`).
```
apps/{base,home}/ # workloads + the list of apps this cluster runs
clusters/homek8s/ # THE live Flux tree (kustomizations + gotk-sync)
clusters/home/ # DEAD CODE: not bootstrapped, nothing applies it
infrastructure/{home,networking,storage,controllers,databases,node-io}/
monitoring/controllers/home/
```
**`clusters/home/` is dead code.** The bootstrapped path is `./clusters/homek8s`
(`clusters/homek8s/flux-system/gotk-sync.yaml`), and `clusters/home` has no
`kustomization.yaml`. A Kustomization declared there never reaches the cluster — put
new Flux Kustomizations under `clusters/homek8s/`.
Do not `kubectl apply` these paths by hand: Flux owns them. Cilium and
kube-prometheus-stack are HelmReleases, so a manual `helm`/`kubectl apply` is reverted.