CNPG Postgres Operator cluster install

Deploy postgres clusters with ease using CNPG

Mon, 15 Jan 2024

This is my config for how I deployed my postgres cluster using CNPG. This is a fairly barebones implementation seeing as all I wanted was the postgres instances that can survive a pod going down without the service going interrupted for a while. You should for sure read the docs to see all of the options you can customize

An operator mananges our instances. I didn’t customize the operator and just used all of the default settings

helm repo add cnpg
helm repo update
helm upgrade --install cnpg --create-namespace cnpg-system cnpg/cloudnative-pg

Once the cluster is setup, all you need to do is deploy a cluster manifest

# Example of PostgreSQL cluster
kind: Cluster
  name: tds-postgresql
  namespace: default
  instances: 3
    storageClass: nfs-client
    size: 10Gi
    enablePodMonitor: true
  enableSuperuserAccess: true
      memory: "1Gi"
      memory: "1Gi"

This will deploy a postgres cluster with 3 instances, one will be read-write, the other 2 read only. If the read-write instance goes down, the operator will promote one of 2 read only instances. This will also deploy postgres 14 and create an empty database named app. All of the credentials will be stored as a secret credential

Buy Me A CoffeeDigitalOcean Referral Badge
Edward Beazer

Edward Beazer - I just like to build shit. Sometimes I get stuck for hours, even days while trying to figure out how to solve an issue or implement a new feature. Hope my tips and tutorials can save you some time.

DigitalOcean Referral Badge