cluster

by CloudNativePG

Helm chartv0.9.0Verified publisher

Deploys and manages a CloudNativePG cluster and its associated resources.

About this chart

cluster

Warning

This chart is under active development.

Advised caution when using in production!

A note on the chart's purpose

This is an opinionated chart that is designed to provide a subset of simple, stable and safe configurations using the CloudNativePG operator. It is designed to provide a simple way to perform recovery operations to decrease your RTO.

It is not designed to be a one size fits all solution. If you need a more complicated setup we strongly recommend that you either:

  • use the operator directly
  • create your own chart
  • use Kustomize to modify the chart's resources

Note that the latter option carries it's own risks as the chart configuration may change, especially before it reaches a stable release.

That being said, we welcome PRs that improve the chart, but please keep in mind that we don't plan to support every single configuration that the operator provides and we may reject PRs that add too much complexity and maintenance difficulty to the chart.

Migrating to the Barman Cloud Plugin

[!WARNING] Starting with version 1.26, native backup and recovery capabilities are being progressively phased out of the core operator and moved to official CNPG-I plugins. This transition aligns with CloudNativePG's shift towards a backup-agnostic architecture, enabled by its extensible interface—CNPG-I—which standardizes the management of WAL archiving, physical base backups, and corresponding recovery processes.

Migrating from the Built-in CloudNativePG Backup to the Barman Cloud CNPG-I plugin is a straightforward, single step process, as the chart creates the necessary ObjectStore resource as a helm hook before the cluster is updated.

All you have to do is change the backup method from barmanObjectStore to plugin and specify the plugin name. The same change should also be applied to your scheduled backups.

backups:
  enabled: true
- method: barmanObjectStore
+ method: plugin
+ pluginConfiguration:
+   name: barman-cloud.cloudnative-pg.io
  scheduledBackups:
    - name: daily-backup
      schedule: "0 0 0 * * *"
      backupOwnerReference: self
-     method: barmanObjectStore
+     method: plugin
+     pluginConfiguration:
+       name: barman-cloud.cloudnative-pg.io

Getting Started

Installing the Operator

Skip this step if the CNPG operator is already installed in your cluster.

helm repo add cnpg https://cloudnative-pg.github.io/charts
helm upgrade --install cnpg \
--namespace cnpg-system \
--create-namespace \
cnpg/cloudnative-pg

Setting up a CNPG Cluster

helm repo add cnpg https://cloudnative-pg.github.io/charts
helm upgrade --install cnpg \
--namespace cnpg-database \
--create-namespace \
--values values.yaml \
cnpg/cluster

A more detailed guide can be found in the Getting Started docs.

Cluster Configuration

Database types

Currently the chart supports two database types. These are configured via the type parameter. These are:

  • postgresql - A standard PostgreSQL database.
  • postgis - A PostgreSQL database with the PostGIS extension installed.

Depending on the type the chart will use a different Docker image and fill in some initial setup, like extension installation.

Modes of operation

The chart has three modes of operation. These are configured via the mode parameter:

  • standalone - Creates new or updates an existing CNPG cluster. This is the default mode.
  • replica - Creates a replica cluster from an existing CNPG cluster.
  • recovery - Recovers a CNPG cluster from a backup, object store or via pg_basebackup.

Backup configuration

CNPG implements disaster recovery via Barman. The following section configures the barman object store where backups will be stored. Barman performs backups of the cluster filesystem base backup and WALs. Both are stored in the specified location. The backup provider is configured via the backups.provider parameter. The following providers are supported:

  • S3 or S3-compatible stores, like RustFS
  • Microsoft Azure Blob Storage
  • Google Cloud Storage

Additionally you can specify the following parameters:

  • backups.retentionPolicy - The retention policy for backups. Defaults to 30d.
  • backups.scheduledBackups - An array of scheduled backups containing a name and a crontab schedule. Example:
backups:
  scheduledBackups:
    - name: daily-backup
      schedule: "0 0 0 * * *" # Daily at midnight
      backupOwnerReference: self

Each backup adapter takes it's own set of parameters, listed in the Configuration options section. Refer to the table for the full list of parameters and place the configuration under the appropriate key: backups.s3, backups.azure, or backups.google.

Recovery

There is a separate document outlining the recovery procedure here: Recovery

Examples

There are several configuration examples in the examples directory. Refer to them for a basic setup and refer to the CloudNativePG Documentation for more advanced configurations.

Requirements

Kubernetes: >=1.29.0-0

Values

