How crunchydata/postgres-operator works
PGO is a Kubernetes operator that turns declarative Postgres custom resources into managed clusters. The primary workflow is a user submitting a PostgresCluster; the operator reconciles Kubernetes resources and maintains the cluster’s desired state. The product also includes HA via Patroni, backup and restore, monitoring, connection pooling, pgAdmin, and PostgreSQL upgrade management. Source excerpts show controller setup and selected reconciliation behavior; README statements support the broader capabilities, but unsampled subsystem internals are not asserted in detail.
Main entry points: controller.go Cluster Reconciler · main.go Operator Manager · postgrescluster_types.go Custom Resources · runtime Reconcile Runtime
Components 17
Operator Control
- Custom Resources
pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go - Operator Manager
cmd/postgres-operator/main.go - Reconcile Runtime
internal/controller/runtime
Cluster Lifecycle
- Cluster Reconciler
internal/controller/postgrescluster/controller.go - PostgreSQL Config
internal/postgres/reconcile.go - HA and Failover
internal/patroni/reconcile.go - TLS and Certificates
internal/pki/pki.go
Cluster Services
- Connection Pooling
internal/pgbouncer/reconcile.go - Cluster pgAdmin
internal/pgadmin/reconcile.go - Standalone pgAdmin
internal/controller/standalone_pgadmin/controller.go
Operations
- Version Upgrades
internal/controller/pgupgrade/pgupgrade_controller.go - Backup and Restore
internal/pgbackrest/reconcile.go - Metrics and Logs
internal/collector/postgres.go - Postgres Monitoring
internal/pgmonitor/exporter.go
Other components
- Kubernetes User
- Kubernetes API
- Postgres Cluster
Connections 21
- Kubernetes User → Custom Resources: defines desired state
README.md - Custom Resources → Operator Manager: submits resources
README.md - Operator Manager → Reconcile Runtime: starts manager
cmd/postgres-operator/main.go - Operator Manager → Cluster Reconciler: registers controller
cmd/postgres-operator/main.go - Operator Manager → Version Upgrades: registers controller
cmd/postgres-operator/main.go - Operator Manager → Standalone pgAdmin: registers controller
- Reconcile Runtime → Kubernetes API: watches and writes
- Cluster Reconciler → Kubernetes API: reconciles resources
internal/controller/postgrescluster/controller.go - Cluster Reconciler → PostgreSQL Config: configures database
- Cluster Reconciler → HA and Failover: configures HA
- Cluster Reconciler → Backup and Restore: configures backups
- Cluster Reconciler → Connection Pooling: configures pooling
- Cluster Reconciler → Cluster pgAdmin: configures pgAdmin
- Cluster Reconciler → TLS and Certificates: secures cluster
- Cluster Reconciler → Metrics and Logs: configures telemetry
- Metrics and Logs → Postgres Monitoring: uses monitoring
- Cluster Reconciler → Postgres Cluster: maintains desired state
README.md - Version Upgrades → Postgres Cluster: updates version
internal/controller/pgupgrade/pgupgrade_controller.go - Backup and Restore → Postgres Cluster: backs up data
README.md - HA and Failover → Postgres Cluster: manages failover
README.md - Standalone pgAdmin → Kubernetes API: reconciles resources
internal/controller/standalone_pgadmin/controller.go