docs(pitr): the plugin path is real — transcript, layout, metrics, 1.31 gate closed

Documents what the live migration actually produced (kanban t_5df331de):

- §8.3: restore manifest is externalClusters[].plugin + barmanObjectName/
  serverName, with the 2026-11-19 rehearsal transcript (marker 23:04:53.07,
  target 23:05:00Z, poison 23:05:15.80 -> marker present, poison gone).
- §8.4 (new): how the plugin is wired — vendored manifest, Service-annotation
  registration, cert-manager dependency, ObjectStore/ScheduledBackup shape,
  the injected init-sidecar, and the metrics family change.
- §8.1/§5.1: producer is the plugin; retention moved to the ObjectStore;
  the "1.31 is a hard gate" caveat is replaced by "gate closed".
- §9/§10 + namespace table: cert-manager and barman-cloud are live state now,
  with the verification log rows.
- pitr-restore.md rewritten for the plugin (manifest, sidecar log evidence,
  the two-servers-name trap, retention location).
- CNPG dashboard: the `or` now prefers the plugin's metric — the legacy
  cnpg_collector series still holds the PRE-migration timestamp.
This commit is contained in:
devops 2026-11-19 18:09:23 -05:00
commit 4c90eba08b
5 changed files with 224 additions and 105 deletions

View file

