From 897813a91605d197b4b8e4ed67294187d05c592d Mon Sep 17 00:00:00 2001 From: kasun Date: Fri, 20 Nov 2026 21:48:20 +0100 Subject: [PATCH] docs: trim CLAUDE.md files to what the code doesn't show Following the Claude Code memory docs: drop architecture lists, generic commands and CI details Claude can read from the code, keep the reasons behind decisions, and fix the outdated provider and pfSense SDK statements. --- 01-proxmox-infra/CLAUDE.md | 28 ++-------------- 02-k8s-bootstrap/CLAUDE.md | 31 ++---------------- 03-k8s-infra/CLAUDE.md | 48 +++------------------------ 04-k8s-apps/CLAUDE.md | 30 ++--------------- 05-monitoring/CLAUDE.md | 31 +----------------- CLAUDE.md | 66 ++++++++------------------------------ 6 files changed, 26 insertions(+), 208 deletions(-) diff --git a/01-proxmox-infra/CLAUDE.md b/01-proxmox-infra/CLAUDE.md index af5dac0..57c88ae 100644 --- a/01-proxmox-infra/CLAUDE.md +++ b/01-proxmox-infra/CLAUDE.md @@ -1,28 +1,4 @@ # proxmox-infra -## 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. - -## Common Commands - -```bash -# Install deps and compile the bundled pfSense SDK -npm install - -# Sync Pulumi state with actual Proxmox state — run before `up` if VMs were -# changed manually in the Proxmox GUI -pulumi refresh --yes - -pulumi refresh --yes && pulumi up --yes -``` - -## Architecture - -- **Entry point**: `index.ts` — all resources declared here. -- **Providers**: two `@muhlba91/pulumi-proxmoxve` providers — `pveProvider` (node `pve`) and `pveBckpProvider` (node `pve-bckp`). Always pass the correct provider when adding resources. -- pfSense SDK lives in `sdks/pfsense/` (gitignored, regenerated by `npm install` / CI via `pulumi package add terraform-provider marshallford/pfsense 0.22.0`). - -## CI/CD - -Workflow: `../.gitea/workflows/01-deploy-proxmox-infra.yaml`. Secret: `PROXMOX_INFRA_PULUMI_DEV_YAML`. In addition to the shared pattern, this workflow regenerates the pfSense SDK (`pulumi package add terraform-provider marshallford/pfsense 0.22.0`) before preview/deploy. +- The pfSense SDK in `sdks/pfsense/` is gitignored and generated by `pulumi package add terraform-provider marshallford/pfsense 0.22.0` (CI runs it; locally, run it before `npm install` if the folder is missing). Don't edit it by hand. +- VMs are sometimes changed by hand in the Proxmox GUI. Before planning an `up`, suggest `pulumi refresh` so state matches reality. diff --git a/02-k8s-bootstrap/CLAUDE.md b/02-k8s-bootstrap/CLAUDE.md index 70efe34..0e9bafc 100644 --- a/02-k8s-bootstrap/CLAUDE.md +++ b/02-k8s-bootstrap/CLAUDE.md @@ -1,38 +1,13 @@ # k8s-bootstrap -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`. - ## Decisions the code doesn't explain - **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 +## Running against live VMs -```bash -# Pre-shared k3s token — any strong random string -pulumi config set --secret k3sToken "$(openssl rand -hex 32)" +Re-running this stack restarts the bootstrap sequence against already-provisioned VMs. That's why it only deploys via manual dispatch. For changes to the running cluster, write the code for a fresh bootstrap and give separate manual steps. -# Node IPs — static DHCP leases from the router (not secrets) -pulumi config set master1Ip "192.168.1.x" -pulumi config set master2Ip "192.168.1.x" -pulumi config set master3Ip "192.168.1.x" -pulumi config set worker1Ip "192.168.1.x" -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. Must be a free address outside the router's DHCP pool. -pulumi config set --secret controlPlaneVipAddress "192.168.1.147" -``` - -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. - -## 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. +The SSH key comes from `proxmox-infra`'s first `pulumi up`. VMs created before that need the public key added to `~/.ssh/authorized_keys` by hand. diff --git a/03-k8s-infra/CLAUDE.md b/03-k8s-infra/CLAUDE.md index 4a437d6..ef433ae 100644 --- a/03-k8s-infra/CLAUDE.md +++ b/03-k8s-infra/CLAUDE.md @@ -1,46 +1,6 @@ # k8s-infra -Cluster-level infrastructure for the k3s homelab cluster, deployed via Helm and `@pulumi/kubernetes`. Reads `kubeconfig` from `k8s-bootstrap` via StackReference. - -## Common Commands - -```bash -npm install -pulumi refresh --yes && pulumi up --yes -``` - -CI installs the `helm` CLI (`azure/setup-helm`) before running Pulumi. - -## Architecture - -| Component | What it does | -| --- | --- | -| NFS CSI Driver | `csi-driver-nfs` Helm chart — enables NFS-backed PVCs | -| `truenas-nfs` StorageClass | Backed by an NFS share on TrueNAS (`Retain` reclaim policy) | -| cert-manager | Certificate lifecycle management | -| `letsencrypt-prod` ClusterIssuer | DNS-01 via Cloudflare, issues Let's Encrypt TLS certs | -| Longhorn | Default block storage (`longhorn` StorageClass, 2 replicas) — used by app/monitoring PVCs. Worker nodes get an extra `longhorn-extra` disk at `/mnt/longhorn-extra` (a dedicated mount set up by `k8s-bootstrap`, patched onto the Longhorn `Node` CR here) so Longhorn data stays off the root disk and doesn't cause `DiskPressure`. `nodeDownPodDeletionPolicy` deletes both the StatefulSet and Deployment pod on node-down so stateful workloads reschedule automatically | -| kube-vip | DaemonSet that ARP-announces a virtual IP for LoadBalancer Services | -| kube-vip-cloud-provider | Allocates LoadBalancer IPs from a single-address pool (`kubeVipAddress`) — k3s's built-in ServiceLB is not used | -| `traefik` ServicePatch | Pins Traefik's LoadBalancer IP to `kubeVipAddress` | - -**Export**: `nfsStorageClass = "truenas-nfs"`. - -## Required Pulumi config - -```bash -pulumi config set --secret truenasHost -pulumi config set --secret truenasNfsPath /mnt/pool/k8s -pulumi config set --secret cloudflareApiToken -pulumi config set --secret letsencryptEmail -pulumi config set --secret kubeVipAddress -pulumi config set kubeVipInterface -``` - -`kubeconfig` is read automatically via StackReference — do not set it here. - -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 - -Workflow: `../.gitea/workflows/03-deploy-k8s-infra.yaml`. Secret: `K8S_INFRA_PULUMI_DEV_YAML`. +- **k3s's built-in ServiceLB is not used.** kube-vip ARP-announces LoadBalancer VIPs, and kube-vip-cloud-provider allocates them from a single-address pool (`kubeVipAddress`). Traefik's LoadBalancer IP is pinned to that address. +- **Longhorn stays off the root disk.** Worker nodes get an extra `longhorn-extra` disk at `/mnt/longhorn-extra` (mounted by `k8s-bootstrap`, registered on the Longhorn `Node` CR here) to avoid `DiskPressure`. `nodeDownPodDeletionPolicy` deletes StatefulSet and Deployment pods on node-down so stateful workloads reschedule. +- The TrueNAS dataset and NFS share are created by hand before deploying, see [the runbook](../docs/runbooks/truenas-nfs.md). +- Needs the `helm` CLI; CI installs it with `azure/setup-helm`. diff --git a/04-k8s-apps/CLAUDE.md b/04-k8s-apps/CLAUDE.md index 115a435..1e3964b 100644 --- a/04-k8s-apps/CLAUDE.md +++ b/04-k8s-apps/CLAUDE.md @@ -1,30 +1,4 @@ # k8s-apps -Application workloads for the k3s homelab cluster. Reads `kubeconfig` from `k8s-bootstrap` via StackReference. - -## Common Commands - -```bash -npm install -pulumi up --yes -``` - -## Architecture - -- **heimdall** — application dashboard (`lscr.io/linuxserver/heimdall`), namespace `heimdall` - - PVC `heimdall-config` (50Mi, `longhorn` StorageClass) - - Deployment + ClusterIP Service - - Ingress (`traefik` class, `cert-manager.io/cluster-issuer: letsencrypt-prod`) at `heimdall.` - - deployed with one replica because heimdall is not able to work with multiple replicas. Works with node failure detection and automatic rescheduling. - -**Export**: `domain` (secret) — consumed by `monitoring` via StackReference for its own ingress hostnames. - -## Required Pulumi config - -```bash -pulumi config set --secret domain -``` - -## CI/CD - -Workflow: `../.gitea/workflows/04-deploy-k8s-apps.yaml`. Secret: `K8S_APPS_PULUMI_DEV_YAML`. +- heimdall runs with one replica on purpose: it can't run with more than one. Node-failure recovery relies on rescheduling, not replicas. +- The `domain` output is consumed by `monitoring` for its ingress hostnames. Renaming or removing it breaks that stack. diff --git a/05-monitoring/CLAUDE.md b/05-monitoring/CLAUDE.md index 97371d8..4b46e67 100644 --- a/05-monitoring/CLAUDE.md +++ b/05-monitoring/CLAUDE.md @@ -1,32 +1,3 @@ # monitoring -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 - -```bash -npm install -pulumi up --yes -``` - -## Architecture - -- Namespace `monitoring` -- `kube-prometheus-stack` Helm release (chart v86.2.0) - - Grafana: ingress at `grafana.` (`traefik`, `letsencrypt-prod`), `longhorn` PVC (2Gi) - - Prometheus: `longhorn` PVC (20Gi) via `volumeClaimTemplate` - - Alertmanager disabled - -## Key Notes - -- The `monitoring` namespace and the Helm release both use the Pulumi `import` resource option (`monitoring`, `monitoring/kube-prometheus-stack`) — they were adopted from pre-existing cluster resources rather than created fresh. Be careful with renames or changes that would force a replace. - -## Required Pulumi config - -```bash -pulumi config set --secret grafanaAdminPassword -``` - -## CI/CD - -Workflow: `../.gitea/workflows/05-deploy-monitoring.yaml`. Secret: `MONITORING_PULUMI_DEV_YAML`. +- The `monitoring` namespace and the `kube-prometheus-stack` Helm release were adopted from existing cluster resources via the Pulumi `import` option. Be careful with renames or changes that would force a replace. diff --git a/CLAUDE.md b/CLAUDE.md index ce61fb0..d0e5844 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,20 +1,12 @@ # CLAUDE.md -Repository-wide instructions. Each stack directory has its own `CLAUDE.md` with stack-specific commands and architecture. + -## Project overview - -Pulumi (TypeScript) IaC for a Proxmox-based k3s homelab. Independent Pulumi projects ("stacks"), each with its own `Pulumi.yaml`/`package.json`, deployed in order and linked via `pulumi.StackReference`: - -| # | Directory | Pulumi stack | Purpose | -| --- | --- | --- | --- | -| 1 | `01-proxmox-infra` | `proxmox-infra` | Provisions k3s VMs + DHCP on Proxmox/pfSense | -| 2 | `02-k8s-bootstrap` | `k8s-bootstrap` | Installs k3s on the VMs over SSH | -| 3 | `03-k8s-infra` | `k8s-infra` | Cluster infra: storage, cert-manager, kube-vip | -| 4 | `04-k8s-apps` | `k8s-apps` | Application workloads (e.g. heimdall) | -| 5 | `05-monitoring` | `monitoring` | kube-prometheus-stack (Prometheus + Grafana) | - -All stacks use the Pulumi stack name `dev`. +Pulumi (TypeScript) IaC for a Proxmox-based k3s homelab. Each `0N-*` directory is an independent Pulumi project ("stack"), all using the Pulumi stack name `dev`. ## Deployment order & StackReferences @@ -23,23 +15,22 @@ proxmox-infra → k8s-bootstrap → k8s-infra ↘ k8s-apps → monitoring ``` -- `k8s-bootstrap` reads VM IDs, Proxmox credentials, and the SSH private key from `proxmox-infra` via StackReference. -- `k8s-infra`, `k8s-apps`, and `monitoring` all read `kubeconfig` from `k8s-bootstrap` via StackReference (`requireOutput("kubeconfig")`) — never set `kubeconfig` as Pulumi config in these stacks. -- `monitoring` additionally reads `domain` from `k8s-apps` via StackReference. +- `k8s-bootstrap` reads VM IDs, node IPs, Proxmox credentials, and the SSH private key from `proxmox-infra`. +- `k8s-infra`, `k8s-apps`, and `monitoring` read `kubeconfig` from `k8s-bootstrap` (`requireOutput("kubeconfig")`). Never set `kubeconfig` as Pulumi config in these stacks. +- `monitoring` additionally reads `domain` from `k8s-apps`. - StackReference format: `${pulumi.getOrganization()}//dev`. - -A stack's outputs must exist (i.e. it must have been deployed) before any downstream stack referencing it will succeed. +- A stack's outputs must exist (it must have been deployed) before a downstream stack referencing it will succeed. ## Shared conventions -- **TypeScript**: `strict: true`, `target: es2024`, `module`/`moduleResolution: nodenext`, `noImplicitReturns`, `noFallthroughCasesInSwitch` — functions need explicit return types where TS can't infer them. - **Secrets**: read via `config.requireSecret()`, never via environment variables or hardcoded values. -- **`Pulumi.dev.yaml`**: gitignored (contains the encryption salt) — never delete it or secrets become unrecoverable. Encrypted with `PULUMI_CONFIG_PASSPHRASE`. -- **Backend**: self-hosted Postgres state backend, set via `PULUMI_BACKEND_URL`. +- **`Pulumi.dev.yaml`**: gitignored (contains the encryption salt). Never delete it or secrets become unrecoverable. CI restores it from a base64 Gitea secret `_PULUMI_DEV_YAML`; after changing local config, remind me to update that secret. +- **Environment**: `PULUMI_BACKEND_URL` (self-hosted Postgres backend) and `PULUMI_CONFIG_PASSPHRASE` must be set. +- **CI**: PRs run `pulumi preview`. `03`–`05` deploy on push to `main`; `01`/`02` deploy only via manual dispatch. ## Git conventions -Branch names, commit messages and PR titles follow @CONVENTIONS.md. Don't add a co-author when committing to git. +Branch names, commit messages and PR titles follow @CONVENTIONS.md. The commit-msg hook needs `git config core.hooksPath .githooks` once per clone. Only commit when I explicitly say "commit" for that change. A yes to a question that also mentioned committing is not enough; when unsure, ask. @@ -62,32 +53,3 @@ The remote is a self-hosted Gitea, so `gh` doesn't work. For PRs and their CI st After editing a stack, run `npm run typecheck` in that stack's directory, then `pulumi preview`, and show the output of both. A passing typecheck only proves the code compiles; the preview is what shows which resources would be created, updated or replaced. Don't silence a check to make it pass (`@ts-ignore`, `as any`, `git commit --no-verify`) without a stated reason and my OK. - -## Common commands (run from a stack directory) - -```bash -git config core.hooksPath .githooks # once per clone, from the repo root: enforces CONVENTIONS.md -npm install -npm run typecheck -pulumi preview -pulumi up --yes # run by the user or CI -pulumi destroy # run by the user -pulumi stack output -pulumi config -``` - -Requires `PULUMI_BACKEND_URL` and `PULUMI_CONFIG_PASSPHRASE` in the environment (or `pulumi login`). - -Start Claude Code sessions from the repository root: the permission rules and the live-infra hook in `.claude/settings.json` only load from there. - -## CI/CD (Gitea Actions) - -One workflow per stack: `.gitea/workflows/0N-deploy-.yaml`, scoped to changes under that stack's directory. - -- **Pull request → `main`**: `pulumi preview` only. -- `01`/`02` (VM provisioning / cluster bootstrap — riskier to automate): deploy only via manual `workflow_dispatch`. -- `03`–`05`: deploy on push to `main` *or* `workflow_dispatch` — `pulumi refresh` then `pulumi up`. -- Each workflow restores `Pulumi.dev.yaml` from a base64-encoded Gitea secret (`_PULUMI_DEV_YAML`). After changing local config, re-encode and update the secret: - ```bash - base64 -w 0 0N-/Pulumi.dev.yaml - ```