cnpg-cluster

by daviunx

Helm chartv1.1.0App 1.29.1MITVerified publisher

Runs a CloudNativePG PostgreSQL cluster on Kubernetes, tuned to stay available on spot and preemptible nodes, with backups, PgBouncer pooling and automatic recovery of stuck replicas.

About this chart

CloudNativePG Cluster Helm Chart

Runs a CloudNativePG PostgreSQL cluster on Kubernetes from one values file: the Cluster, optional PgBouncer poolers, scheduled backups to GCS, S3 or Azure, PodMonitors, NetworkPolicies and External Secrets Operator integration. Its defaults are tuned for clusters that run on spot or preemptible nodes, where a node can disappear at any minute: immediate failover, PVC reuse, soft anti-affinity, and an optional recovery job that rebuilds replicas a reclaimed node left broken. It is for teams who already run the CloudNativePG operator and want one chart for every database instead of hand-written manifests per cluster. It is published by Neomanex, an AI-native company, and it is the chart we run our own production PostgreSQL on.

helm install my-postgres oci://ghcr.io/neomanexlabs/charts/cnpg-cluster --version 1.1.0 -f my-values.yaml

Add the repository

helm repo add neomanexlabs https://neomanexlabs.github.io/helm-charts
helm repo update
helm install my-postgres neomanexlabs/cnpg-cluster --version 1.1.0 -f my-values.yaml

Both install paths serve the identical package.

Requirements

RequirementDetail
Kubernetes1.25 or newer, with a StorageClass that supports dynamic provisioning
CloudNativePG operatorInstalled cluster-wide before this chart. The chart renders postgresql.cnpg.io/v1 resources only and does not install CRDs. Tested with operator 1.28 and 1.29
External Secrets OperatorOptional, only for externalSecrets.enabled
Prometheus OperatorOptional, only for the PodMonitor that monitoring.enabled renders
Object storageOptional, only for backups: a GCS bucket, an S3 (or S3-compatible) bucket, or an Azure Blob Storage container

Quick start

examples/minimal.yaml installs a single instance with no backups and no pooler. examples/ha-spot.yaml installs the production topology: three instances, a read-write pooler, daily backups to GCS through Workload Identity and the replica recovery job.

helm template my-postgres neomanexlabs/cnpg-cluster -f examples/ha-spot.yaml

Read the render before installing. The high availability example names a placeholder bucket and service account; replace both.

Credentials

By default CloudNativePG creates the database owner with a generated password and stores it in the <cluster>-app secret. To choose the password, supply it through auth.appUser.password, auth.appUser.existingSecret or externalSecrets.appUserSecret, and name that secret in bootstrap.initdb.secret.name (<cluster>-app-user unless you set auth.appUser.existingSecret). auth.appUser.username must match bootstrap.initdb.owner. When bootstrap.initdb.secret is set, the operator uses that secret instead of generating <cluster>-app.

Superuser access is off by default, as in CloudNativePG. With auth.superuser.enabled: true and nothing else, the operator generates the <cluster>-superuser secret. Set auth.superuser.password, auth.superuser.existingSecret or externalSecrets.superuserSecret to supply it yourself.

Client access

When postgresql.pg_hba is empty, the cluster accepts scram-sha-256 password logins from the RFC 1918 private ranges only. Set your own list to replace that rule set entirely.

How it works

