db(portal): migrate WAL archiving to the CNPG-I Barman Cloud plugin #21
11 changed files with 1312 additions and 51 deletions
|
|
@ -27,49 +27,35 @@ spec:
|
|||
# ---------------------------------------------------------------------------
|
||||
# Point-in-time recovery: continuous WAL archiving + daily base backups into
|
||||
# Garage on the Linode hub (10.10.0.5), i.e. a different power and internet
|
||||
# domain from this primary. Companion object: ScheduledBackup portal-daily.
|
||||
# domain from this primary. Companion objects: ObjectStore portal-wal (the
|
||||
# store + 14d retention) and ScheduledBackup portal-daily.
|
||||
#
|
||||
# This is the CNPG-I Barman Cloud **plugin** (Deployment cnpg-system/barman-cloud,
|
||||
# vendored in infrastructure/databases/base), not the operator's in-tree
|
||||
# barman-cloud support: 1.30 deprecates the in-tree path and 1.31 removes it
|
||||
# (`Warning: Native support for Barman Cloud backups and recovery is
|
||||
# deprecated ...`). See objectstore-portal-wal.yaml for the store definition.
|
||||
#
|
||||
# `serverName: portal` is the barman prefix and must stay exactly the cluster
|
||||
# name: the plugin writes to s3://pg-wal-archive/portal/{base,wals}/... — the
|
||||
# same objects the in-tree archiver left behind, so the existing 14-day window
|
||||
# stays restorable. Changing it starts a new prefix and abandons that window.
|
||||
#
|
||||
# Credentials live in Secret sirius-growth/portal-wal-s3 (created out of band
|
||||
# from the Garage key `cnpg-portal-wal`, id GK7f2b4bb1fc9abaec50fde37b, scope
|
||||
# read+write on bucket `pg-wal-archive` only). Never commit the key values.
|
||||
#
|
||||
# This uses the operator's in-tree barman-cloud integration rather than the
|
||||
# CNPG-I barman-cloud plugin: same barman-cloud binaries, no extra Deployment
|
||||
# and TLS plugin registration to keep alive on a 3-node homelab. The plugin is
|
||||
# the migration path when 1.30's in-tree support is finally removed.
|
||||
#
|
||||
# `pg_dump` in forgejo/cluster-backup still runs nightly for this database as
|
||||
# a second, logical copy: a dump survives a barman-format regression or a
|
||||
# store that has been emptied, and it is the only copy that is readable
|
||||
# without barman. Belt and braces, not redundancy theatre — the RPO comes
|
||||
# from the WAL archive, not from the dump.
|
||||
backup:
|
||||
retentionPolicy: "14d"
|
||||
barmanObjectStore:
|
||||
# Bucket root, not bucket/portal: barman appends the server name (which
|
||||
# defaults to the Cluster name), so the archive lives at
|
||||
# s3://pg-wal-archive/portal/{base,wals}/... — one prefix per cluster,
|
||||
# which is what lets forgejo/pg share this bucket later without colliding.
|
||||
destinationPath: s3://pg-wal-archive
|
||||
endpointURL: http://10.10.0.5:3900
|
||||
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
|
||||
# gzip on both: this is a WAL stream over the WireGuard mesh to a fixed
|
||||
# 20 GB store, so bytes on the wire and in the bucket are the cost.
|
||||
wal:
|
||||
compression: gzip
|
||||
maxParallel: 2
|
||||
data:
|
||||
compression: gzip
|
||||
jobs: 2
|
||||
plugins:
|
||||
- name: barman-cloud.cloudnative-pg.io
|
||||
isWALArchiver: true
|
||||
parameters:
|
||||
barmanObjectName: portal-wal
|
||||
serverName: portal
|
||||
# Scraped via podmonitor.yaml in this directory (hand-written; see the comment
|
||||
# in apps/base/forgejo/podmonitor.yaml for why enablePodMonitor is false).
|
||||
# Only the operator's default query set here — this database needs no custom
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ resources:
|
|||
- service-blog.yaml
|
||||
- service-portal-gate.yaml
|
||||
- httproute.yaml
|
||||
# The WAL archive store must exist before the Cluster references it.
|
||||
- objectstore-portal-wal.yaml
|
||||
- cluster.yaml
|
||||
- scheduled-backup.yaml
|
||||
- podmonitor.yaml
|
||||
|
|
|
|||
51
apps/base/sirius-growth/objectstore-portal-wal.yaml
Normal file
51
apps/base/sirius-growth/objectstore-portal-wal.yaml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# The WAL archive for Cluster sirius-growth/portal, in the CNPG-I Barman Cloud
|
||||
# plugin's own CR instead of Cluster.spec.backup.barmanObjectStore.
|
||||
#
|
||||
# Same store, same layout: destinationPath is the *bucket root* and the plugin
|
||||
# appends the server name (Cluster.spec.plugins[].parameters.serverName, set to
|
||||
# `portal`), so the existing objects stay exactly where the in-tree archiver put
|
||||
# them — s3://pg-wal-archive/portal/{base,wals}/... . Anything that changes the
|
||||
# prefix silently abandons the 14-day window that is already in the bucket.
|
||||
#
|
||||
# `spec.configuration` is the literal translation of the retired
|
||||
# `spec.backup.barmanObjectStore` block (same schema, same Secret), and
|
||||
# `retentionPolicy` moved here from Cluster.spec.backup.retentionPolicy — in the
|
||||
# plugin architecture retention is a property of the store, not the cluster.
|
||||
#
|
||||
# Credentials: Secret sirius-growth/portal-wal-s3 (Garage key `cnpg-portal-wal`,
|
||||
# id GK7f2b4bb1fc9abaec50fde37b, RW on bucket `pg-wal-archive` only), created
|
||||
# out of band. The key values are deliberately not in git.
|
||||
apiVersion: barmancloud.cnpg.io/v1
|
||||
kind: ObjectStore
|
||||
metadata:
|
||||
name: portal-wal
|
||||
namespace: sirius-growth
|
||||
spec:
|
||||
configuration:
|
||||
destinationPath: s3://pg-wal-archive
|
||||
endpointURL: http://10.10.0.5:3900
|
||||
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
|
||||
# gzip on both directions: this is a WAL stream over the WireGuard mesh into
|
||||
# a 20 GB store on the Linode, so bytes on the wire and in the bucket are
|
||||
# the cost. Must match what the in-tree archiver wrote (gzip) — the
|
||||
# archive is read by segment, but a mismatch in base-backup compression
|
||||
# would make the existing base backups unrestorable.
|
||||
wal:
|
||||
compression: gzip
|
||||
maxParallel: 2
|
||||
data:
|
||||
compression: gzip
|
||||
jobs: 2
|
||||
# Enforced by the plugin instance sidecar every 30 min (default
|
||||
# retentionPolicyIntervalSeconds) with barman-cloud's retention logic, i.e.
|
||||
# the same 14-day window the in-tree archiver maintained.
|
||||
retentionPolicy: "14d"
|
||||
|
|
@ -12,8 +12,13 @@ spec:
|
|||
name: portal
|
||||
# `self`: the Backup objects are owned by this ScheduledBackup, so deleting the
|
||||
# schedule (or the namespace) does not leave orphaned Backups pointing at the
|
||||
# cluster. Retention/cleanup of the archive itself is the Cluster's
|
||||
# spec.backup.retentionPolicy (14d), enforced by barman-cloud on each backup.
|
||||
# cluster. Retention/cleanup of the archive itself is the ObjectStore's
|
||||
# spec.retentionPolicy (14d), enforced by the plugin's sidecar.
|
||||
backupOwnerReference: self
|
||||
method: barmanObjectStore
|
||||
# Plugin method, not `barmanObjectStore`: the in-tree method is removed in
|
||||
# CNPG 1.31. `pluginConfiguration` names the CNPG-I plugin, whose
|
||||
# ObjectStore is referenced by the Cluster's spec.plugins.
|
||||
method: plugin
|
||||
pluginConfiguration:
|
||||
name: barman-cloud.cloudnative-pg.io
|
||||
immediate: false
|
||||
|
|
|
|||
|
|
@ -15,3 +15,7 @@ spec:
|
|||
prune: true
|
||||
dependsOn:
|
||||
- name: infrastructure
|
||||
# `sirius-growth` now carries an `ObjectStore` (barmancloud.cnpg.io) whose
|
||||
# CRD ships with the plugin in the `databases` Kustomization, and the
|
||||
# portal Cluster references it. Apply apps only after that CRD exists.
|
||||
- name: databases
|
||||
|
|
|
|||
|
|
@ -11,9 +11,15 @@ spec:
|
|||
kind: GitRepository
|
||||
name: flux-system
|
||||
path: ./infrastructure/databases/base
|
||||
# The CloudNativePG operator bundle contains its 11 CRDs. Those must never be
|
||||
# pruned automatically: dropping them would delete every Cluster/Database
|
||||
# The CloudNativePG operator bundle contains its 11 CRDs, and the vendored
|
||||
# Barman Cloud plugin adds the `ObjectStore` CRD. Those must never be pruned
|
||||
# automatically: dropping them would delete every Cluster/Database/Backup
|
||||
# object (and the Forgejo and portal Postgres clusters with them). Same
|
||||
# reasoning as gateway-api-crds. Reverting the operator Deployment args is a
|
||||
# git change, not a prune.
|
||||
prune: false
|
||||
# The plugin's operator<->plugin mTLS pair is issued by cert-manager
|
||||
# (Issuer/Certificate in the vendored plugin manifest). Applying those before
|
||||
# the cert-manager CRDs and webhook exist just churns; wait for it.
|
||||
dependsOn:
|
||||
- name: cert-manager
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# CloudNativePG operator, pinned at 1.30.0.
|
||||
# CloudNativePG operator, pinned at 1.30.0, plus the CNPG-I Barman Cloud plugin.
|
||||
#
|
||||
# The operator was installed by hand at some point and Flux did not own it, so
|
||||
# a kubectl patch was lost on every reinstall. The upstream release manifest is
|
||||
|
|
@ -7,9 +7,21 @@
|
|||
# and patched only for the deltas that already existed live plus the widened
|
||||
# leader-election window. Do not upgrade the version in this directory without
|
||||
# a separate, tested change: the CRDs are in this bundle.
|
||||
#
|
||||
# The Barman Cloud plugin is the replacement for the in-tree barman-cloud
|
||||
# integration that 1.30 still ships but deprecates (removed in 1.31). Also
|
||||
# vendored verbatim (sha256
|
||||
# aee614683892dd4b44ff9f7afaca55254f1c28de17abbaa0552bf2e1228f7155,
|
||||
# https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v0.16.0/manifest.yaml):
|
||||
# a separate Deployment in cnpg-system, registered with the operator through
|
||||
# Service annotations, carrying the `ObjectStore` CRD (barmancloud.cnpg.io). Its
|
||||
# operator<->plugin mTLS pair is issued by cert-manager (Flux Kustomization
|
||||
# `cert-manager`). v0.16.0 requires CloudNativePG >= 1.30 — satisfied above.
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
resources:
|
||||
- upstream/cnpg-1.30.0.yaml
|
||||
- upstream/plugin-barman-cloud-0.16.0.yaml
|
||||
patches:
|
||||
- path: patch-controller-manager.yaml
|
||||
- path: patch-barman-cloud.yaml
|
||||
|
|
|
|||
36
infrastructure/databases/base/patch-barman-cloud.yaml
Normal file
36
infrastructure/databases/base/patch-barman-cloud.yaml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Delta on the vendored Barman Cloud plugin manifest (0.16.0).
|
||||
#
|
||||
# Upstream ships the plugin operator with `--log-level=debug`. On this cluster
|
||||
# nothing scrapes the plugin's logs and siriussec's root filesystem is the
|
||||
# tightest disk in the estate, so the arg is lowered to `info`. Everything else
|
||||
# in the release manifest is used verbatim — including the Service annotations
|
||||
# (`cnpg.io/pluginName`, `cnpg.io/pluginPort`, `cnpg.io/pluginClientSecret`,
|
||||
# `cnpg.io/pluginServerSecret`) that are the actual CNPG-I registration.
|
||||
#
|
||||
# The whole `args` list is restated because strategic merge replaces a container
|
||||
# `args` list rather than merging it.
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: barman-cloud
|
||||
namespace: cnpg-system
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: barman-cloud
|
||||
args:
|
||||
- operator
|
||||
- --server-cert=/server/tls.crt
|
||||
- --server-key=/server/tls.key
|
||||
- --client-cert=/client/tls.crt
|
||||
- --server-address=:9090
|
||||
- --leader-elect
|
||||
- --log-level=info
|
||||
resources:
|
||||
requests:
|
||||
cpu: 50m
|
||||
memory: 64Mi
|
||||
limits:
|
||||
cpu: 500m
|
||||
memory: 256Mi
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -245,9 +245,9 @@ cnpg = [
|
|||
{"h": 5, "w": 4, "x": 16, "y": 1},
|
||||
desc="1 = the operator is asking for a manual switchover (e.g. after a fencing event).",
|
||||
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]),
|
||||
stat("Last available backup", [target('max by (namespace) (cnpg_collector_last_available_backup_timestamp{%s})' % CLUSTER_NS)],
|
||||
stat("Last available backup", [target('max by (namespace) (cnpg_collector_last_available_backup_timestamp{%s} or barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{%s})' % (CLUSTER_NS, CLUSTER_NS))],
|
||||
{"h": 5, "w": 4, "x": 20, "y": 1}, unit="dateTimeAsIso",
|
||||
desc="0 = never. There are NO Backup/Cluster backup resources in this cluster (verified: `kubectl get backups.postgresql.cnpg.io -A` is empty), so a 0 here is the honest answer, not a broken panel.",
|
||||
desc="0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, which exposes its own metric family `barman_cloud_cloudnative_pg_io_*`; the in-tree `cnpg_collector_*` name is kept in the `or` for any cluster still on the deprecated path. A 0 means neither series exists.",
|
||||
thresholds=[{"color": "red", "value": None}, {"color": "green", "value": 1}]),
|
||||
|
||||
row("Throughput", 6),
|
||||
|
|
@ -280,10 +280,10 @@ cnpg = [
|
|||
desc="pg_database_size. Both PVs are 10Gi (forgejo/pg) and 5Gi (sirius-growth/portal) — this is the trend that fills them."),
|
||||
ts("WAL generation", [target('sum by (namespace) (rate(cnpg_collector_wal_bytes{%s}[5m]))' % CLUSTER_NS, "{{namespace}}")],
|
||||
{"h": 8, "w": 8, "x": 8, "y": 25}, unit="Bps",
|
||||
desc="Bytes of WAL written per second. On a cluster with no backups, WAL has nothing archiving it away."),
|
||||
desc="Bytes of WAL written per second. sirius-growth/portal archives its WAL to the Linode Garage; forgejo/pg does not archive, so its WAL only ever fills the pg_wal directory."),
|
||||
ts("WAL archiver failures", [target('max by (namespace) (cnpg_pg_stat_archiver_failed_count{%s})' % CLUSTER_NS, "{{namespace}}")],
|
||||
{"h": 8, "w": 8, "x": 16, "y": 25}, unit="short",
|
||||
desc="pg_stat_archiver.failed_count. Archiving is not configured on either cluster (no ObjectStore/backup), so treat non-zero here as 'something was attempted and failed'."),
|
||||
desc="pg_stat_archiver.failed_count. Archiving is configured only on sirius-growth/portal (Barman Cloud plugin -> Linode Garage); forgejo/pg has no archiver, so any non-zero value is the honest signal that WAL failed to reach the archive."),
|
||||
|
||||
row("Replication (single instance — panels are honest about it)", 33),
|
||||
ts("Replication lag", [target('max by (namespace) (cnpg_pg_replication_lag{%s})' % CLUSTER_NS, "{{namespace}}")],
|
||||
|
|
@ -294,9 +294,11 @@ cnpg = [
|
|||
{"h": 6, "w": 8, "x": 8, "y": 34}, unit="short",
|
||||
desc="Both clusters run instances: 1, so 0 streaming replicas and in_recovery=0 is the correct reading. A future replica would light these up with no dashboard change."),
|
||||
note("Known unknowns on the CNPG board", """\
|
||||
- **No backups exist.** `kubectl get backups.postgresql.cnpg.io -A` returns nothing; neither Cluster
|
||||
declares `spec.backup`. The "Last available backup" stat therefore reads 0 (never) — that is the
|
||||
real state, not a missing metric.
|
||||
- **Backups exist on one cluster only.** `sirius-growth/portal` archives WAL + daily base backups
|
||||
through the CNPG-I Barman Cloud plugin (`ObjectStore portal-wal`) into the Linode Garage;
|
||||
`forgejo/pg` has no archiver by design. The "Last available backup" stat reads 0 only if neither
|
||||
the plugin's `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp` nor the legacy
|
||||
`cnpg_collector_last_available_backup_timestamp` series exists.
|
||||
- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /
|
||||
in recovery are structurally zero. The panels show the zero and say so instead of hiding them.
|
||||
- **Query age vs transaction age.** CNPG's default query set exposes
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ data:
|
|||
"id": 29,
|
||||
"type": "stat",
|
||||
"title": "Last available backup",
|
||||
"description": "0 = never. There are NO Backup/Cluster backup resources in this cluster (verified: `kubectl get backups.postgresql.cnpg.io -A` is empty), so a 0 here is the honest answer, not a broken panel.",
|
||||
"description": "0 = never. sirius-growth/portal archives through the CNPG-I Barman Cloud plugin, which exposes its own metric family `barman_cloud_cloudnative_pg_io_*`; the in-tree `cnpg_collector_*` name is kept in the `or` for any cluster still on the deprecated path. A 0 means neither series exists.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
|
|
@ -440,7 +440,7 @@ data:
|
|||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
},
|
||||
"expr": "max by (namespace) (cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"})",
|
||||
"expr": "max by (namespace) (cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"} or barman_cloud_cloudnative_pg_io_last_available_backup_timestamp{namespace=~\"$namespace\"})",
|
||||
"refId": "A",
|
||||
"editorMode": "code",
|
||||
"range": true,
|
||||
|
|
@ -937,7 +937,7 @@ data:
|
|||
"id": 40,
|
||||
"type": "timeseries",
|
||||
"title": "WAL generation",
|
||||
"description": "Bytes of WAL written per second. On a cluster with no backups, WAL has nothing archiving it away.",
|
||||
"description": "Bytes of WAL written per second. sirius-growth/portal archives its WAL to the Linode Garage; forgejo/pg does not archive, so its WAL only ever fills the pg_wal directory.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
|
|
@ -994,7 +994,7 @@ data:
|
|||
"id": 41,
|
||||
"type": "timeseries",
|
||||
"title": "WAL archiver failures",
|
||||
"description": "pg_stat_archiver.failed_count. Archiving is not configured on either cluster (no ObjectStore/backup), so treat non-zero here as 'something was attempted and failed'.",
|
||||
"description": "pg_stat_archiver.failed_count. Archiving is configured only on sirius-growth/portal (Barman Cloud plugin -> Linode Garage); forgejo/pg has no archiver, so any non-zero value is the honest signal that WAL failed to reach the archive.",
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "prometheus"
|
||||
|
|
@ -1203,7 +1203,7 @@ data:
|
|||
"showLineNumbers": false,
|
||||
"showMiniMap": false
|
||||
},
|
||||
"content": "- **No backups exist.** `kubectl get backups.postgresql.cnpg.io -A` returns nothing; neither Cluster\n declares `spec.backup`. The \"Last available backup\" stat therefore reads 0 (never) \u2014 that is the\n real state, not a missing metric.\n- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /\n in recovery are structurally zero. The panels show the zero and say so instead of hiding them.\n- **Query age vs transaction age.** CNPG's default query set exposes\n `cnpg_backends_max_tx_duration_seconds` (transaction age). Per-statement `query_start` age is not in\n the default set; adding it would need another custom query in the cluster's\n `customQueriesConfigMap`.\n- **Permissions.** Custom queries run as `cnpg_metrics_exporter`, not superuser. See\n docs/monitoring-dashboards.md for the GRANT the Forgejo Actions metrics need.\n"
|
||||
"content": "- **Backups exist on one cluster only.** `sirius-growth/portal` archives WAL + daily base backups\n through the CNPG-I Barman Cloud plugin (`ObjectStore portal-wal`) into the Linode Garage;\n `forgejo/pg` has no archiver by design. The \"Last available backup\" stat reads 0 only if neither\n the plugin's `barman_cloud_cloudnative_pg_io_last_available_backup_timestamp` nor the legacy\n `cnpg_collector_last_available_backup_timestamp` series exists.\n- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /\n in recovery are structurally zero. The panels show the zero and say so instead of hiding them.\n- **Query age vs transaction age.** CNPG's default query set exposes\n `cnpg_backends_max_tx_duration_seconds` (transaction age). Per-statement `query_start` age is not in\n the default set; adding it would need another custom query in the cluster's\n `customQueriesConfigMap`.\n- **Permissions.** Custom queries run as `cnpg_metrics_exporter`, not superuser. See\n docs/monitoring-dashboards.md for the GRANT the Forgejo Actions metrics need.\n"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue