Getting Started
Verified against the
mainmanifestcnpg-1.30.0-rc1.yaml. Commands assume a running Kubernetes cluster and a configuredkubectl.
Prerequisites
- A Kubernetes cluster (a local one such as kind or minikube is fine for this walkthrough).
kubectlconfigured to reach that cluster, with permission to apply cluster-scoped resources.- A default StorageClass, so the
Clustercan allocate a PersistentVolume.
Install
Apply the operator manifest. This example uses the release candidate manifest carried on main; for production use the matching YAML from the releases page of the stable line you want.
kubectl apply --server-side -f \
https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/main/releases/cnpg-1.30.0-rc1.yamlWait for the operator Deployment to roll out:
kubectl rollout status deployment \
-n cnpg-system cnpg-controller-managerA first working setup
Write a three-instance
Clusterdefinition tocluster-example.yaml:yamlapiVersion: postgresql.cnpg.io/v1 kind: Cluster metadata: name: cluster-example spec: instances: 3 storage: size: 1GiApply it:
bashkubectl apply -f cluster-example.yamlWatch the Pods come up. The operator labels every object it manages with
cnpg.io/cluster:bashkubectl get pods -l cnpg.io/cluster=cluster-exampleYou should see three Pods, one primary and two replicas, reaching
Running.
Verify it works
Install the cnpg kubectl plugin (the kubectl-cnpg binary built from cmd/kubectl-cnpg) and ask for cluster status:
kubectl cnpg status cluster-exampleA healthy cluster reports a single primary, the replica instances streaming, and a Cluster in healthy state summary. You can also confirm directly from the resource:
kubectl get cluster cluster-exampleThe STATUS column should read Cluster in healthy state once reconciliation settles.
Where to go next
- Backup and point-in-time recovery to object storage, configured through the barman-cloud plugin.
- High availability tuning: synchronous replication quorum (
minSyncReplicas/maxSyncReplicas) and theFailoverQuorumresource. - Connection pooling with the
PoolerCRD (PgBouncer) and monitoring with the generated PrometheusPodMonitor.
See the official documentation for these production concerns.