KeyTypeDefaultDescription
backups.azure.connectionStringstring""
backups.azure.containerNamestring""
backups.azure.inheritFromAzureADboolfalse
backups.azure.pathstring"/"
backups.azure.serviceNamestring"blob"
backups.azure.storageAccountstring""
backups.azure.storageKeystring""
backups.azure.storageSasTokenstring""
backups.data.compressionstring"gzip"Data compression method. One of `` (for no compression), gzip, bzip2 or snappy.
backups.data.encryptionstring"AES256"Whether to instruct the storage provider to encrypt data files. One of `` (use the storage container default), AES256 or aws:kms.
backups.data.jobsint2Number of data files to be archived or restored in parallel.
backups.destinationPathstring""Overrides the provider specific default path.
backups.enabledboolfalseYou need to configure backups manually, so backups are disabled by default.
backups.endpointCAobject{"create":false,"key":"","name":"","value":""}Specifies a CA bundle to validate a privately signed certificate.
backups.endpointCA.createboolfalseCreates a secret with the given value if true, otherwise uses an existing secret.
backups.endpointURLstring""Overrides the provider specific default endpoint.
backups.google.applicationCredentialsstring""
backups.google.bucketstring""
backups.google.gkeEnvironmentboolfalse
backups.google.pathstring"/"
backups.instanceSidecarConfigurationobject{}The configuration for the Barman Cloud Plugin sidecar that runs in the instance pods. See: https://cloudnative-pg.io/plugin-barman-cloud/docs/next/plugin-barman-cloud.v1/#instancesidecarconfiguration
backups.methodstring"barmanObjectStore"One of barmanObjectStore (default) or plugin
backups.objectStore.annotationsobject{}Extra annotations for the plugin ObjectStore resources only (unlike cluster.annotations, these are not applied to the Cluster). Handy for argocd.argoproj.io/sync-wave: "-1" when helmHook is false.
backups.objectStore.createbooltrueWhether to create the ObjectStore resource used by the barman-cloud.cloudnative-pg.io plugin. Its name comes from the plugin's barmanObjectName parameter (see cluster.plugins), defaulting to <fullname>-backups. Set to false to reference an ObjectStore managed outside of this chart, leaving it untouched.
backups.objectStore.helmHookbooltrueRender the ObjectStore as a Helm hook (pre-install,pre-upgrade,pre-rollback) so it is applied before the Cluster. Set to false for GitOps tools (ArgoCD/Flux) that treat Helm hooks as ephemeral resources: as a hook the ObjectStore gets pruned and WAL archiving breaks. When false, order the ObjectStore yourself via the annotations below (e.g. an ArgoCD sync-wave).
backups.pluginConfigurationobject{}
backups.providerstring"s3"One of s3, azure or google
backups.retentionPolicystring"30d"Retention policy for backups
backups.s3.accessKeystring""
backups.s3.bucketstring""
backups.s3.inheritFromIAMRoleboolfalseUse the role based authentication without providing explicitly the keys
backups.s3.pathstring"/"
backups.s3.regionstring""
backups.s3.secretKeystring""
backups.scheduledBackups[0].backupOwnerReferencestring"self"Backup owner reference
backups.scheduledBackups[0].methodstring"barmanObjectStore"Backup method, can be barmanObjectStore (default), volumeSnapshot or plugin.
backups.scheduledBackups[0].namestring"daily-backup"Scheduled backup name
backups.scheduledBackups[0].pluginConfigurationobject{}
backups.scheduledBackups[0].schedulestring"0 0 0 * * *"Schedule in cron format
backups.secret.createbooltrueWhether to create a secret for the backup credentials
backups.secret.namestring""Name of the backup credentials secret
backups.targetstring"prefer-standby"Which instance takes the backups. One of prefer-standby (default) or primary.
backups.wal.compressionstring"gzip"WAL compression method. One of `` (for no compression), gzip, bzip2 or snappy.
backups.wal.encryptionstring"AES256"Whether to instruct the storage provider to encrypt WAL files. One of `` (use the storage container default), AES256 or aws:kms.
backups.wal.maxParallelint1Number of WAL files to be archived or restored in parallel.
cluster.additionalLabelsobject{}
cluster.affinityobject{"topologyKey":"topology.kubernetes.io/zone"}Affinity/Anti-affinity rules for Pods. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-AffinityConfiguration
cluster.annotationsobject{}
cluster.certificatesobject{}The configuration for the CA and related certificates. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-CertificatesConfiguration
cluster.console.enabledboolfalseDeploys a console StatefulSet to run long-running commands against the cluster (e.g. CREATE INDEX).
cluster.enablePDBbooltrueAllow to disable PDB, mainly useful for upgrade of single-instance clusters or development purposes See: https://cloudnative-pg.io/documentation/current/kubernetes_upgrade/#pod-disruption-budgets
cluster.enableSuperuserAccessbooltrueWhen this option is enabled, the operator will use the SuperuserSecret to update the postgres user password. If the secret is not present, the operator will automatically create one. When this option is disabled, the operator will ignore the SuperuserSecret content, delete it when automatically created, and then blank the password of the postgres user by setting it to NULL.
cluster.envlist[]Env follows the Env format to pass environment variables to the pods created in the cluster
cluster.envFromlist[]EnvFrom follows the EnvFrom format to pass environment variables sources to the pods to be used by Env
cluster.ephemeralVolumeSourceobject{}Override the default emptyDir used by CNPG for temporary storage. See: https://cloudnative-pg.io/documentation/current/cluster_conf/#ephemeral-volumes
cluster.imageCatalogRefobject{}Reference to ImageCatalog of ClusterImageCatalog, if specified takes precedence over cluster.imageName
cluster.imageNamestring""Name of the container image, supporting both tags (:) and digests for deterministic and repeatable deployments: :@sha256:
cluster.imagePullPolicystring"IfNotPresent"Image pull policy. One of Always, Never or IfNotPresent. If not defined, it defaults to IfNotPresent. Cannot be updated. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images
cluster.imagePullSecretslist[]The list of pull secrets to be used to pull the images. See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-LocalObjectReference
cluster.initdbobject{}BootstrapInitDB is the configuration of the bootstrap process when initdb is used. See: https://cloudnative-pg.io/documentation/current/bootstrap/ See: https://cloudnative-pg.io/documentation/current/cloudnative-pg.v1/#postgresql-cnpg-io-v1-bootstrapinitdb
cluster.instancesint3Number of instances
cluster.logLevelstring"info"The instances' log level, one of the following values: error, warning, info (default), debug, trace
cluster.monitoring.customQuerieslist[]Custom Prometheus metrics Will be stored in the ConfigMap
cluster.monitoring.customQueriesSecretlist[]The list of secrets containing the custom queries
cluster.monitoring.disableDefaultQueriesboolfalseWhether the default queries should be injected. Set it to true if you don't want to

Deploy cluster with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has 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 chartcluster is pinned at v0.9.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