diff --git a/AGENTS.md b/AGENTS.md index 20517f0..a26a27c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -42,6 +42,25 @@ every file is YAML/TXT applied with `kubectl apply -f`. - Node IPs have moved (`10.0.2.x` → `10.1.0.x`). Any manifest referencing the old registry `10.0.2.119:5000` is unreachable from current nodes; use the public image `pgvector/pgvector:pg18-trixie` instead (see PostgreSQL migration). +- Hetzner Cloud Firewalls (`allow-all-internal`, `allow-all-home`, `Home-ip`) + are applied to every node: inbound only from `10.0.0.0/8` and home + (`192.168.8.0/24`, `192.168.5.0/24`, `78.58.8.250/32`). There are no + outbound rules, so outbound is allow-all. **Adding one outbound rule flips + outbound to deny-all** — if you restrict egress, add the full allowlist in + one call. See `Cluster_admin/firewall.md`. +- IPv6 is egress-only (no inbound IPv6 rules). The `slow` SMB CSI Storage Box + mount uses IPv6 directly; keep it that way. +- Public IPs are kept on workers (Option A). Do not remove Primary IPs or + repoint worker default routes without reading `Cluster_admin/firewall.md` + and the "Firewall / egress" section in `Environment.md`. +- Cluster → home LAN goes through the master's WireGuard (`wg0`). Hetzner's + private network is routed (`/32` per node) and drops non-private sources, so + each worker gets a point-to-point GRE tunnel (`169.254.8.0/24`) to the master; + the master masquerades the traffic to `192.168.5.3` on `wg0`. + `HomeAccess/home_lan_router_daemonset.yaml` keeps the tunnels, routes and NAT + in place, and hardcodes the worker private IPs — update `WORKERS` when nodes + change. The master's `wg0` peer `AllowedIPs` must include `192.168.8.0/24` + (host config). See `HomeAccess/README.md`. ## Secrets are gitignored diff --git a/Cluster_admin/firewall.md b/Cluster_admin/firewall.md new file mode 100644 index 0000000..31f90da --- /dev/null +++ b/Cluster_admin/firewall.md @@ -0,0 +1,151 @@ +# Hetzner Cloud Firewall — inbound/outbound model + +Operational note for the cluster's public network posture ("Option A"): +**public IPs stay, inbound is locked down, outbound is open**. This is not a +manifest — it is managed in the Hetzner Cloud Console / API. + +Last verified: **2026-11-26**. + +## Servers + +| Server | Private IP | Public IPv4 | Public IPv6 | +|---|---|---|---| +| `master-4gb-hel1-2` | `10.1.0.3` | `46.62.205.103` | `2a01:4f9:c013:68e::/64` | +| `ubuntu-4gb-hel1-docker` (Worker-0) | `10.1.0.2` | `65.108.84.87` | `2a01:4f9:c010:e481::/64` | +| `woker-1-8gb-hel1-1` (Woker-1) | `10.1.0.4` | `95.216.198.61` | `2a01:4f9:c013:68ec::/64` | + +## Applied firewalls + +All three firewalls are applied to **all three** servers. + +| Firewall | ID | Inbound | Outbound | +|---|---|---|---| +| `allow-all-internal` | `10660297` | TCP/UDP/GRE/ICMP/ESP from `10.0.0.0/8` | none | +| `allow-all-home` | `10296229` | TCP/UDP/ICMP/GRE/ESP from `192.168.8.0/24`, `192.168.5.0/24` | none | +| `Home-ip` | `10714705` | TCP/UDP from `78.58.8.250/32` (home WAN) | none | + +All sources above are IPv4; there are **no IPv6 inbound rules**. + +## Effective posture + +Hetzner Cloud Firewalls are stateful: + +- Inbound `NEW` traffic: **dropped** unless a rule allows it. +- `ESTABLISHED` / `RELATED`: always allowed (responses to outbound connections + come back without an inbound rule). +- Outbound `NEW` traffic: **allowed** as long as there are no outbound rules. +- **Trap:** as soon as *one* outbound rule exists, outbound switches to + deny-by-default and only matching destinations pass. Do not add a single + outbound rule without the complete allowlist. + +Consequences: + +- The public IPs are **not reachable from the internet**. Verified on + 2026-11-25: from the master (a non-home source) ports 22/80/443/6443 on both + worker public IPs were blocked. +- Home LAN/WG (`192.168.8.0/24`, `192.168.5.0/24`, `78.58.8.250`) can reach the + nodes; the private network (`10.0.0.0/8`) can reach them. +- IPv6 is **egress-only**: no inbound IPv6 rules, so nodes can initiate + connections over IPv6 (used by the `slow` SMB Storage Box mount) but nothing + can initiate in. +- Nodes pull images and packages **directly over Hetzner** (Docker Hub, GHCR, + Quay, Ubuntu archive, `rg.mariushome.lt`). No home/VPN dependency. +- `rg.mariushome.lt` resolves to the home WAN (`78.58.8.250`) and is proxied by + the home edge into the cluster; pulls need the `registry-creds` image pull + secret (one per namespace). +- Mailu is **not deployed** (no pods in `mailu`). Its SMTP/IMAP ports are not + open to the internet under this posture. See `Email/README.md` step 3.4 if it + is ever deployed. + +## Operating the firewalls + +The Hetzner API token is stored in the cluster (CSI token). Do **not** commit +it or paste it into docs/logs: + +```bash +TOKEN=$(kubectl -n kube-system get secret hcloud -o jsonpath='{.data.token}' | base64 -d) +``` + +Inspect firewalls and the rules applied to each server: + +```bash +curl -s -H "Authorization: Bearer $TOKEN" \ + https://api.hetzner.cloud/v1/firewalls | jq . + +curl -s -H "Authorization: Bearer $TOKEN" \ + https://api.hetzner.cloud/v1/servers \ + | jq -r '.servers[] | "\(.name) firewalls=\([.public_net.firewalls[]?.id] | join(","))"' +``` + +Replace a firewall's rules (this **replaces all rules** on that firewall, so +include the full inbound + outbound set): + +```bash +curl -s -X POST -H "Authorization: Bearer $TOKEN" \ + -H 'Content-Type: application/json' \ + https://api.hetzner.cloud/v1/firewalls/10296229/actions/set_rules \ + -d @rules.json +``` + +The Console equivalent is **Firewalls → select firewall → Rules**. Changes are +applied within seconds. + +## If outbound must be restricted again + +Add the complete allowlist in one `set_rules` call. Starting point (merge these +outbound rules with the current inbound rules, or the inbound rules are lost): + +```json +{ + "rules": [ + { "direction": "out", "protocol": "tcp", "port": "80", "destination_ips": ["0.0.0.0/0", "::/0"] }, + { "direction": "out", "protocol": "tcp", "port": "443", "destination_ips": ["0.0.0.0/0", "::/0"] }, + { "direction": "out", "protocol": "udp", "port": "53", "destination_ips": ["0.0.0.0/0", "::/0"] }, + { "direction": "out", "protocol": "tcp", "port": "53", "destination_ips": ["0.0.0.0/0", "::/0"] }, + { "direction": "out", "protocol": "udp", "port": "123", "destination_ips": ["0.0.0.0/0", "::/0"] }, + { "direction": "out", "protocol": "tcp", "port": "445", "destination_ips": ["91.98.250.141/32", "2a01:4f8:bacc:2:200::180d/128"] }, + { "direction": "out", "protocol": "udp", "port": "51820", "destination_ips": ["78.58.8.250/32"] }, + { "direction": "out", "protocol": "icmp", "destination_ips": ["0.0.0.0/0", "::/0"] } + ] +} +``` + +Notes: + +- `91.98.250.141` / `2a01:4f8:bacc:2:200::180d` are the Hetzner Storage Box + (`//u518679.your-storagebox.de`) used by the `slow` SMB StorageClass. +- `78.58.8.250` is the home WAN / WireGuard endpoint. +- Hetzner's own services (DNS `185.12.64.1/2`, `api.hetzner.cloud`, metadata) + are generally exempt from firewall filtering, but the 443/53 rules cover them. +- Test from a node immediately after: `curl` to a registry, `apt update`, and a + throwaway `crictl pull`. + +## Validation checklist + +From a node: + +```bash +curl -s -o /dev/null -w '%{http_code}\n' https://registry-1.docker.io/v2/ # 401 +curl -s -o /dev/null -w '%{http_code}\n' http://archive.ubuntu.com/ubuntu/ # 200 +``` + +From a non-home source (e.g. the master, **not** the home network) the worker +public IPs must refuse: + +```bash +nc -vz 95.216.198.61 22 # blocked from master +nc -vz 65.108.84.87 443 # blocked from master +``` + +Real pull test (per node): + +```bash +crictl pull docker.io/library/hello-world:latest +crictl rmi docker.io/library/hello-world:latest +``` + +## Related + +- `Environment.md` → "Firewall / egress" +- `AGENTS.md` → "Network / IP layout" +- `Email/README.md` → step 3.4 (Mailu public SMTP/IMAP caveat) diff --git a/Email/README.md b/Email/README.md index 208f53c..59da32c 100644 --- a/Email/README.md +++ b/Email/README.md @@ -97,10 +97,16 @@ If `pwgen` is not installed: `apt-get install -y pwgen` (or use IMAP / Submission / ManageSieve ports must **NOT** go through Cloudflare — they need a direct, DNS-only route (grey cloud) to the Hetzner-announced IP. Mail clients should be configured against `mail.mariushome.lt` directly. -4. **Hetzner Cloud firewall / security group**: ensure ports 25, 465, 587, - 143, 993, 4190 are open to the internet for the node(s) running the - `front` pod. Hetzner blocks outbound 25 by default for new accounts — - confirm it has been lifted (already done per planning). +4. **Hetzner Cloud firewall**: the current firewalls only allow inbound from + the private network and home (`allow-all-internal`, `allow-all-home`, + `Home-ip`). There are **no** public inbound rules for 25/465/587/143/993/ + 4190, so Mailu is not reachable directly from the internet as-is. To expose + it, add explicit inbound TCP rules for those ports (this reopens the public + IPs for those ports) while keeping the private/home rules. See + `Cluster_admin/firewall.md`. Mailu is not currently deployed (no pods in + `mailu`), so this is preparatory. Outbound is allow-all now, but Hetzner + may still block outbound 25 for new accounts — confirm before relying on + direct delivery. ## Install / upgrade diff --git a/Environment.md b/Environment.md index 7c578bc..efb5c8d 100644 --- a/Environment.md +++ b/Environment.md @@ -18,11 +18,12 @@ inspecting `kubectl get/describe/logs`. | Directory | Purpose | |-------------------|----------------------------------------------------------------------| | `Cilium/` | Cilium networking: `LoadBalancerIPPool`, `L2AnnouncementPolicy`, ingress example | -| `Cluster_admin/` | Operational notes (node reboot/update sequences, `kubectl cp` example) — not manifests applied to cluster | +| `Cluster_admin/` | Operational notes (node reboot/update sequences, firewall/egress, `kubectl cp` example) — not manifests applied to cluster | | `Docker/PostgreSQL/` | Custom PostgreSQL image build (Dockerfile + build script) | | `DockerRegistry/` | Private Docker registry Deployment + Service + PVC, and a registry UI subdirectory | | `Email/` | Mailu mail server (Helm) + namespace + Cilium LB pool manifests | | `Gitea/` | Gitea Deployment/Service/Ingress/Namespace/PVC/DB-secret | +| `HomeAccess/` | DaemonSet that routes `192.168.8.0/24` (home LAN) through the master's WireGuard + README | | `Immich/` | Immich server + machine-learning + redis Deployments/Services, config + secret | | `Monitoring/` | kube-prometheus-stack Helm values + hand-managed Grafana manifests | | `PostgreSQL/` | PostgreSQL manifests (only `hetzner/` subdir currently present) | @@ -57,6 +58,34 @@ inspecting `kubectl get/describe/logs`. the public image name `rg.mariushome.lt/custom-postgres` instead. - LB pool ranges are RFC1918 and announced via L2 on worker nodes. +### Firewall / egress + +Public IPs are kept on all nodes (Option A). Hetzner Cloud Firewalls are +applied to every node: + +- `allow-all-internal` — inbound from `10.0.0.0/8` +- `allow-all-home` — inbound from `192.168.8.0/24`, `192.168.5.0/24` +- `Home-ip` — inbound from `78.58.8.250/32` (home WAN) + +There are **no outbound rules**, so Hetzner allows all outbound. Inbound `NEW` +from the internet is dropped; IPv6 has no inbound rules and is egress-only. +Nodes pull images/packages directly over Hetzner, and the `slow` SMB Storage Box +stays on direct IPv6. + +**Gotcha:** adding a single outbound rule flips Hetzner outbound to +deny-by-default. Add the complete allowlist in one call, or leave outbound open. +See `Cluster_admin/firewall.md` for the rules, API commands and validation. + +The master's WireGuard (`wg0`, `192.168.5.0/24`) is the only path between the +cluster and the home LAN; it is **not** an internet path. It carries both +directions: home → cluster (kubectl, LB IPs) and cluster → home (`HomeAccess/`: +each worker gets a point-to-point GRE tunnel to the master because Hetzner's +private network is routed and drops non-private sources, and the master +masquerades the traffic to `192.168.5.3`). The private-only-worker design +remains deferred: the home router does not forward the WG subnet, so home +devices reach workers only through the master. Mailu is not deployed and its +SMTP/IMAP ports are not open to the internet. + ## Storage Three `StorageClass`es exist: diff --git a/HomeAccess/README.md b/HomeAccess/README.md new file mode 100644 index 0000000..3559ff7 --- /dev/null +++ b/HomeAccess/README.md @@ -0,0 +1,129 @@ +# Home access from the cluster + +Lets pods and nodes reach the home LAN at `192.168.8.0/24` (the `pop-os` +workstation lives there) through the master's existing WireGuard tunnel. + +``` +pod on worker --Cilium--> worker node + | SNAT to 169.254.8.X, GRE (outer 10.1.0.X -> 10.1.0.3) + v + master 10.1.0.3 + | forward + MASQUERADE out wg0 (src 192.168.5.3) + v + home router --> 192.168.8.28 +``` + +Two things make this less obvious than it looks: + +1. **Hetzner's private network is routed, not L2.** Each node has a `/32` + (`10.1.0.x/32`) with a gateway at `10.1.0.1`; you cannot ARP a peer and use + it as a next hop. +2. **It drops non-private sources.** A packet forwarded by the master with + `source 192.168.8.x` never reaches the worker's NIC, so the return path has + to be tunnelled as well. + +Hence the point-to-point GRE tunnels (`169.254.8.0/24`) between each worker and +the master. The inner packet keeps its real source end to end; only the outer +header uses the private node IPs. The master then masquerades `169.254.8.0/24` +to `192.168.5.3` on `wg0`, the address the PC already answers. + +| Worker private IP | Tunnel pair | +|---|---| +| `10.1.0.2` | `169.254.8.0/31` (worker `.0`, master `.1`) | +| `10.1.0.4` | `169.254.8.4/31` (worker `.4`, master `.5`) | + +The worker list is hardcoded in the DaemonSet (`WORKERS`). Update it when a node +is added, removed or renumbered. + +## Prerequisites (host-side, not managed here) + +1. On `master-4gb-hel1-2`, the `/etc/wireguard/wg0.conf` peer for the home + router must list the home LAN: + + ```ini + AllowedIPs = 192.168.5.0/24, 192.168.8.0/24 + ``` + + Reload with `wg syncconf wg0 <(wg-quick strip wg0)` **and** add the route if + `ip route get 192.168.8.28` does not say `dev wg0` (`wg syncconf` does not + install routes): + + ```bash + ip route replace 192.168.8.0/24 dev wg0 + ip route get 192.168.8.28 # expect: dev wg0 src 192.168.5.3 + ``` + +2. The home router routes `192.168.8.0/24` into the WireGuard tunnel and + allows WireGuard ↔ LAN forwarding. + +3. Hetzner Cloud Firewall `allow-all-home` includes `192.168.8.0/24`. + +## Deploy + +```bash +kubectl apply -f HomeAccess/home_lan_router_daemonset.yaml +kubectl -n kube-system rollout status ds/home-lan-router +``` + +The DaemonSet is privileged with `hostNetwork: true` because it programs the +node's interfaces, routes and iptables. A 60 s reconcile loop re-applies +everything, so reboots, drains, Cilium upgrades and iptables flushes heal +themselves. + +## Verify + +```bash +# master: tunnels, NAT +kubectl -n kube-system exec ds/home-lan-router -- ip -br addr show | grep home-gw +kubectl -n kube-system exec ds/home-lan-router -- iptables -t nat -S POSTROUTING | grep 192.168.8 + +# worker: tunnel + route +kubectl -n kube-system exec -- ip route show 192.168.8.0/24 + +# end-to-end (ICMP is the quickest; use any listening TCP port on the PC) +kubectl -n kube-system exec -- ping -c2 192.168.8.28 +kubectl -n kube-system exec -- nc -vz -w2 192.168.8.28 22 +kubectl -n gitea exec deploy/gitea -- curl -s -o /dev/null -w '%{http_code}\n' -m 5 http://192.168.8.28:/ +``` + +`` needs an HTTP listener; when nothing is running on `pop-os`, +the ICMP and `nc` checks are enough. + +## Notes + +- Only `192.168.8.0/24` becomes reachable from pods, not the rest of the home + network. +- `pop-os` gets its address over DHCP. The route is subnet-wide, so a lease + change does not break routing; add a DHCP reservation on the UniFi gateway if + anything references the address. +- The worker `rp_filter` must be permissive (`0`) on the GRE interfaces and the + master's `all.rp_filter` must be `0`; the DaemonSet sets both. This is what + lets the forwarded, un-NAT'd reply enter the stack. +- TCP MSS is clamped to `1356` (`1396` GRE inner MTU − 40) on the workers, so + payloads do not black-hole on PMTUD. +- The host and the containers both use the `nf_tables` iptables backend, so + rules are visible and editable from either side. + +## Rollback + +```bash +kubectl delete -f HomeAccess/home_lan_router_daemonset.yaml +``` + +Host state (interfaces, routes, iptables rules) survives pod deletion; remove it +manually or reboot the nodes: + +```bash +# workers +ip tunnel del home-gw +iptables -t nat -D CILIUM_POST_nat -d 192.168.8.0/24 -j RETURN +iptables -t nat -D POSTROUTING -s 10.0.0.0/8 -d 192.168.8.0/24 -j SNAT --to-source 169.254.8.X +iptables -D FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + +# master +ip tunnel del home-gw-0 home-gw-4 +iptables -t nat -D POSTROUTING -s 169.254.8.0/24 -d 192.168.8.0/24 -o wg0 -j MASQUERADE +iptables -t nat -D POSTROUTING -s 10.0.0.0/8 -d 192.168.8.0/24 -o wg0 -j MASQUERADE +iptables -D FORWARD -i 'home-gw+' -o wg0 -j ACCEPT +iptables -D FORWARD -i wg0 -o 'home-gw+' -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT +``` diff --git a/HomeAccess/home_lan_router_daemonset.yaml b/HomeAccess/home_lan_router_daemonset.yaml new file mode 100644 index 0000000..62c60a0 --- /dev/null +++ b/HomeAccess/home_lan_router_daemonset.yaml @@ -0,0 +1,149 @@ +# Gives the cluster a route to the home LAN (192.168.8.0/24) through the +# master's WireGuard tunnel (wg0) and SNATs it to the master's WG address, so +# replies come back over the path the home router already knows. +# +# Hetzner's private network is routed (/32 per node) and drops packets whose +# source is not a private address, so worker traffic cannot simply be routed +# "via 10.1.0.3". Instead each worker gets a point-to-point GRE tunnel to the +# master: the inner packet keeps its real source, the outer packet uses the +# private node IPs. +# +# Prerequisite (host-side, see README.md): the master's wg0 peer must list +# 192.168.8.0/24 in AllowedIPs. +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: home-lan-router + namespace: kube-system + labels: + app: home-lan-router +spec: + selector: + matchLabels: + app: home-lan-router + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 10% + template: + metadata: + labels: + app: home-lan-router + spec: + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + priorityClassName: system-node-critical + tolerations: + - operator: Exists + containers: + - name: router + image: nicolaka/netshoot:v0.13 + command: ["/bin/bash", "-c"] + args: + - | + set -u + + HOME_LAN="192.168.8.0/24" + MASTER_IP="10.1.0.3" + WG_IF="wg0" + TUN_NET="169.254.8.0/24" + TUN_MTU=1396 + MSS=1356 + # Worker private IPs. Update this list when a node is added, + # removed or renumbered. The master ignores its own address. + WORKERS="10.1.0.2 10.1.0.4" + + is_master() { + # The label is empty on workers; wg0 is a fallback in case the + # label lookup comes back empty on the master. + [ -n "${CONTROL_PLANE:-}" ] || ip link show "$WG_IF" >/dev/null 2>&1 + } + + # /31 pair for a worker, derived from the last octet of its IP: + # 10.1.0.2 -> 169.254.8.0/31, 10.1.0.4 -> 169.254.8.4/31. + tun_net() { echo $(( ($1 - 2) * 2 )); } + + master_loop() { + for w in $WORKERS; do + local last dev net + last="${w##*.}" + net="$(tun_net "$last")" + dev="home-gw-$net" + if ! ip link show "$dev" >/dev/null 2>&1; then + ip tunnel add "$dev" mode gre local "$MASTER_IP" remote "$w" ttl 255 + fi + ip link set "$dev" mtu "$TUN_MTU" up + ip addr replace "169.254.8.$((net + 1))/31" dev "$dev" + ip route replace "169.254.8.$net/31" dev "$dev" + sysctl -qw "net.ipv4.conf.$dev.rp_filter=0" || true + done + sysctl -qw net.ipv4.conf.all.rp_filter=0 || true + sysctl -qw net.ipv4.ip_forward=1 || true + + for src in "$TUN_NET" "10.0.0.0/8"; do + iptables -t nat -C POSTROUTING -s "$src" -d "$HOME_LAN" -o "$WG_IF" -j MASQUERADE 2>/dev/null \ + || iptables -t nat -A POSTROUTING -s "$src" -d "$HOME_LAN" -o "$WG_IF" -j MASQUERADE + done + iptables -C FORWARD -i 'home-gw+' -o "$WG_IF" -j ACCEPT 2>/dev/null \ + || iptables -I FORWARD 1 -i 'home-gw+' -o "$WG_IF" -j ACCEPT + iptables -C FORWARD -i "$WG_IF" -o 'home-gw+' -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 2>/dev/null \ + || iptables -I FORWARD 1 -i "$WG_IF" -o 'home-gw+' -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + } + + worker_loop() { + local local_ip last net dev + local_ip="$(ip route get "$MASTER_IP" | sed -n 's/.* src \([^ ]*\).*/\1/p')" + [ -n "$local_ip" ] || { echo "ERROR: cannot determine local IP"; return 1; } + last="${local_ip##*.}" + net="$(tun_net "$last")" + dev="home-gw" + + if ! ip link show "$dev" >/dev/null 2>&1; then + ip tunnel add "$dev" mode gre local "$local_ip" remote "$MASTER_IP" ttl 255 + fi + ip link set "$dev" mtu "$TUN_MTU" up + ip addr replace "169.254.8.$net/31" dev "$dev" + ip route replace "$HOME_LAN" via "169.254.8.$((net + 1))" dev "$dev" + sysctl -qw "net.ipv4.conf.$dev.rp_filter=0" || true + sysctl -qw net.ipv4.conf.all.rp_filter=0 || true + + # Let our SNAT rule own this destination, otherwise Cilium + # masquerades to a tunnel device that has no address. + iptables -t nat -C CILIUM_POST_nat -d "$HOME_LAN" -j RETURN 2>/dev/null \ + || iptables -t nat -I CILIUM_POST_nat 1 -d "$HOME_LAN" -j RETURN + iptables -t nat -C POSTROUTING -s "10.0.0.0/8" -d "$HOME_LAN" -j SNAT --to-source "169.254.8.$net" 2>/dev/null \ + || iptables -t nat -A POSTROUTING -s "10.0.0.0/8" -d "$HOME_LAN" -j SNAT --to-source "169.254.8.$net" + iptables -C FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 2>/dev/null \ + || iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT + iptables -t mangle -C FORWARD -o "$dev" -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss "$MSS" 2>/dev/null \ + || iptables -t mangle -A FORWARD -o "$dev" -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss "$MSS" + iptables -t mangle -C FORWARD -i "$dev" -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss "$MSS" 2>/dev/null \ + || iptables -t mangle -A FORWARD -i "$dev" -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss "$MSS" + } + + echo "home-lan-router: node=${NODE_NAME:-unknown} role=$(is_master && echo master || echo worker)" + while true; do + if is_master; then + master_loop + else + worker_loop + fi + sleep 60 + done + env: + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: CONTROL_PLANE + valueFrom: + fieldRef: + fieldPath: "metadata.labels['node-role.kubernetes.io/control-plane']" + securityContext: + privileged: true + resources: + requests: + cpu: 10m + memory: 32Mi + limits: + memory: 64Mi diff --git a/Monitoring/kube-prometheus-stack.values.yaml b/Monitoring/kube-prometheus-stack.values.yaml index ef4f538..77b49be 100644 --- a/Monitoring/kube-prometheus-stack.values.yaml +++ b/Monitoring/kube-prometheus-stack.values.yaml @@ -1,7 +1,7 @@ # kube-prometheus-stack Helm chart values # Installed via: # helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \ -# --namespace monitoring --version 87.3.0 -f Monitoring/kube-prometheus-stack.values.yaml +# --namespace monitoring --version 88.6.1 -f Monitoring/kube-prometheus-stack.values.yaml # # Notes: # - Bundled Grafana is disabled; the hand-managed Grafana in Monitoring/Grafana/ @@ -31,6 +31,9 @@ prometheus: prometheusSpec: # Match the previous manual deployment's retention. retention: 15d + # Hard size cap: keep total TSDB size at/below 8GiB (~80% of the 10Gi PVC). + # Prevents a metric-cardinality spike from filling the Hetzner volume. + retentionSize: "8GB" # Hetzner CSI volume, same class as the old prometheus-data PVC. storageSpec: diff --git a/Ollama/MIGRATION_PLAN.md b/Ollama/MIGRATION_PLAN.md index 085f220..6f6d5b0 100644 --- a/Ollama/MIGRATION_PLAN.md +++ b/Ollama/MIGRATION_PLAN.md @@ -42,6 +42,40 @@ All manifests are in `Ollama/`: | `openwebui_deployment.yaml` | Open WebUI Deployment (PostgreSQL + pgvector) | | `openwebui_service.yaml` | ClusterIP Service `open-webui:8080` | | `openwebui_ingress.yaml` | Cilium dedicated LB ingress `chat.mariushome.lt` | +| `openwebui_imagegen_config.yaml` | ConfigMap `openwebui-imagegen` — enables ComfyUI image generation (see below) | + +## Image generation (ComfyUI on pop-os) + +Image generation runs on the `pop-os` workstation (RTX 2070, 8 GB) where ComfyUI +listens on `http://192.168.8.28:8188`. The cluster reaches it over the home-gw / +WireGuard route: every node has a route for `192.168.8.0/24` (master via `wg0`, +workers via `home-gw` with SNAT `10.0.0.0/8 → 169.254.8.x`), so pods can connect +directly. No tunnel or master proxy is needed. + +- `openwebui_imagegen_config.yaml` (`openwebui-imagegen` ConfigMap) sets + `ENABLE_IMAGE_GENERATION=true`, `IMAGE_GENERATION_ENGINE=comfyui`, + `IMAGE_GENERATION_MODEL=qwen-image`, `IMAGE_SIZE`, `IMAGE_STEPS`, and the full + `COMFYUI_WORKFLOW` / `COMFYUI_WORKFLOW_NODES` (Qwen-Image 2512 + Lightning + 4-step txt2img). +- `openwebui_deployment.yaml` consumes it via `envFrom.configMapRef`. +- **PersistentConfig caveat:** Open WebUI stores `image_generation.*` in the + `config` table of the `openwebui` Postgres DB, and **DB values override env**. + Setting the ConfigMap alone is not enough on an existing install — the DB rows + must match too. Either use Admin → Settings → Images, or update the DB: + + ```bash + POD=$(kubectl -n database get pods -l app=postgres-hetzner -o jsonpath='{.items[0].metadata.name}') + kubectl -n database exec $POD -- sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -U "${POSTGRES_USER:-admin}" -d openwebui' <<'SQL' + UPDATE config SET value='true'::json WHERE key='image_generation.enable'; + UPDATE config SET value=to_json('comfyui'::text) WHERE key='image_generation.engine'; + UPDATE config SET value=to_json('qwen-image'::text) WHERE key='image_generation.model'; + UPDATE config SET value=to_json('http://192.168.8.28:8188'::text) WHERE key='image_generation.comfyui.base_url'; + SQL + ``` + +- Requirements on pop-os: ComfyUI bound to the LAN (`--listen ...,192.168.8.28`, + handled by `comfy-mode`), static IP `192.168.8.28`, and the machine powered on + (generation fails while it is offline/asleep). ## Storage diff --git a/Ollama/openwebui_deployment.yaml b/Ollama/openwebui_deployment.yaml index 2436408..76ec2f6 100644 --- a/Ollama/openwebui_deployment.yaml +++ b/Ollama/openwebui_deployment.yaml @@ -21,6 +21,10 @@ spec: - name: open-webui image: ghcr.io/open-webui/open-webui:main imagePullPolicy: Always + envFrom: + # Image generation (ComfyUI on pop-os). See openwebui_imagegen_config.yaml. + - configMapRef: + name: openwebui-imagegen env: - name: OLLAMA_BASE_URL value: "http://ollama.ollama.svc.cluster.local:11434" diff --git a/Ollama/openwebui_imagegen_config.yaml b/Ollama/openwebui_imagegen_config.yaml new file mode 100644 index 0000000..ccbe901 --- /dev/null +++ b/Ollama/openwebui_imagegen_config.yaml @@ -0,0 +1,22 @@ +# Image generation config for Open WebUI (Kubernetes). +# Points Open WebUI at ComfyUI running on pop-os (GPU), reachable from the +# cluster via the home-gw / WireGuard route to 192.168.8.0/24. +# The workflow below is the Qwen-Image 2512 + Lightning 4-step text-to-image +# graph (matches ~/comfy/workflows/openwebui_qwen_t2i.json on pop-os). +apiVersion: v1 +kind: ConfigMap +metadata: + name: openwebui-imagegen + namespace: ollama + labels: + app: open-webui +data: + ENABLE_IMAGE_GENERATION: "true" + IMAGE_GENERATION_ENGINE: "comfyui" + IMAGE_GENERATION_MODEL: "qwen-image" + IMAGE_SIZE: "1024x1024" + IMAGE_STEPS: "4" + COMFYUI_BASE_URL: "http://192.168.8.28:8188" + COMFYUI_API_KEY: "" + COMFYUI_WORKFLOW: '{"1":{"class_type":"UnetLoaderGGUF","inputs":{"unet_name":"qwen-image-Q4_K_M.gguf"}},"2":{"class_type":"CLIPLoader","inputs":{"clip_name":"qwen_2.5_vl_7b_fp8_scaled.safetensors","type":"qwen_image","device":"default"}},"3":{"class_type":"VAELoader","inputs":{"vae_name":"qwen_image_vae.safetensors"}},"4":{"class_type":"LoraLoaderModelOnly","inputs":{"model":["1",0],"lora_name":"Qwen-Image-2512-Lightning-4steps-V1.0-fp32.safetensors","strength_model":1.0}},"5":{"class_type":"ModelSamplingAuraFlow","inputs":{"model":["4",0],"shift":3.1}},"6":{"class_type":"CLIPTextEncode","inputs":{"clip":["2",0],"text":""}},"7":{"class_type":"CLIPTextEncode","inputs":{"clip":["2",0],"text":""}},"8":{"class_type":"EmptySD3LatentImage","inputs":{"width":1024,"height":1024,"batch_size":1}},"9":{"class_type":"KSampler","inputs":{"model":["5",0],"positive":["6",0],"negative":["7",0],"latent_image":["8",0],"seed":42,"steps":4,"cfg":1.0,"sampler_name":"euler","scheduler":"simple","denoise":1.0}},"10":{"class_type":"VAEDecode","inputs":{"samples":["9",0],"vae":["3",0]}},"11":{"class_type":"SaveImage","inputs":{"images":["10",0],"filename_prefix":"openwebui_qwen"}}}' + COMFYUI_WORKFLOW_NODES: '[{"type":"prompt","node_ids":["6"],"key":"text"},{"type":"negative_prompt","node_ids":["7"],"key":"text"},{"type":"width","node_ids":["8"],"key":"width"},{"type":"height","node_ids":["8"],"key":"height"},{"type":"n","node_ids":["8"],"key":"batch_size"},{"type":"steps","node_ids":["9"],"key":"steps"},{"type":"seed","node_ids":["9"],"key":"seed"}]' diff --git a/PostgreSQL/BACKUP_PLAN.md b/PostgreSQL/BACKUP_PLAN.md new file mode 100644 index 0000000..fde0a89 --- /dev/null +++ b/PostgreSQL/BACKUP_PLAN.md @@ -0,0 +1,64 @@ +# PostgreSQL Backup Plan — Hetzner Storage Box + +Goal: automated backups of the `postgres-hetzner` database (namespace `database`) +to an off-cluster Hetzner Storage Box, using the plain-manifest style of this repo. + +## Current state + +- Postgres: single-replica Deployment `postgres-hetzner`, ns `database`, + data on `hcloud-volumes` PVC (`postgres-hetzner-pvc`). +- Image: `rg.mariushome.lt/custom-postgres` (postgres 18.4 + pgvector, + **already contains rclone** — can talk SFTP directly, no new image build needed). +- Credentials live in existing `postgres-secret` (POSTGRES_USER / POSTGRES_PASSWORD). +- No backup automation exists today. + +## Proposed approach + +CronJob + `pg_dump` + `rclone` over SFTP (logical backups, no sidecar, +no new Docker image, no extra PVC — stream dump into `rclone rcat`). + +### 1. Storage Box (one-time, manual) +- Create sub-account/directory, e.g. `postgres-backups/`. +- SFTP endpoint: `uXXXXX@uXXXXX.your-storagebox.de:23`. + +### 2. Secrets (gitignored — never committed) +- New Secret `postgres-backup-secret` in `database` ns: + - `SFTP_HOST`, `SFTP_USER`, `SFTP_PASS` (or `SFTP_KEY`). +- DB credentials reused from existing `postgres-secret`. + +### 3. New manifests — `PostgreSQL/backup/` +- `postgres_backup_rclone_configmap.yaml` — rclone.conf with `storagebox:` SFTP remote. +- `postgres_backup_cronjob.yaml` — CronJob: + - schedule: (TBD, e.g. daily `0 3 * * *`) + - image `rg.mariushome.lt/custom-postgres` + - command: `pg_dumpall | rclone rcat storagebox:postgres-backups/dump-$(date).pgdump` + - retention: `rclone delete --min-age Nd` (TBD) before/after upload + - `concurrencyPolicy: Forbid`, history limits 1/1 + - `backoffLimit: 2` + +### 4. Verification +- Test run: `kubectl create job --from=cronjob/postgres-backup backup-test -n database` +- Check logs; verify file on Storage Box via `rclone lsd` from a debug pod. +- Document restore procedure (`pg_restore` / `psql`) in this file after first successful backup. + +### 5. Later (optional) +- PrometheusRule alert on failed/timed-out CronJob (kube-prometheus-stack already selects all). +- Restore drill runbook. + +## Open questions (fill in before implementation) + +1. **Backup scope**: `pg_dumpall` (all DBs + roles/globals) vs. per-database `pg_dump` loop? → +2. **Physical vs. logical**: logical `pg_dumpall` assumed OK (small homelab DB, simple restore). PITR/WAL archiving is out of scope — confirm? → +3. **Schedule**: e.g. daily at 03:00 UTC? → +4. **Retention**: keep N days? also keep weeklies/monthlies? → +5. **Storage Box auth**: SSH key or password? → +6. **Storage Box host/account**: hostname + username once the sub-account exists? → +7. **Backup filename scheme**: OK with `postgres-backup-YYYYMMDD-HHMM.pgdump`? → +8. **Alerting**: add PrometheusRule for failed CronJob now, or later? → + +## Notes / constraints + +- Dump size must fit in pod ephemeral storage if not streaming; streaming via + `rclone rcat` avoids any local disk requirement. +- Storage Box SFTP uses port 23 (Hetzner default). +- Downtime is NOT required — `pg_dumpall` is online and consistent per DB. diff --git a/PostgreSQL/hetzner/postgres_hetzner_pvc.yaml b/PostgreSQL/hetzner/postgres_hetzner_pvc.yaml index d250473..f01ac51 100644 --- a/PostgreSQL/hetzner/postgres_hetzner_pvc.yaml +++ b/PostgreSQL/hetzner/postgres_hetzner_pvc.yaml @@ -8,5 +8,5 @@ spec: - ReadWriteOnce resources: requests: - storage: 39Gi + storage: 50Gi storageClassName: hcloud-volumes \ No newline at end of file diff --git a/README.md b/README.md index bc2677e..ba54552 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ homelab cluster. | Directory | Description | |------------------|---------------------------------------------------------------| | `Cilium/` | Cilium networking: `LoadBalancerIPPool`, `L2AnnouncementPolicy`, Ingress examples | -| `Cluster_admin/` | Admin notes: node restart commands, data migration examples | +| `Cluster_admin/` | Admin notes: node restart commands, firewall/egress, data migration examples | | `DockerRegistry/`| Private Docker registry deployment, service, PVC and UI | | `Gitea/` | Gitea deployment, service, ingress, namespace, PVC, DB secret | | `Immich/` | Immich server, machine-learning, redis, config, secret |