The chart renders one CloudNativePG Cluster plus the optional resources you turn on. Four behaviours are worth knowing:

  • Spot-friendly defaults. failover.delay: 0 promotes a replica as soon as the primary is lost, maintenance.reusePVC: true lets an instance come back on its own volume after a node is reclaimed, and anti-affinity is preferred so a smaller node pool still schedules every instance. Set affinity.tolerations and pooler.defaultTolerations to the taint your spot nodes carry.
  • Replica recovery. A node reclaimed mid-write can leave a replica in CrashLoopBackOff on a damaged volume, and CloudNativePG keeps restarting it. With replicaRecovery.enabled, a CronJob finds replicas past replicaRecovery.minRestarts restarts, deletes the pod and its PVCs, and lets the operator rebuild the replica from the primary. It never touches the current primary. The same job deletes instance pods that are Pending, no longer declared by the cluster, and missing their PVC, because those can never schedule. Every run ends with a verdict and fails when the read-write Service has no endpoints, so a broken database shows up as a failed Job.
  • Poolers. Each entry in pooler.instances renders a PgBouncer Pooler of type rw or ro. Pooler pods take their resources, affinity, tolerations, node selector, priority class and topology spread from the pooler.default* values unless the entry overrides them. Pooler pods carry the chart version label, so any chart upgrade rolls them; PostgreSQL instance pods are not restarted by a chart upgrade.
  • Backups. backup.* configures Barman WAL archiving plus base backups and scheduledBackup.* renders the ScheduledBackup. backup.method: barmanObjectStore (default) keeps the object store on the cluster; backup.method: plugin renders an ObjectStore for the Barman Cloud Plugin, which upstream recommends because the built-in integration is deprecated. GCS can authenticate through GKE Workload Identity (backup.gcs.gkeEnvironment: true plus the service account annotation), S3 and Azure through a secret the chart can create or one you name.

Examples

FileWhat it installs
examples/minimal.yamlOne instance, no backups, no pooler, no PodDisruptionBudget
examples/ha-spot.yamlThree instances on tainted spot nodes, read-write pooler, daily GCS backups through Workload Identity, replica recovery

Values