@ -333,6 +333,12 @@ second S3 service: a WAL archive on the Pi would sit in the same building, power
domain and uplink as the CNPG primary on siriussec. Off-site or it is not a
backup.
Producer: the **CNPG-I Barman Cloud plugin** (`cnpg-system/barman-cloud`,
`ObjectStore sirius-growth/portal-wal`) — not the operator's deprecated in-tree
`barmanObjectStore`. The bucket, key and layout are unchanged (`portal/base/…`,
`portal/wals/…`), because the plugin appends the same barman server name
(`portal`) to the same `s3://pg-wal-archive` root. See §8.4.
---
## 6. Workloads
@ -388,9 +394,10 @@ Nothing runs on `linode` except its Cilium agent. `rpi` runs only the two runner
| `kube-system` | 45 d | control plane, Cilium, Envoy, CoreDNS, hubble-relay + hubble-ui |
| `kube-public`, `kube-node-lease`, `default` | 45 d | kubeadm defaults |
| `forgejo` | 45 d | Forgejo, its CNPG cluster, 3 runners, prune CronJob |
| `cnpg-system` | 45 d | CloudNativePG operator |
| `cnpg-system` | 45 d | CloudNativePG operator **+ the CNPG-I Barman Cloud plugin** (`barman-cloud`, §8.4) |
| `cert-manager` | 1 m | cert-manager v1.21.3 (controller + webhook + cainjector) — installed for the Barman Cloud plugin's mTLS pair, §8.4 |
| `monitoring` | 1 d | kube-prometheus-stack: Prometheus (7d/8GB), Grafana, kube-state-metrics, node-exporter |
| `flux-system` | 41 d | 4 Flux controllers, GitRepository, 4 Kustomizations |
| `flux-system` | 41 d | 4 Flux controllers, GitRepository, 7 Kustomizations (`flux-system`, `gateway-api-crds`, `cert-manager`, `databases`, `infrastructure`, `monitoring`, `apps`) |
| `gateway-system` | 45 d | Gateway `public` |
| `internal` | 41 d | Gateways `internal` (8081) and `hubble-ui` (8084) |
| `local-path-storage` | 45 d | provisioner |
@ -538,14 +545,18 @@ Five independent scheduled paths, all **off** the T480 and **off** the Pi:
`garage-meta-backup.timer` (hourly) + `garage-data-backup.timer` (nightly) →
`[email protected]:/root/garage-backup`.
4. **Point-in-time recovery for `sirius-growth/portal`**, continuous WAL archiving
+ a daily base backup straight from the CNPG operator into a **second Garage
node running on the Linode** (`infrastructure/garage-linode/`, bucket
`pg-wal-archive`, bucket-private, `10.10.0.5:3900` WireGuard-only). This is the
only path with a **sub-24 h RPO**: recovery to any second inside the last 14
days, not just "the state at 02:37". Config:
`apps/base/sirius-growth/cluster.yaml` `spec.backup.barmanObjectStore` +
`apps/base/sirius-growth/scheduled-backup.yaml` (`ScheduledBackup portal-daily`,
`20 3 * * *` UTC in **six**-field cron, seconds first).
+ a daily base backup straight from the **CNPG-I Barman Cloud plugin** into a
**second Garage node running on the Linode** (`infrastructure/garage-linode/`,
bucket `pg-wal-archive`, bucket-private, `10.10.0.5:3900` WireGuard-only). This
is the only path with a **sub-24 h RPO**: recovery to any second inside the last
14 days, not just "the state at 02:37". Config:
`apps/base/sirius-growth/objectstore-portal-wal.yaml` (`ObjectStore portal-wal`,
store + `retentionPolicy: 14d`), the Cluster's `spec.plugins`
(`barman-cloud.cloudnative-pg.io`, `isWALArchiver: true`, `serverName: portal`)
and `apps/base/sirius-growth/scheduled-backup.yaml` (`ScheduledBackup
portal-daily`, `20 3 * * *` UTC in **six**-field cron, seconds first,
`method: plugin`). The plugin Deployment itself is vendored in
`infrastructure/databases/base/` (§8.4).
A fifth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
`wireguard-backup.timer` (nightly 04:13) → `[email protected]:/root/pihost-backup`.
@ -554,7 +565,7 @@ A fifth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
|---|---|---|---|
| `forgejo-data` PVC (`/data`) | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `forgejo-data/<stamp>/` + `latest` symlink | 7 snapshots (hardlinked: 1 full copy + nightly deltas) |
| `forgejo/pg` | `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket — no DB password exists in git or in the Job | `db/forgejo-pg-<stamp>.dump` | 14 |
| `sirius-growth/portal` | two independent copies, on purpose. **(a)** `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket, through exec RBAC in `sirius-growth` — logical, human-readable with any `pg_restore`. **(b)** barman-cloud **continuous WAL archive + daily base backup** (path 4) | (a) `db/sirius-growth-portal-<stamp>.dump`; (b) `pg-wal-archive` bucket on the Linode: `portal/base/<stamp>/` + `portal/wals/…` | (a) 14 dumps; (b) 14 days of WAL (`retentionPolicy: 14d`) |
| `sirius-growth/portal` | two independent copies, on purpose. **(a)** `pg_dump -Fc -Z6` **inside the CNPG primary** over the local socket, through exec RBAC in `sirius-growth` — logical, human-readable with any `pg_restore`. **(b)** barman-cloud **continuous WAL archive + daily base backup** through the CNPG-I plugin (path 4) | (a) `db/sirius-growth-portal-<stamp>.dump`; (b) `pg-wal-archive` bucket on the Linode: `portal/base/<stamp>/` + `portal/wals/…` | (a) 14 dumps; (b) 14 days of WAL (`ObjectStore.spec.retentionPolicy: 14d`) |
| `osint/osint-db` (plain Postgres Deployment, has TimescaleDB + PostGIS) | `pg_dump -Fc -Z6` **inside the pod** over the local socket, using its own `POSTGRES_USER`/`POSTGRES_DB` via exec RBAC in `osint` | `db/osint-osint-db-<stamp>.dump` | 14 |
| `grafana.db` (sqlite) | **sqlite backup API** in a `python:3.12-alpine` pod that mounts the PVC — a `cp` of a live db can capture a torn page; the image is `-distroless`, so there is no shell to exec into | `grafana/grafana-<stamp>.db` | 14 |
| `sgs-leadgen-data` PVC | `rsync -a --delete --link-dest` snapshot mirror, PVC mounted read-only | `leadgen-data/<stamp>/` + `latest` | 7 |
@ -598,22 +609,29 @@ A fifth path covers the Pi's own hub state: `infrastructure/wireguard/backup/`
window**. Worst case on a busy database (every segment full at a typical 3–5×
gzip ratio) is ~1.5 GB/day → 21 GB for 14 days, i.e. it would hit the 20 GB
cap. The cap is deliberate: Garage answers `507 InsufficientStorage` and
`barman-cloud-backup` fails loudly (red `Backup`/`ScheduledBackup`) rather
barman-cloud fails loudly (a red `Backup`/`ScheduledBackup`) rather
than filling the Linode disk. If that ever fires, the lever is
`spec.backup.retentionPolicy` (7d) — not deleting WALs by hand.
`ObjectStore portal-wal` → `spec.retentionPolicy` (7d) — not deleting WALs by
hand.
- **The barman credentials are a namespaced Secret, not git**:
`sirius-growth/portal-wal-s3` (`ACCESS_KEY_ID` / `ACCESS_SECRET_KEY` /
`REGION`), created out of band from Garage key `cnpg-portal-wal`
(`GK7f2b4bb1fc9abaec50fde37b`, scope **read+write on `pg-wal-archive` only**,
no bucket-create). Recording key IDs is fine; the values are not in git, in the
docs, or in any comment.
- **CNPG 1.30 still ships the in-tree barman-cloud integration, and it warns that
1.31 removes it** (`Warning: Native support for Barman Cloud backups and
recovery is deprecated ... Please migrate existing clusters to the new Barman
Cloud Plugin`). That is why this is on 1.30 only: the plugin (an extra
Deployment + CNPG-I registration + TLS) is the migration path, and it must land
before the operator goes to 1.31. Nothing else here changes when it does — the
bucket layout stays `portal/base` + `portal/wals`.
- **The 1.31 gate is closed — WAL archiving runs on the CNPG-I plugin, not the
in-tree path.** CNPG 1.30 deprecated `spec.backup.barmanObjectStore` and warns
on every apply that 1.31 removes it. `sirius-growth/portal` was migrated on
**2026-11-19** (kanban `t_5df331de`) to the Barman Cloud plugin
(`infrastructure/databases/base/upstream/plugin-barman-cloud-0.16.0.yaml`,
Deployment `cnpg-system/barman-cloud`, `ObjectStore sirius-growth/portal-wal`,
`Cluster.spec.plugins`, `ScheduledBackup.method: plugin`), so bumping the
operator pin from 1.30.0 to 1.31 no longer breaks archiving or PITR. The bucket
layout did not move: `portal/base` + `portal/wals` are the same objects the
in-tree archiver wrote, and the restore rehearsal in §8.3 ran against that
mixed archive. The plugin needs cert-manager (its mTLS pair is an
`Issuer` + two `Certificate`s), installed as `cert-manager` HelmRelease v1.21.3
— see §8.4.
**Accepted gaps (with the reason, not just a TODO):**
@ -640,11 +658,15 @@ plain Deployment and cannot use CNPG backup at all.
A new CloudNativePG cluster is **not** picked up automatically by either
mechanism. For dumps: add `<ns>/<cluster>` to `CNPG_TARGETS` in the CronJob env
*and* an equivalent exec-only Role/RoleBinding for the `forgejo/cluster-backup`
ServiceAccount in that namespace. For barman: add `spec.backup.barmanObjectStore`
with a `destinationPath` of `s3://pg-wal-archive` (the bucket root — the server
name, defaulting to the cluster name, becomes the prefix, so clusters share one
bucket without colliding), the same `sirius-growth/portal-wal-s3`-shaped Secret
in that namespace, and a `ScheduledBackup`.
ServiceAccount in that namespace. For WAL archiving: create an `ObjectStore` in
that namespace whose `spec.configuration.destinationPath` is
`s3://pg-wal-archive` (the bucket root — the plugin appends the barman server
name, which defaults to the cluster name, so clusters share one bucket without
colliding), point its `s3Credentials` at a `sirius-growth/portal-wal-s3`-shaped
Secret in that namespace, give it its own `retentionPolicy`, add
`spec.plugins: [{name: barman-cloud.cloudnative-pg.io, isWALArchiver: true,
parameters: {barmanObjectName: <store>}}]` to the Cluster and a
`ScheduledBackup` with `method: plugin`.
### 8.2 Restoring
@ -713,10 +735,11 @@ sudo systemctl start wg-quick@wg0 && sudo wg show
### 8.3 Point-in-time recovery (`sirius-growth/portal`)
Rehearsed end to end on **2026-11-19** (task `t_ce7d6772`) against the live
archive: a marker row was written, 10 s later a second, unwanted row was written,
and a throwaway cluster was restored with `targetTime` between the two. The
marker came back, the later row did not.
Rehearsed end to end twice: **2026-11-19** with the in-tree barman-cloud archiver
(task `t_ce7d6772`) and again the same day **on the CNPG-I Barman Cloud plugin**
(task `t_5df331de`, §8.4) — marker row → forced WAL switch → unwanted row →
forced WAL switch → throwaway cluster restored with `targetTime` between the
two. Both times the marker came back and the later row did not.
**Step 1 — establish the target time.** Take it from the data, never from
memory:
@ -729,6 +752,8 @@ date -u +%FT%TZ
**Step 2 — restore into a throwaway cluster.** Never into `portal` itself while
it is serving: CNPG recovery bootstraps a *new* data dir from the archive.
`externalClusters[].plugin` replaces `barmanObjectStore`; `serverName` is the
barman prefix and must stay the **source** cluster name.
```yaml
apiVersion: postgresql.cnpg.io/v1
@ -745,17 +770,14 @@ spec:
recovery:
source: portal-wal
recoveryTarget:
targetTime: "2026-11-19T22:35:15Z" # UTC, RFC3339
targetTime: "2026-11-19T23:05:00Z" # UTC, RFC3339
externalClusters:
- name: portal-wal
barmanObjectStore:
destinationPath: s3://pg-wal-archive
endpointURL: http://10.10.0.5:3900
serverName: portal # MUST be the *source* cluster name
s3Credentials:
accessKeyId: {name: portal-wal-s3, key: ACCESS_KEY_ID}
secretAccessKey: {name: portal-wal-s3, key: ACCESS_SECRET_KEY}
region: {name: portal-wal-s3, key: REGION}
plugin:
name: barman-cloud.cloudnative-pg.io
parameters:
barmanObjectName: portal-wal # the ObjectStore in this namespace
serverName: portal # MUST be the *source* cluster name
```
```bash
@ -773,6 +795,25 @@ kubectl -n sirius-growth exec portal-pitr-test-1 -c postgres -- \
psql -U postgres -tAc "select pg_is_in_recovery(), pg_last_xact_replay_timestamp()"
```
Rehearsal transcript on the plugin path (2026-11-19 23:04–23:06 UTC), target
`2026-11-19T23:05:00Z`, marker written 23:04:53.07, unwanted row 23:05:15.80:
```
# live primary, the mistake
1 | MARKER-plugin-before-target | 2026-11-19 23:04:53.072104+00
2 | POISON-plugin-after-target | 2026-11-19 23:05:15.798408+00
# pg_stat_archiver after forcing both segments out: ...062 (23:04:54), ...063 (23:05:16), failed_count 6 (historical, static)
# restored cluster portal-pitr-test (targetTime 23:05:00Z)
id | note | at
----+-----------------------------+-------------------------------
1 | MARKER-plugin-before-target | 2026-11-19 23:04:53.072104+00
(1 row)
select count(*) from pitr_probe where note like 'POISON%' -> 0
select pg_is_in_recovery(), pg_last_xact_replay_timestamp() -> f|
clients=4 calendar_tokens=3 applications=1 # identical to the primary
```
`pg_is_in_recovery() = f` on a single-instance recovery cluster means replay
finished and it has already been promoted. **A recovery cluster is writable the
moment it is Ready** — do not leave `portal-pitr-test` running, and do not point
@ -797,6 +838,36 @@ timestamp near the present.
(§8.2 step 2) — 24 h RPO, logical, and readable without barman. That is exactly
why `sirius-growth/portal` stayed in `CNPG_TARGETS`.
### 8.4 The CNPG-I Barman Cloud plugin (how it is wired)
Active since **2026-11-19**. Three moving parts, all in git:
| Piece | Where | Notes |
|---|---|---|
| Plugin Deployment | `infrastructure/databases/base/upstream/plugin-barman-cloud-0.16.0.yaml` (vendored verbatim, sha256 `aee61468…7155`), patched only for `--log-level=info` + resources | `cnpg-system/barman-cloud`, port 9090, `replicas: 1`; **registered through Service annotations** `cnpg.io/pluginName: barman-cloud.cloudnative-pg.io` + `cnpg.io/pluginPort`/`pluginClientSecret`/`pluginServerSecret` — there is no `Plugin` CR in CNPG 1.30; delete the Service and the operator deregisters it |
| mTLS | `infrastructure/controllers/cert-manager/` (HelmRelease `cert-manager` v1.21.3, `crds.enabled: true`) issuing `barman-cloud-server-tls` / `barman-cloud-client-tls` from the vendored `Issuer` + `Certificate`s | cert-manager is a hard dependency of the plugin manifest, not a nice-to-have |
| Store + wiring | `ObjectStore sirius-growth/portal-wal`, `Cluster portal` `spec.plugins`, `ScheduledBackup portal-daily` `method: plugin` | `ObjectStore` must live in the Cluster's namespace, and its `serverName` field must stay **empty** (the CRD enforces this); the prefix comes from `spec.plugins[].parameters.serverName` |
Instance side: the operator injects an init-container sidecar
(`plugin-barman-cloud`, restartable sidecar) into `portal-1` and mounts a
`plugins` volume, which is why the Cluster restarted its primary once at
migration time. That sidecar runs `barman-cloud-wal-archive` /
`barman-cloud-backup` and enforces `retentionPolicy` every 30 min; the archive
URL it uses is `s3://pg-wal-archive portal <segment>` — same prefix as before.
Metrics change family with the archiver: `barman_cloud_cloudnative_pg_io_*`
(`…_last_available_backup_timestamp`, `…_first_recoverability_point`,
`…_last_failed_backup_timestamp`) replace `cnpg_collector_*` for this cluster.
The CNPG Grafana board accepts both. The deprecated
`cnpg_collector_last_available_backup_timestamp` is still *scraped* for portal
and holds the pre-migration value (22:34 UTC), so a panel that selects it alone
freezes at the last in-tree backup — that is why §8.4's dashboard change puts
the plugin metric first in the `or`.
Dependency order in Flux: `cert-manager` → `databases` (plugin + `ObjectStore`
CRD) → `apps` (the `ObjectStore` CR and the Cluster that references it).
---
## 9. Known hazards and runbook pointers
@ -892,3 +963,16 @@ All times 2026-10-26 UTC. `kubeconfig` on the Legion admin laptop → `https://1
| 36 | siriussec: `curl :2381/metrics` (etcd) | `wal_fsync` 158 >8.192 s / 2,518 >2.048 s of 14,813,192; `backend_commit` 187 >8.192 s of 6,652,027; 99.6 %/99.7 % ≤32 ms — matches the stated stall profile, so this is spiky contention, not a failing disk |
**Not verified, deliberately:** Cloudflare DNS records, Forgejo's `app.ini`, any secret material, and the SG-VPS/phone spoke routing beyond what the Linode's `wg show` reports.
**CNPG-I Barman Cloud plugin migration, verified 2026-11-19 22:57–23:07 UTC (commits `f3a8233`, `c452552`; kanban `t_5df331de`):**
| # | Command | Key result |
|---|---|---|
| 37 | `kubectl -n cert-manager get pods`; `kubectl -n flux-system get kustomization` | controller/webhook/cainjector `1/1 Running`; all 7 Kustomizations `Ready=True` at the same revision, `databases` `dependsOn cert-manager`, `apps` `dependsOn databases` |
| 38 | `kubectl -n cnpg-system get pods,certificate` | `barman-cloud-7b779d49d8-2pnbk 1/1 Running`; `barman-cloud-client` + `barman-cloud-server` certificates `READY=True` — the operator logged `Registered plugin` for `barman-cloud.cloudnative-pg.io` |
| 39 | `kubectl -n sirius-growth get cluster portal -o jsonpath='{.status.pluginStatus}'` | `[{name: barman-cloud.cloudnative-pg.io, version: 0.16.0, capabilities: [TYPE_RECONCILER_HOOKS, TYPE_LIFECYCLE_SERVICE, TYPE_INSTANCE_SIDECAR_INJECTION]}]`; pod `portal-1` now carries the `plugin-barman-cloud` init-sidecar and `plugins` volume; Cluster `Ready=True` |
| 40 | `kubectl -n sirius-growth logs portal-1 -c plugin-barman-cloud` | `Executing barman-cloud-wal-archive … ["--gzip","--endpoint-url","http://10.10.0.5:3900","--cloud-provider","aws-s3","s3://pg-wal-archive","portal", …05D]` → `Archived WAL file … elapsedWalTime 0.586`; retention runnable applied `14d` |
| 41 | `kubectl -n sirius-growth get backup portal-plugin-proof-1 -o wide` | `METHOD plugin`, `PHASE completed` (on-demand base backup through the plugin) |
| 42 | `aws --endpoint-url http://10.10.0.5:3900 s3 ls --recursive s3://pg-wal-archive/` (from a pod, Secret `portal-wal-s3`) | `portal/base/20261119T223452/…` (in-tree) **and** `portal/base/20261119T230300/…` (plugin) side by side, `portal/wals/…` continuous — the prefix did not move; 4 objects under `base/`, 10 under `wals/` |
| 43 | PITR rehearsal: marker `23:04:53.07`, poison `23:05:15.80`, `targetTime 2026-11-19T23:05:00Z` | restored `portal-pitr-test` → marker row present, `count(POISON%)=0`, `pg_is_in_recovery()=f`, `clients 4 / calendar_tokens 3 / applications 1` identical to the primary; test cluster + PVC deleted, probe table dropped afterwards |
| 44 | Prometheus (`/api/v1/query`) | `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp` = 1795129385 (23:03:05, the plugin backup), `…_first_recoverability_point` = 1795127697; the legacy `cnpg_collector_last_available_backup_timestamp` for `portal` still returns the **pre-migration** 1795127697 — hence the dashboard's `or` lists the plugin metric first |