Configuring Backups
CloudNativePG provides multiple ways to configure backups depending on your business requirements. A comparison of the currently available options can be found in their documentation.
The current version of this chart does not provide wrapper configuration around CRDs for managing backup configuration - such as ScheduledBackup or ObjectStore. You may configure these CRDs independently from this chart, or bundle them into the templates folder, based on your strategy for managing helm charts within your Kubernetes setup.
Warning
The images utilized in this chart do not contain Barman, and therefore it is required to leverage the Barman Cloud CNPG-I plugin to perform backups / wal archiving.
Backups via Barman Cloud CNPG-I plugin
You can follow these steps to setup scheduled backups to an AWS S3 bucket using the Barman Cloud CNPG-I plugin.
Note
The Barman Cloud CNPG-I plugin supports additional ObjectStore providers, including Microsoft Azure Blob Storage, Google Cloud Storage, and additional S3-compatible services such as MinIO, Linode Object Storage, and Digital Ocean Spaces.
For more information, refer to the Barman Cloud CNPG-I plugin documentation.
-
Install the Barman Cloud CNPG-I plugin
Installation instructions can be accessed in the Barman Cloud CNPG-I Plugin docs.
kubectl apply -f \ https://github.com/cloudnative-pg/plugin-barman-cloud/releases/download/v0.6.0/manifest.yamlThis step assumes you have already installed
cert-manageras part of general instructions for this chart. If not, install that according to the cert-manager documentation. -
Create an S3 Bucket and issue an Access Key / Secret Access Key for a user which has access to the bucket.
-
Create a Kubernetes secret and store your AWS credentials.
kubectl create secret generic aws-creds \ --from-literal=ACCESS_KEY_ID=<ACCESS_KEY_ID> \ --from-literal=ACCESS_SECRET_KEY=<ACCESS_SECRET_KEY> -
Create an
ObjectStorewhich points to your S3 bucket and is configured to fetch secrets from theaws-credssecret above.You can add this template into the templates folder or manage it through a separate Helm deployment:
apiVersion: barmancloud.cnpg.io/v1 kind: ObjectStore metadata: name: s3-store spec: configuration: destinationPath: "s3://<YOUR BUCKET NAME>/path/if/desired" s3Credentials: accessKeyId: name: aws-creds key: ACCESS_KEY_ID secretAccessKey: name: aws-creds key: ACCESS_SECRET_KEYNote
You should generally not re-use an ObjectStore across multiple CloudNativePG clusters, but the data will be namespaced with the name of each CloudNativePG cluster (pgedge-n1 for example).
-
Create or update your cluster to configure backups via the plugin.
For example, the following template enables backups and WAL archiving via the Barman Cloud CNPG-I plugin into the
ObjectStoredefined above:pgEdge: appName: pgedge nodes: - name: n1 hostname: pgedge-n1-rw clusterSpec: plugins: - name: barman-cloud.cloudnative-pg.io isWALArchiver: true parameters: barmanObjectName: s3-store - name: n2 hostname: pgedge-n2-rw clusterSpec: storage: size: 1Gi -
Once deployed, run backups via the
kubectl cnpgplugin.kubectl cnpg backup pgedge-n1 -m plugin --plugin-name barman-cloud.cloudnative-pg.ioOnce created, you can monitor your backup via kubectl:
kubectl get backups -
If desired, configure scheduled backups with Barman via the
ScheduledBackupresource.For example, to setup a scheduled backup at midnight everyday for the
n1node, use this template:apiVersion: postgresql.cnpg.io/v1 kind: ScheduledBackup metadata: name: scheduled-pgedge-n1 spec: schedule: "0 0 0 * * *" backupOwnerReference: self cluster: name: pgedge-n1 method: plugin pluginConfiguration: name: barman-cloud.cloudnative-pg.io