Reference
Cluster CRD Reference¶
Complete reference for the CNPG Cluster custom resource.
Basic Cluster Spec¶
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: myapp-postgres
namespace: myapp
spec:
instances: 2
storage:
size: 10Gi
storageClass: longhorn-redundant-app
Key Spec Fields¶
instances¶
Number of PostgreSQL instances (1 for standalone, ≥2 for HA).
postgresql¶
PostgreSQL configuration parameters:
postgresql:
parameters:
max_connections: "200"
shared_buffers: "256MB"
work_mem: "4MB"
bootstrap¶
Cluster initialization method:
bootstrap:
initdb:
database: myapp
owner: myapp
Or restore from backup:
bootstrap:
recovery:
source: backup-name
storage¶
Persistent volume configuration:
storage:
size: 10Gi
storageClass: longhorn-redundant-app
resizeInUseVolumes: true
backup¶
Backup configuration:
backup:
barmanObjectStore:
destinationPath: s3://bucket/
endpointURL: https://fsn1.your-objectstorage.com
s3Credentials:
accessKeyId: { name: secret, key: ACCESS_KEY_ID }
secretAccessKey: { name: secret, key: SECRET_ACCESS_KEY }
retentionPolicy: "30d"
resources¶
CPU and memory limits:
resources:
requests: { cpu: 100m, memory: 256Mi }
limits: { cpu: 500m, memory: 512Mi }
affinity¶
Pod placement rules:
affinity:
podAntiAffinityType: preferred # or "required"
nodeSelector: { ... }
tolerations: [ ... ]
monitoring¶
Prometheus monitoring:
monitoring:
enablePodMonitor: true
Status Fields¶
Check cluster status:
kubectl get cluster myapp-postgres -n myapp -o yaml
Key status fields:
status.phase- Cluster lifecycle phasestatus.instances- Number of running instancesstatus.currentPrimary- Current primary instance namestatus.latestGeneratedNode- Last provisioned instance number