Selective CloudNativePG Adoption: Moving Seven Stray Postgres Deployments onto PITR
Platform EngineeringPostgreSQLGitOpsSeven PostgreSQL databases in our openEduSuite platform were running as hand-rolled Kubernetes Deployments with a PVC each: discourse, openproject, dify, indico, toss, bigbluebutton, greenlight. Each had its own init scripts, its own service name, and a backup story consisting of a PVC snapshot plus a nightly pg_dump cron. That backup scheme has a quiet, structural hole: you can restore to last night, never to crash time. We recently closed that hole with CloudNativePG — not by rewriting everything, but by adopting deliberately.
The decision was against a big-bang migration
The evaluation doc we wrote first (cloudnativepg-evaluation) starts with a no. CNPG is PostgreSQL-only, so the MySQL/MariaDB fleet (Galera, SOGo, Request Tracker, ILIAS, InvoiceNinja, XWiki, Piler) is simply not a candidate — it needs its own answer, and we document it separately rather than pretending an operator will save it. The small file/SQLite services (hedgedoc, caldav, overleaf) keep their current, cheap form.
What remained were the six or seven stray Postgres instances that carried real user data but no point-in-time recovery. For those, the reference architecture already existed inside the org: operaton-db has run on CloudNativePG since early 2026 — operator pinned at 1.30.x, barman-cloud plugin archiving WAL into our own S3 (SeaweedFS), a daily ScheduledBackup at 01:30, thirty-day retention, everything managed by ArgoCD. Two other databases (dependencytrack, litellm) sit on the conscious opposite pattern: regeneratable data, no backup at all. Adoption therefore means copying a proven shape, not inventing one — the sequence runs from least to most exposed: toss → dify → indico → discourse → openproject → greenlight.
The unglamorous part: images
CNPG owns the pods, which means the distro image has to fit its contract: uid/gid 26, no custom entrypoint, barman tooling available. Two of our apps needed freshly derived images, and both derivations produced a surprise:
- Discourse needs the
vectorextension (plus pg_trgm, unaccent, hstore). The legacydiscourse-postgresimage is a full application-style build with its own entrypoint and uid 999 — CNPG-incompatible. Solution: a genericpostgresql-pgvectorderivation (PG 16.16 + pgvector 0.8.7 viawithPackages), verified by actually creating the extension and running a distance operator, not just by building it. - Indico is live on PostgreSQL 17, and
pg_restorerefuses to restore into a target with a lower major version than the source. So the cluster image ispostgresql-17(17.12, nix) — pinning everything to the fleet default 16 would have failed the import mid-window. - Greenlight runs upstream
postgres:16-alpine. Upstream images are exactly the kind of unpinned drift our supply-chain gates exist for; it gets hardened to a pinned nix image before it gets a CNPG CR, not during.
Pushing the new images also needed a trick: the in-cluster registry host has no Docker daemon, so the flow became nix build | gzip -dc | rsync | skopeo copy docker-archive → docker:// inside a container with --network host.
Two lessons we had already paid for
An earlier CNPG incident (operator migration to a nix-built image, ~45 minutes of downtime) left two rules that shaped this adoption:
- Architecture metadata matters. The nix operator image shipped without multi-arch binaries, and pod recreation hung on image resolution. Today the pipeline records the target architecture per image and the operator is pinned by digest — boring, mandatory, and written into the runbook.
- Server-side apply tracks field ownership. CNPG's controller writes several spec fields itself (backup target mode among them). If the manifest does not declare them explicitly, ArgoCD sees permanent OutOfSync drift and someone eventually adds a
--forcethey shouldn't trust. The adoption manifests declare the controller-owned defaults literally, so SSA reconciles cleanly.
What the databases get
Each adopted database is three objects: a Cluster CR (single instance where the app never had replicas — HA is optional, the PITR is the point), a barmancloud ObjectStore CR pointing at s3://…/cnpg/<db>/, and a ScheduledBackup at 0 30 1 * * * (note the six fields — CNPG cron includes seconds, and five-field crons fail in ways that look like operator bugs). Credentials move to <db>-db-creds secrets created out of band, so app passwords do not change. Consumers then switch their host to the CNPG -rw service and the old Deployment goes away.
The payoff is concrete: restore to any point within retention instead of last night's dump; WAL archiving into storage we already operate; declarative upgrades via rolling image bounces; a metrics endpoint per pod for Prometheus without sidecar surgery.
What "done" looks like
Not "everything on one operator". The end state we are implementing is: CNPG for the stateful Postgres apps (seven), documented exception lists for MySQL/MariaDB and the regeneratable pair, and one backup mechanism in the platform's centre of gravity instead of seven small cron jobs nobody watched. Half of the migrations will be boring — and after the incident lessons above, boring is the entire point.
Status: the adoption is complete — all seven databases run on CNPG now. The change (cnpg-adopt-postgres-backends) was delivered task-by-task (45/45), archived, and its spec graduated into the platform's operating standard (database/cnpg-management). One finding during rollout: a nightly backup job had silently failed for days, so the fleet gained a cnpg-backup-check CronJob plus a CNPGBackupCheckFailed alert (>26 h backup gap) — PITR is only as good as the chain you watch.