PostgreSQL Operator
Every Stack namespace receives its own managed PostgreSQL cluster powered by CloudNativePG. The operator is installed automatically when you run stack init, and the Stack controller drives it for each StackApp.
Bootstrapping CloudNativePG
stack init applies:
- The CloudNativePG CRDs (
clusters.postgresql.cnpg.io, etc.). - The CloudNativePG operator deployment in the
stack-systemnamespace (or whatever you pass with--operator-namespace). - Supporting RBAC so the Stack controller can create
Clusterresources.
You can verify the installation with:
kubectl get pods -n stack-system -l app.kubernetes.io/name=cloudnative-pg kubectl get crd | grep postgresql.cnpg.io
What happens per StackApp
When you run stack install --manifest app.yaml, the controller:
- Creates a
Cluster(e.g.stack-db-cluster) inside your application namespace. - Generates unique credentials for application, readonly, migrations, and owner roles.
- Stores connection strings in
database-urlsanddb-ownersecrets. - Wires those secrets into your Deployment’s environment variables so the app, migrations, and helper services can connect securely.
The cluster includes streaming replicas and can enable extensions like pgvector so you’re ready for advanced search or embedding workloads when you need them.
Development shortcuts
- During local testing you can expose the database via NodePort by applying the
postgres-service-dev.yamlmanifest included in the repo. - If you need deterministic credentials, the controller accepts overrides via the manifest’s
spec.database.insecurePasswordsfield (intended only for tests).
Maintenance tips
- Use
kubectl cnpg status <cluster>(from the CloudNativePG plugin) to view backups, replicas, and failover readiness. stack operator --onceis useful after editing a manifest so you can confirm the database reconciliation succeeds.- For disaster recovery, pair CloudNativePG’s backup CRDs with your preferred object storage bucket; Stack’s defaults focus on day-one experience but the operator supports full PITR configurations.