cnpg-cluster
by daviunx
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
| Requirement | Detail |
|---|---|
| Kubernetes | 1.25 or newer, with a StorageClass that supports dynamic provisioning |
| CloudNativePG operator | Installed 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 Operator | Optional, only for externalSecrets.enabled |
| Prometheus Operator | Optional, only for the PodMonitor that monitoring.enabled renders |
| Object storage | Optional, 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: 0promotes a replica as soon as the primary is lost,maintenance.reusePVC: truelets an instance come back on its own volume after a node is reclaimed, and anti-affinity ispreferredso a smaller node pool still schedules every instance. Setaffinity.tolerationsandpooler.defaultTolerationsto 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 pastreplicaRecovery.minRestartsrestarts, 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.instancesrenders a PgBouncerPoolerof typerworro. Pooler pods take their resources, affinity, tolerations, node selector, priority class and topology spread from thepooler.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 andscheduledBackup.*renders theScheduledBackup.backup.method: barmanObjectStore(default) keeps the object store on the cluster;backup.method: pluginrenders anObjectStorefor the Barman Cloud Plugin, which upstream recommends because the built-in integration is deprecated. GCS can authenticate through GKE Workload Identity (backup.gcs.gkeEnvironment: trueplus the service account annotation), S3 and Azure through a secret the chart can create or one you name.
Examples
| File | What it installs |
|---|---|
examples/minimal.yaml | One instance, no backups, no pooler, no PodDisruptionBudget |
examples/ha-spot.yaml | Three instances on tainted spot nodes, read-write pooler, daily GCS backups through Workload Identity, replica recovery |
Values
| Key | Type | Default | Description |
|---|---|---|---|
| affinity.additionalPodAffinity | object | {} | Additional pod affinity rules |
| affinity.additionalPodAntiAffinity | object | {} | Additional pod anti-affinity rules |
| affinity.enablePodAntiAffinity | bool | true | Enable pod anti-affinity (spread instances across nodes) REQUIRED for HA on preemptible nodes |
| affinity.nodeAffinity | object | {} | Node affinity rules |
| affinity.nodeSelector | object | {} | Node selector labels |
| affinity.podAntiAffinityType | string | "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.tolerations | list | [] | Pod tolerations |
| affinity.topologyKey | string | "kubernetes.io/hostname" | Topology key for anti-affinity kubernetes.io/hostname = different nodes (recommended for preemptible) topology.kubernetes.io/zone = different zones |
| auth.appUser | object | {"enabled":true,"existingSecret":"","password":"","username":"app"} | Application user configuration |
| auth.appUser.enabled | bool | true | Enable application user |
| auth.appUser.existingSecret | string | "" | Use existing secret for app user credentials |
| auth.appUser.password | string | "" | Password (use existingSecret or externalSecrets for production) |
| auth.appUser.username | string | "app" | Username |
| auth.superuser | object | {"enabled":false,"existingSecret":"","password":""} | Superuser (postgres) configuration |
| auth.superuser.enabled | bool | false | Enable 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.existingSecret | string | "" | Use existing secret for superuser credentials |
| auth.superuser.password | string | "" | Password (use existingSecret or externalSecrets for production) |
| backup.azure | object | {"container":"","credentials":{"connectionString":""},"inheritFromAzureAD":false,"path":"","storageAccount":""} | Azure Blob Storage configuration |
| backup.azure.container | string | "" | Container name |
| backup.azure.credentials | object | {"connectionString":""} | Credentials |
| backup.azure.inheritFromAzureAD | bool | false | Use Azure AD authentication |
| backup.azure.path | string | "" | Path within container |
| backup.azure.storageAccount | string | "" | Storage account name. Builds the destination https://.blob.core.windows.net// |
| backup.credentials | object | {"createSecret":false,"existingSecret":""} | Credentials secret configuration |
| backup.credentials.createSecret | bool | false | Create secret from values |
| backup.credentials.existingSecret | string | "" | Use existing secret |
| backup.data | object | {"compression":"gzip","encryption":"","jobs":2} | Base backup configuration |
| backup.data.compression | string | "gzip" | Compression: gzip, bzip2, snappy |
| backup.data.encryption | string | "" | Encryption algorithm |
| backup.data.jobs | int | 2 | Number of parallel backup jobs |
| backup.destinationPath | string | "" | Custom destination path (overrides provider-specific path) |
| backup.enabled | bool | false | Enable backups |
| backup.gcs | object | {"bucket":"","credentials":{"key":"gcp-credentials.json"},"gkeEnvironment":false,"path":""} | GCS (Google Cloud Storage) configuration |
| backup.gcs.bucket | string | "" | GCS bucket name |
| backup.gcs.credentials | object | {"key":"gcp-credentials.json"} | Explicit credentials (if not using Workload Identity) |
| backup.gcs.gkeEnvironment | bool | false | Authenticate with GKE Workload Identity instead of a credentials secret |
| backup.gcs.path | string | "" | Path within bucket (defaults to cluster name) |
| backup.method | string | "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.plugin | object | {"instanceSidecarConfiguration":{},"name":"barman-cloud.cloudnative-pg.io","objectStoreName":"","serverName":""} | Barman Cloud Plugin settings, used when backup.method is plugin |
| backup.plugin.instanceSidecarConfiguration | object | {} | Sidecar settings for every instance: resources, env, logLevel, retentionPolicyIntervalSeconds |
| backup.plugin.name | string | "barman-cloud.cloudnative-pg.io" | Plugin name registered with the operator |
| backup.plugin.objectStoreName | string | "" | ObjectStore resource name (defaults to the cluster name) |
| backup.plugin.serverName | string | "" | Server name (folder) inside the object store (defaults to the cluster name) |
| backup.provider | string | "" | Backup provider: gcs, s3, or azure |
| backup.retentionPolicy | string | "30d" | Retention policy (e.g., "30d", "7d") |
| backup.s3 | object | {"bucket":"","credentials":{"accessKeyId":"","secretAccessKey":""},"endpoint":"","path":"","region":""} | S3 configuration |
| backup.s3.bucket | string | "" | S3 bucket name |
| backup.s3.credentials | object | {"accessKeyId":"","secretAccessKey":""} | Credentials (use externalSecrets for production) |
| backup.s3.endpoint | string | "" | Custom endpoint (for S3-compatible storage) |
| backup.s3.path | string | "" | Path within bucket |
| backup.s3.region | string | "" | AWS region |
| backup.target | string | "prefer-standby" | Backup target: primary or prefer-standby |
| backup.wal | object | {"compression":"gzip","encryption":"","maxParallel":8} | WAL archiving configuration |
| backup.wal.compression | string | "gzip" | Compression: gzip, bzip2, snappy |
| backup.wal.encryption | string | "" | Encryption algorithm |
| backup.wal.maxParallel | int | 8 | Maximum parallel WAL archiving jobs |
| bootstrap.initdb | object | {"database":"app","options":[],"owner":"app","postInitApplicationSQL":[],"postInitApplicationSQLRefs":{"configMapRefs":[],"secretRefs":[]},"postInitSQL":[],"postInitTemplateSQL":[],"secret":{}} | initdb configuration (new cluster) |
| bootstrap.initdb.database | string | "app" | Default database name |
| bootstrap.initdb.options | list | [] | Additional initdb options |
| bootstrap.initdb.owner | string | "app" | Default database owner |
| bootstrap.initdb.postInitApplicationSQL | list | [] | SQL to run in app database after initdb |
| bootstrap.initdb.postInitApplicationSQLRefs | object | {"configMapRefs":[],"secretRefs":[]} | References to ConfigMaps/Secrets with SQL scripts |
| bootstrap.initdb.postInitSQL | list | [] | SQL to run after initdb |
| bootstrap.initdb.postInitTemplateSQL | list | [] | SQL to run in template1 after initdb |
| bootstrap.initdb.secret | object | {} | 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.method | string | "initdb" | Bootstrap method: initdb, recovery, or pg_basebackup |
| bootstrap.pg_basebackup | object | {"database":"","owner":"","source":""} | pg_basebackup configuration (clone from existing cluster) |
| bootstrap.pg_basebackup.source | string | "" | Source cluster name |
| bootstrap.recovery | object | {"backup":{},"recoveryTarget":{},"source":""} | recovery configuration (restore from backup) |
| bootstrap.recovery.backup | object | {} | Backup to restore from |
| bootstrap.recovery.recoveryTarget | object | {} | 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcnpg-cluster is pinned at v1.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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