KeyTypeDefaultDescription
affinity.additionalPodAffinityobject{}Additional pod affinity rules
affinity.additionalPodAntiAffinityobject{}Additional pod anti-affinity rules
affinity.enablePodAntiAffinitybooltrueEnable pod anti-affinity (spread instances across nodes) REQUIRED for HA on preemptible nodes
affinity.nodeAffinityobject{}Node affinity rules
affinity.nodeSelectorobject{}Node selector labels
affinity.podAntiAffinityTypestring"preferred"Anti-affinity type preferred = best-effort (allows scheduling even if not perfect) required = strict (pods won't schedule if can't spread) Use 'preferred' for preemptible nodes to avoid scheduling issues
affinity.tolerationslist[]Pod tolerations
affinity.topologyKeystring"kubernetes.io/hostname"Topology key for anti-affinity kubernetes.io/hostname = different nodes (recommended for preemptible) topology.kubernetes.io/zone = different zones
auth.appUserobject{"enabled":true,"existingSecret":"","password":"","username":"app"}Application user configuration
auth.appUser.enabledbooltrueEnable application user
auth.appUser.existingSecretstring""Use existing secret for app user credentials
auth.appUser.passwordstring""Password (use existingSecret or externalSecrets for production)
auth.appUser.usernamestring"app"Username
auth.superuserobject{"enabled":false,"existingSecret":"","password":""}Superuser (postgres) configuration
auth.superuser.enabledboolfalseEnable superuser access. Off by default, as in CloudNativePG. When on and no password, existingSecret or external secret is given, the operator generates the <cluster>-superuser secret itself.
auth.superuser.existingSecretstring""Use existing secret for superuser credentials
auth.superuser.passwordstring""Password (use existingSecret or externalSecrets for production)
backup.azureobject{"container":"","credentials":{"connectionString":""},"inheritFromAzureAD":false,"path":"","storageAccount":""}Azure Blob Storage configuration
backup.azure.containerstring""Container name
backup.azure.credentialsobject{"connectionString":""}Credentials
backup.azure.inheritFromAzureADboolfalseUse Azure AD authentication
backup.azure.pathstring""Path within container
backup.azure.storageAccountstring""Storage account name. Builds the destination https://.blob.core.windows.net//
backup.credentialsobject{"createSecret":false,"existingSecret":""}Credentials secret configuration
backup.credentials.createSecretboolfalseCreate secret from values
backup.credentials.existingSecretstring""Use existing secret
backup.dataobject{"compression":"gzip","encryption":"","jobs":2}Base backup configuration
backup.data.compressionstring"gzip"Compression: gzip, bzip2, snappy
backup.data.encryptionstring""Encryption algorithm
backup.data.jobsint2Number of parallel backup jobs
backup.destinationPathstring""Custom destination path (overrides provider-specific path)
backup.enabledboolfalseEnable backups
backup.gcsobject{"bucket":"","credentials":{"key":"gcp-credentials.json"},"gkeEnvironment":false,"path":""}GCS (Google Cloud Storage) configuration
backup.gcs.bucketstring""GCS bucket name
backup.gcs.credentialsobject{"key":"gcp-credentials.json"}Explicit credentials (if not using Workload Identity)
backup.gcs.gkeEnvironmentboolfalseAuthenticate with GKE Workload Identity instead of a credentials secret
backup.gcs.pathstring""Path within bucket (defaults to cluster name)
backup.methodstring"barmanObjectStore"How the cluster talks to the object store: barmanObjectStore (built into the operator, deprecated upstream) or plugin (Barman Cloud Plugin, which must be installed in the operator namespace). Switching an existing cluster triggers a rolling restart
backup.pluginobject{"instanceSidecarConfiguration":{},"name":"barman-cloud.cloudnative-pg.io","objectStoreName":"","serverName":""}Barman Cloud Plugin settings, used when backup.method is plugin
backup.plugin.instanceSidecarConfigurationobject{}Sidecar settings for every instance: resources, env, logLevel, retentionPolicyIntervalSeconds
backup.plugin.namestring"barman-cloud.cloudnative-pg.io"Plugin name registered with the operator
backup.plugin.objectStoreNamestring""ObjectStore resource name (defaults to the cluster name)
backup.plugin.serverNamestring""Server name (folder) inside the object store (defaults to the cluster name)
backup.providerstring""Backup provider: gcs, s3, or azure
backup.retentionPolicystring"30d"Retention policy (e.g., "30d", "7d")
backup.s3object{"bucket":"","credentials":{"accessKeyId":"","secretAccessKey":""},"endpoint":"","path":"","region":""}S3 configuration
backup.s3.bucketstring""S3 bucket name
backup.s3.credentialsobject{"accessKeyId":"","secretAccessKey":""}Credentials (use externalSecrets for production)
backup.s3.endpointstring""Custom endpoint (for S3-compatible storage)
backup.s3.pathstring""Path within bucket
backup.s3.regionstring""AWS region
backup.targetstring"prefer-standby"Backup target: primary or prefer-standby
backup.walobject{"compression":"gzip","encryption":"","maxParallel":8}WAL archiving configuration
backup.wal.compressionstring"gzip"Compression: gzip, bzip2, snappy
backup.wal.encryptionstring""Encryption algorithm
backup.wal.maxParallelint8Maximum parallel WAL archiving jobs
bootstrap.initdbobject{"database":"app","options":[],"owner":"app","postInitApplicationSQL":[],"postInitApplicationSQLRefs":{"configMapRefs":[],"secretRefs":[]},"postInitSQL":[],"postInitTemplateSQL":[],"secret":{}}initdb configuration (new cluster)
bootstrap.initdb.databasestring"app"Default database name
bootstrap.initdb.optionslist[]Additional initdb options
bootstrap.initdb.ownerstring"app"Default database owner
bootstrap.initdb.postInitApplicationSQLlist[]SQL to run in app database after initdb
bootstrap.initdb.postInitApplicationSQLRefsobject{"configMapRefs":[],"secretRefs":[]}References to ConfigMaps/Secrets with SQL scripts
bootstrap.initdb.postInitSQLlist[]SQL to run after initdb
bootstrap.initdb.postInitTemplateSQLlist[]SQL to run in template1 after initdb
bootstrap.initdb.secretobject{}Secret with the owner credentials (basic-auth, username equal to owner). When empty, the operator generates the owner password in <cluster>-app. To bootstrap with a secret from auth.appUser or externalSecrets.appUserSecret, name it here: <cluster>-app-user unless auth.appUser.existingSecret is set.
bootstrap.methodstring"initdb"Bootstrap method: initdb, recovery, or pg_basebackup
bootstrap.pg_basebackupobject{"database":"","owner":"","source":""}pg_basebackup configuration (clone from existing cluster)
bootstrap.pg_basebackup.sourcestring""Source cluster name
bootstrap.recoveryobject{"backup":{},"recoveryTarget":{},"source":""}recovery configuration (restore from backup)
bootstrap.recovery.backupobject{}Backup to restore from
bootstrap.recovery.recoveryTargetobject{}Recovery target configuration

Deploy cnpg-cluster with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cnpg-cluster on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartcnpg-cluster is pinned at v1.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply