diff --git a/01-proxmox-infra/CLAUDE.md b/01-proxmox-infra/CLAUDE.md index 6d10843..af5dac0 100644 --- a/01-proxmox-infra/CLAUDE.md +++ b/01-proxmox-infra/CLAUDE.md @@ -1,7 +1,5 @@ # proxmox-infra -This file provides guidance to Claude Code when working in `01-proxmox-infra`. See the [repo-root CLAUDE.md](../CLAUDE.md) for shared conventions, deployment order, and CI/CD. - ## Project Overview Pulumi TypeScript project provisioning VMs and LXC containers in Proxmox using the `@muhlba91/pulumi-proxmoxve` provider, plus pfSense DHCPv4 static mappings via a locally-bundled `@pulumi/pfsense` SDK. diff --git a/02-k8s-bootstrap/CLAUDE.md b/02-k8s-bootstrap/CLAUDE.md index 847b454..70efe34 100644 --- a/02-k8s-bootstrap/CLAUDE.md +++ b/02-k8s-bootstrap/CLAUDE.md @@ -1,20 +1,12 @@ # k8s-bootstrap -This file provides guidance to Claude Code when working in `02-k8s-bootstrap`. See the [repo-root CLAUDE.md](../CLAUDE.md) for shared conventions, deployment order, and CI/CD. +Bootstraps a k3s cluster on the Proxmox VMs created by `proxmox-infra`. Starts VMs via the Proxmox REST API, then provisions k3s over SSH using `@pulumi/command` `remote.Command`. Exports the secret stack output `kubeconfig`. -Bootstraps a k3s cluster on the Proxmox VMs created by `proxmox-infra`. Starts VMs via the Proxmox REST API, then provisions k3s over SSH using `@pulumi/command` `remote.Command`. +## Decisions the code doesn't explain -## How it works - -1. Starts all VMs via `POST /api2/json/nodes/{node}/qemu/{vmid}/status/start` -2. Waits for port 22 to open on each VM (bash `/dev/tcp`), installs k3s on `k3s-master-1` with `--cluster-init --tls-san --tls-san ` -3. Waits for `https://:6443/healthz` to respond before anyone else joins, since every subsequent join uses the VIP, not `master1Ip`. The VIP itself is a pfSense IP Alias Virtual IP with HAProxy TCP-load-balancing 6443 across all three masters — set up manually, not managed by any Pulumi stack (see "pfSense one-time setup" below). This is deliberately *not* a second kube-vip/ARP-based VIP: `03-k8s-infra`'s existing kube-vip DaemonSet already handles Service/LoadBalancer VIPs (e.g. Traefik) separately, entirely inside the cluster, and API access is too critical to depend on the same ARP-failover mechanism -4. Joins `k3s-master-2` and `k3s-master-3` as embedded etcd nodes via `--server https://:6443` -5. Joins `k3s-worker-1`, `k3s-worker-2`, and `k3s-worker-3` as agent nodes via `K3S_URL=https://:6443` -6. Formats the workers' dedicated `scsi1` disk (ext4, if not already formatted) and mounts it at `/mnt/longhorn-extra` (via `/etc/fstab`) — this is the disk `03-k8s-infra` later registers as an extra Longhorn disk, to keep Longhorn off the root filesystem and avoid `DiskPressure` -7. Reads `/etc/rancher/k3s/k3s.yaml` from master-1 via SSH, patches the server URL to `controlPlaneVipAddress`, and exports it as the secret stack output `kubeconfig` - -VM IDs and the CI runner SSH private key are read automatically from the `proxmox-infra` stack output via StackReference — no manual setup needed for those. +- **Everything goes through `controlPlaneVipAddress` except master-1's own install.** master-1 is installed with `--cluster-init` and a `--tls-san` for both `master1Ip` and the VIP. The stack then waits for `https://:6443/healthz` before anyone joins, because master-2, master-3 and the workers all join via the VIP, and the exported `kubeconfig` points at it. +- **The VIP is pfSense + HAProxy, set up by hand, not kube-vip.** `03-k8s-infra`'s kube-vip DaemonSet only handles Service/LoadBalancer VIPs. Don't propose kube-vip `cp_enable` for API access: it was considered and rejected, see [the decision record](../docs/decisions/0001-control-plane-vip-via-pfsense-haproxy.md). The manual pfSense steps are in [the runbook](../docs/runbooks/pfsense-control-plane-vip.md). +- **Workers get a dedicated Longhorn disk.** The `scsi1` disk is formatted ext4 (if not already) and mounted at `/mnt/longhorn-extra` via `/etc/fstab`. `03-k8s-infra` later registers it as an extra Longhorn disk, which keeps Longhorn off the root filesystem and avoids `DiskPressure`. ## Required Pulumi config @@ -31,28 +23,16 @@ pulumi config set worker2Ip "192.168.1.x" pulumi config set worker3Ip "192.168.1.x" # Control-plane VIP — floating IP for API server access, fronted by pfSense -# + HAProxy (see "pfSense one-time setup" below). Must be a free address -# outside the router's DHCP pool. +# + HAProxy. Must be a free address outside the router's DHCP pool. pulumi config set --secret controlPlaneVipAddress "192.168.1.147" ``` -Proxmox credentials (`pve1Endpoint`, `pve1ApiToken`, `pve2Endpoint`, `pve2ApiToken`, `pve3Endpoint`, `pve3ApiToken`) are read automatically from `proxmox-infra` via StackReference — do **not** set them here. +VM IDs, the CI runner SSH private key, and Proxmox credentials (`pve1Endpoint`, `pve1ApiToken`, `pve2Endpoint`, `pve2ApiToken`, `pve3Endpoint`, `pve3ApiToken`) are read automatically from `proxmox-infra` via StackReference — do **not** set them here. ## Prerequisites `proxmox-infra` must be deployed first. On its first `pulumi up` it generates an ed25519 SSH keypair via `@pulumi/tls`, writes the public key into every VM's cloud-init, and exports the private key as a secret stack output. VMs must be re-provisioned (or have the public key manually added to `~/.ssh/authorized_keys`) before this stack can SSH in. -## pfSense one-time setup (before deploying) - -The `@pulumi/pfsense` provider used by `01-proxmox-infra` doesn't expose Virtual IP or HAProxy resources (only DHCP static mappings, DNS overrides, and firewall aliases), so this is manual, not Pulumi-managed: - -1. Confirm `controlPlaneVipAddress` falls outside the DHCP pool (Services → DHCP Server → Range). -2. Firewall → Virtual IPs → Add: Type = `IP Alias`, Interface = `LAN`, Address = `/32`. -3. System → Package Manager → install `haproxy` if not already installed. -4. Services → HAProxy → Backend: add a pool (e.g. `k3s-apiservers`), mode `TCP`, health check `TCP check` (or `ssl-hello-chk`), servers = `:6443`, `:6443`, `:6443`. -5. Services → HAProxy → Frontend: add a frontend listening on `:6443`, type `TCP` (not HTTP — this must stay an opaque passthrough so clients validate k3s's own TLS cert, not one terminated at pfSense), default backend = the pool from step 4. -6. Services → HAProxy → Settings: enable HAProxy, apply. - ## CI/CD Workflow: `../.gitea/workflows/02-deploy-k8s-bootstrap.yaml`. Secret: `K8S_BOOTSTRAP_PULUMI_DEV_YAML`. Deploy is manual (`workflow_dispatch`) — re-running this stack restarts the bootstrap sequence against live VMs. diff --git a/03-k8s-infra/CLAUDE.md b/03-k8s-infra/CLAUDE.md index 0c0235d..4a437d6 100644 --- a/03-k8s-infra/CLAUDE.md +++ b/03-k8s-infra/CLAUDE.md @@ -1,7 +1,5 @@ # k8s-infra -This file provides guidance to Claude Code when working in `03-k8s-infra`. See the [repo-root CLAUDE.md](../CLAUDE.md) for shared conventions, deployment order, and CI/CD. - Cluster-level infrastructure for the k3s homelab cluster, deployed via Helm and `@pulumi/kubernetes`. Reads `kubeconfig` from `k8s-bootstrap` via StackReference. ## Common Commands @@ -41,14 +39,7 @@ pulumi config set kubeVipInterface `kubeconfig` is read automatically via StackReference — do not set it here. -## TrueNAS one-time setup (before deploying) - -1. Create dataset `pool/k8s` -2. Add an NFS share for that dataset: - - ACL type: POSIX/generic Unix permissions (not SMB/NFSv4 ACLs) on TrueNAS SCALE - - Maproot User / Group: `root` / `root` - - Allowed Hosts/Networks: restrict to the k3s node IPs/CIDR -3. In Network → Allowed Networks, permit your LAN subnet (e.g. `192.168.1.0/24`) +The TrueNAS dataset and NFS share must exist before deploying; they are created by hand, see [the runbook](../docs/runbooks/truenas-nfs.md). ## CI/CD diff --git a/04-k8s-apps/CLAUDE.md b/04-k8s-apps/CLAUDE.md index f61881a..115a435 100644 --- a/04-k8s-apps/CLAUDE.md +++ b/04-k8s-apps/CLAUDE.md @@ -1,7 +1,5 @@ # k8s-apps -This file provides guidance to Claude Code when working in `04-k8s-apps`. See the [repo-root CLAUDE.md](../CLAUDE.md) for shared conventions, deployment order, and CI/CD. - Application workloads for the k3s homelab cluster. Reads `kubeconfig` from `k8s-bootstrap` via StackReference. ## Common Commands diff --git a/05-monitoring/CLAUDE.md b/05-monitoring/CLAUDE.md index 5a12ed6..97371d8 100644 --- a/05-monitoring/CLAUDE.md +++ b/05-monitoring/CLAUDE.md @@ -1,7 +1,5 @@ # monitoring -This file provides guidance to Claude Code when working in `05-monitoring`. See the [repo-root CLAUDE.md](../CLAUDE.md) for shared conventions, deployment order, and CI/CD. - Monitoring stack (Prometheus + Grafana) via the `kube-prometheus-stack` Helm chart. Reads `kubeconfig` from `k8s-bootstrap` and `domain` from `k8s-apps`, both via StackReference. ## Common Commands diff --git a/docs/decisions/0001-control-plane-vip-via-pfsense-haproxy.md b/docs/decisions/0001-control-plane-vip-via-pfsense-haproxy.md new file mode 100644 index 0000000..12794b2 --- /dev/null +++ b/docs/decisions/0001-control-plane-vip-via-pfsense-haproxy.md @@ -0,0 +1,30 @@ +# 0001: Control-plane VIP via pfSense + HAProxy, not kube-vip + +Status: accepted (September 2026) + +## Context + +The kubeconfig exported by `02-k8s-bootstrap` pointed at `master1Ip` only, and the other nodes joined through it. Losing master-1 therefore broke API access even though the cluster runs three embedded-etcd masters. + +The fix needs one address that reaches any healthy API server. kube-vip documents a control-plane mode (`cp_enable`) for exactly this on k3s, and kube-vip already runs in this cluster as the DaemonSet that announces the Traefik LoadBalancer VIP. + +## Decision + +The control-plane VIP is a pfSense IP Alias Virtual IP with HAProxy load-balancing TCP 6443 across the three masters, as an opaque passthrough. It is not a second kube-vip instance. + +In `02-k8s-bootstrap`: + +- master-1 is installed with a `--tls-san` for both `master1Ip` and `controlPlaneVipAddress`. +- master-2, master-3 and all workers join through the VIP. +- The exported `kubeconfig` points at the VIP. + +## Why not kube-vip control-plane mode + +When this was decided, the existing kube-vip VIP for Traefik had an unresolved ARP-failover problem: a drained node kept announcing the VIP because drain does not evict DaemonSet pods. Putting API access behind a second ARP-announced VIP would have made the most critical endpoint depend on the same unproven failure mode. A VIP held by the router, outside the cluster, fails independently of it. + +## Consequences + +- The pfSense side is manual. The `marshallford/pfsense` provider has no Virtual IP or HAProxy resources. Steps: [runbook](../runbooks/pfsense-control-plane-vip.md). +- pfSense becomes a dependency for API access. +- Existing masters need the extra TLS SAN before the VIP works for them; a fresh bootstrap gets it from the code. +- If API-server HA comes up again, kube-vip `cp_enable` was considered and rejected for the reason above. Revisit only if the ARP-failover behaviour is understood and fixed. diff --git a/docs/runbooks/pfsense-control-plane-vip.md b/docs/runbooks/pfsense-control-plane-vip.md new file mode 100644 index 0000000..ad2f9d7 --- /dev/null +++ b/docs/runbooks/pfsense-control-plane-vip.md @@ -0,0 +1,12 @@ +# pfSense: control-plane VIP and HAProxy (one-time setup) + +Do this once, before deploying `02-k8s-bootstrap`. It creates the address that `controlPlaneVipAddress` points at. + +The `@pulumi/pfsense` provider used by `01-proxmox-infra` doesn't expose Virtual IP or HAProxy resources (only DHCP static mappings, DNS overrides, and firewall aliases), so this is manual, not Pulumi-managed. For why the VIP lives on pfSense at all, see [the decision record](../decisions/0001-control-plane-vip-via-pfsense-haproxy.md). + +1. Confirm `controlPlaneVipAddress` falls outside the DHCP pool (Services → DHCP Server → Range). +2. Firewall → Virtual IPs → Add: Type = `IP Alias`, Interface = `LAN`, Address = `/32`. +3. System → Package Manager → install `haproxy` if not already installed. +4. Services → HAProxy → Backend: add a pool (e.g. `k3s-apiservers`), mode `TCP`, health check `TCP check` (or `ssl-hello-chk`), servers = `:6443`, `:6443`, `:6443`. +5. Services → HAProxy → Frontend: add a frontend listening on `:6443`, type `TCP` (not HTTP — this must stay an opaque passthrough so clients validate k3s's own TLS cert, not one terminated at pfSense), default backend = the pool from step 4. +6. Services → HAProxy → Settings: enable HAProxy, apply. diff --git a/docs/runbooks/truenas-nfs.md b/docs/runbooks/truenas-nfs.md new file mode 100644 index 0000000..bc40d09 --- /dev/null +++ b/docs/runbooks/truenas-nfs.md @@ -0,0 +1,10 @@ +# TrueNAS: NFS share for the `truenas-nfs` StorageClass (one-time setup) + +Do this once, before deploying `03-k8s-infra`. The share is what `truenasHost` and `truenasNfsPath` point at. + +1. Create dataset `pool/k8s` +2. Add an NFS share for that dataset: + - ACL type: POSIX/generic Unix permissions (not SMB/NFSv4 ACLs) on TrueNAS SCALE + - Maproot User / Group: `root` / `root` + - Allowed Hosts/Networks: restrict to the k3s node IPs/CIDR +3. In Network → Allowed Networks, permit your LAN subnet (e.g. `192.168.1.0/24`)