# Main HA PostgreSQL cluster: one primary and one streaming replica, each on its # own node with a node-local volume. Replication is asynchronous (nodes sit in # different regions), so a failover can lose the last few transactions. # # Layout: the primary runs on the music node (the powerful one), the replica on # master. A failover swaps the roles; switch back with # kubectl cnpg promote main # # Eligible nodes are core/external and carry workload/postgres=true. To move a # replica: label the new node, unlabel the old one, then recreate the instance # (kubectl cnpg destroy main ); the operator re-clones it from the primary. # # Endpoints inside the cluster: main-rw (primary), main-ro (replicas), # main-r (any instance) in the psql namespace. apiVersion: postgresql.cnpg.io/v1 kind: Cluster metadata: name: main namespace: psql spec: description: Main HA PostgreSQL cluster imageName: ghcr.io/cloudnative-pg/postgresql:17 instances: 2 enableSuperuserAccess: false # Roll updates replica-first and hand over by switchover instead of restarting the primary. primaryUpdateStrategy: unsupervised primaryUpdateMethod: switchover storage: storageClass: local-path size: 20Gi # local-path volumes cannot be expanded later affinity: enablePodAntiAffinity: true podAntiAffinityType: required topologyKey: kubernetes.io/hostname nodeSelector: homelab.hexor.cy/pool: core homelab.hexor.cy/exposure: external workload/postgres: "true" resources: requests: cpu: 500m memory: 1Gi limits: memory: 2Gi postgresql: parameters: max_connections: "200" shared_buffers: 512MB effective_cache_size: 1536MB