feat(db): prod techgarden data plane — cnpg cluster, backups, snapshots (WS-02 H1/H2) - #279
Merged
Merged
Conversation
…ts (WS-02 H1/H2)
Stands up the shared prod PostgreSQL cluster that the techgarden monolith will
connect to at the flip. Nothing here is publicly reachable and nothing depends
on identity — the restore drill runs against this empty database before any
Keycloak work starts.
H1 — 1276-prod/databases/postgresql/
- cnpg Cluster `postgresql` in ns `databases`, instances: 2 (dev runs 1).
Name/namespace are load-bearing: they produce
postgresql-rw.databases.svc.cluster.local:5432, which the app repo hardcodes.
- bootstrap.initdb.database: techgarden, then a Database CR
(databaseReclaimPolicy: retain) reassigns the owner to techgarden_app.
- managed.roles techgarden_app — LOGIN NOSUPERUSER NOBYPASSRLS (RLS invariant).
Schema-per-module (ADR-0031): one database, one role, not per-service DBs.
- THREE ExternalSecrets: postgresql-superuser, postgresql-app-credentials, and
techgarden-db-app-credentials (basic-auth + username/password +
cnpg.io/reload — cnpg managed roles need all three or the password is never
applied).
- Dev's postInitApplicationSQLRefs/postInitSQLRefs and init-sql.yaml are
deliberately NOT carried over: legacy from the retired per-service-DB era.
H2 — backups from the start
- shared/kube-system/snapshot-controller: added the controller Deployment+RBAC.
Only the CRDs were installed, on ALL THREE clusters — so a VolumeSnapshot
would have been created and left unbound forever. The external-snapshotter
sidecar in the democratic-csi pods is not a substitute; it services
VolumeSnapshotContent, which nothing was creating. Inert on dev/core (zero
VolumeSnapshotClasses there).
- VolumeSnapshotClass freenas-iscsi-ssd-snapshot (prod had zero).
- cnpg backup.volumeSnapshot + a daily ScheduledBackup (6-field cron, UTC).
- pg_dump CronJob kept as a deliberately redundant LOGICAL export: a snapshot
inherits on-disk corruption, a dump fails loudly on it.
Snapshot-only, no barmanObjectStore — restore-to-snapshot, not PITR between
snapshots. WAL archiving would need S3 credentials outside this contract.
Dev-paired apps (1276-dev.databases.*) verified Synced+Healthy before commit, so
the prod safety gate passes on the merits; no PROMOTE_OVERRIDE required.
Claude-Session: https://claude.ai/code/session_015tcbrNifvkc8ryk4g2M7XK
This was referenced Aug 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WS-02 PR1 of 3 — data plane. Nothing here is publicly reachable and nothing depends on identity. The restore drill (H6) runs against this empty database before any Keycloak work, which is why this PR is first.
H1 — cnpg cluster + techgarden DB + techgarden_app role
New tree
kubernetes/clusters/1276-prod/databases/, modelled on1276-dev/databases/.postgresql/cluster.yamlClusterpostgresql in ns databases,instances: 2(dev runs 1)postgresql/databases.yamlDatabaseCR,databaseReclaimPolicy: retain, owner →techgarden_apppostgresql/externalsecret.yamlpostgresql-superuser+postgresql-app-credentialspostgresql/app-externalsecrets.yamltechgarden-db-app-credentials(managed-role password)_namespace/databasesnamespaceThe name/namespace pair is load-bearing:
postgresqlindatabasesis what producespostgresql-rw.databases.svc.cluster.local:5432, which the app repo hardcodes inprojects/api/deploy/base/api-deployment.yaml. Renaming either silently breaks the API at the flip.Three ExternalSecrets, not two. The managed-role one carries
type: kubernetes.io/basic-auth+username/passwordkeys + thecnpg.io/reloadlabel — cnpg managed roles require all three, and dropping any one creates the role with the password never applied.Schema-per-module (ADR-0031): one
techgardendatabase, onetechgarden_approle.LOGIN NOSUPERUSER NOBYPASSRLSis the RLS invariant. Flyway migrates as superuserpostgres(accepted blast-radius tradeoff).Deliberately not carried over from dev:
init-sql.yamland thepostInitApplicationSQLRefs/postInitSQLRefsthat reference it — legacy from the retired per-service-database era, unused by the monolith.H2 — backups from the start
shared/kube-system/snapshot-controller/shipped only the three CRDs — no controller Deployment — on all three clusters. Theexternal-snapshottersidecar present in every democratic-csi controller pod is not a substitute: it servicesVolumeSnapshotContent, and nothing was creating theVolumeSnapshotContentin the first place. AVolumeSnapshotwould have been accepted and then sat unbound forever, so aScheduledBackupwould hang rather than fail.freenas-iscsi-ssd-snapshot— prod had zero classes.backup.volumeSnapshot+ daily ScheduledBackup.Known ceilings (documented in-file, not fixed here)
barmanObjectStore→ restore-to-snapshot, not PITR between snapshots. WAL archiving needs S3 credentials outside this workstream's contract.retentionPolicyfor the volumeSnapshot method, so snapshots accumulate. ZFS snapshots are copy-on-write, so growth is delta-sized.Backup failure signalling
The existing cluster-wide
k8s-job-failedGrafana rule already covers the pg_dump CronJob, so no second alert is defined for it. The cnpg snapshot path is not covered (snapshots aren't Jobs) and gets acnpg-backup-stalerule — that one lives inkian.sh/ansible(lgtm_config), a different repo and deploy path, so it ships separately.Validation
kustomize build --enable-helmgreen on all four changed directories.ScheduledBackup.spec,Cluster.spec.backup.volumeSnapshot).72a9d5cf…with the expected keys.Prod safety gate
The
dev-health-checkPreToolUse hook did not fire — its regex requires the literalhomelab/kubernetes/clusters/…-prod/adjacency, and the mandated worktree path isworktrees/ws02-pr1/kubernetes/…. I ran the check manually instead:1276-dev.databases.postgresql,.db-backupsand.namespaceare all Synced + Healthy, so the gate passes on the merits. NoPROMOTE_OVERRIDEused or needed.🤖 Generated with Claude Code
https://claude.ai/code/session_015tcbrNifvkc8ryk4g2M7XK