|
1 | 1 | [](https://cloudnative-pg.io/) |
2 | 2 |
|
3 | | -# New Component for CloudNativePG |
| 3 | +# Barman Cloud CNPG-i plugin |
4 | 4 |
|
5 | | -TODO |
| 5 | +This repository contains the codebase for the a CNPG-i plugin implementing |
| 6 | +backup and recovery using the [barman-cloud](https://pgbarman.org/) tool suite. |
6 | 7 |
|
| 8 | +## Table of contents |
| 9 | + |
| 10 | +- [Features](#features) |
| 11 | +- [Prerequisites](#prerequisites) |
| 12 | +- [Installation](#installation) |
| 13 | +- [Usage](#usage) |
| 14 | + - [WAL Archiving](#wal-archiving) |
| 15 | + - [Backup](#backup) |
| 16 | + - [Restore](#restore) |
| 17 | + - [Replica clusters](#replica-clusters) |
| 18 | + |
| 19 | +## Features |
| 20 | + |
| 21 | +This plugin sets up continuous backup on a PostgreSQL cluster to object stores |
| 22 | +with barman-cloud. |
| 23 | + |
| 24 | +The features implemented by this plugin are: |
| 25 | + |
| 26 | +* Data directory backup |
| 27 | +* Data directory restore |
| 28 | +* WAL archiving |
| 29 | +* WAL restoring |
| 30 | +* Point-in-time recovery |
| 31 | +* Replica clusters |
| 32 | + |
| 33 | +Every object store supported by barman-cloud is supported by |
| 34 | +this plugin too: |
| 35 | + |
| 36 | +* Amazon AWS S3 |
| 37 | +* Google Cloud Storage |
| 38 | +* Microsoft Azure Blob Storage |
| 39 | + |
| 40 | +Backups taken by the in-tree object store support can be restored with this |
| 41 | +plugin. |
| 42 | + |
| 43 | + |
| 44 | +## Prerequisites |
| 45 | + |
| 46 | +* [CloudNativePG](https://cloudnative-pg.io) 1.25RC1 or newer |
| 47 | +* [cert-manager](https://cert-manager.io/) |
| 48 | + |
| 49 | + |
| 50 | +## Installation |
| 51 | + |
| 52 | +**IMPORTANT** The plugin should be installed in the same namespace where the |
| 53 | +operator is installed in. This is usually `cnpg-system`. |
| 54 | + |
| 55 | +### Step 1 - verify the prerequisites are met |
| 56 | + |
| 57 | +Supposing that CloudNativePG is installed in the default `cnpg-system` |
| 58 | +namespace, the current version can be verified with: |
| 59 | + |
| 60 | +```sh |
| 61 | +$ kubectl get deployment -n cnpg-system cnpg-controller-manager | grep ghcr.io/cloudnative-pg/cloudnative-pg |
| 62 | +``` |
| 63 | +```output |
| 64 | +image: ghcr.io/cloudnative-pg/cloudnative-pg:1.25.0-rc1 |
| 65 | +``` |
| 66 | + |
| 67 | +Please ensure you're using CloudNativePG 1.25-rc1 or newer. |
| 68 | + |
| 69 | +The [cert-manager](https://cert-manager.io) installation can be verified by |
| 70 | +using the [cmctl](https://cert-manager.io/v1.6-docs/usage/cmctl/#installation) |
| 71 | +tool: |
| 72 | + |
| 73 | +```sh |
| 74 | +$ cmctl check api |
| 75 | +``` |
| 76 | +```output |
| 77 | +The cert-manager API is ready |
| 78 | +``` |
| 79 | + |
| 80 | +### Step 2 - install the barman-cloud plugin |
| 81 | + |
| 82 | +The plugin can be installed via its manifest: |
| 83 | + |
| 84 | +<!-- |
| 85 | +TODO: |
| 86 | +Replace this with the latest manifest as archived on the latest release |
| 87 | +--> |
| 88 | + |
| 89 | +```sh |
| 90 | +$ curl -Lo plugin-barman-cloud.tgz https://api.github.com/repos/cloudnative-pg/plugin-barman-cloud/tarball/main |
| 91 | +$ tar xvzf plugin-barman-cloud.tgz |
| 92 | +$ cd cloudnative-pg-plugin-barman-cloud* |
| 93 | +$ kubectl apply -k kubernetes/ |
| 94 | +``` |
| 95 | +```output |
| 96 | +customresourcedefinition.apiextensions.k8s.io/objectstores.barmancloud.cnpg.io created |
| 97 | +serviceaccount/plugin-barman-cloud created |
| 98 | +role.rbac.authorization.k8s.io/leader-election-role created |
| 99 | +clusterrole.rbac.authorization.k8s.io/metrics-auth-role created |
| 100 | +clusterrole.rbac.authorization.k8s.io/metrics-reader created |
| 101 | +clusterrole.rbac.authorization.k8s.io/objectstore-editor-role created |
| 102 | +clusterrole.rbac.authorization.k8s.io/objectstore-viewer-role created |
| 103 | +clusterrole.rbac.authorization.k8s.io/plugin-barman-cloud created |
| 104 | +rolebinding.rbac.authorization.k8s.io/leader-election-rolebinding created |
| 105 | +clusterrolebinding.rbac.authorization.k8s.io/metrics-auth-rolebinding created |
| 106 | +clusterrolebinding.rbac.authorization.k8s.io/plugin-barman-cloud-binding created |
| 107 | +secret/plugin-barman-cloud-8tfddg42gf created |
| 108 | +service/barman-cloud created |
| 109 | +deployment.apps/barman-cloud configured |
| 110 | +certificate.cert-manager.io/barman-cloud-client created |
| 111 | +certificate.cert-manager.io/barman-cloud-server created |
| 112 | +issuer.cert-manager.io/selfsigned-issuer created |
| 113 | +``` |
| 114 | + |
| 115 | +To verify that the plugin is installed and properly running: |
| 116 | + |
| 117 | +```sh |
| 118 | +$ kubectl rollout status deployment -n cnpg-system barman-cloud |
| 119 | +``` |
| 120 | +```output |
| 121 | +deployment "barman-cloud" successfully rolled out |
| 122 | +``` |
| 123 | + |
| 124 | +## Usage |
| 125 | + |
| 126 | +### The BarmanObjectStore object |
| 127 | + |
| 128 | +A BarmanObjectStore object should be created for each object stored used by the |
| 129 | +PostgreSQL architecture. This is an example: |
| 130 | + |
| 131 | +```yaml |
| 132 | +apiVersion: barmancloud.cnpg.io/v1 |
| 133 | +kind: ObjectStore |
| 134 | +metadata: |
| 135 | + name: minio-store |
| 136 | +spec: |
| 137 | + configuration: |
| 138 | + destinationPath: s3://backups/ |
| 139 | + endpointURL: http://minio:9000 |
| 140 | + s3Credentials: |
| 141 | + accessKeyId: |
| 142 | + name: minio |
| 143 | + key: ACCESS_KEY_ID |
| 144 | + secretAccessKey: |
| 145 | + name: minio |
| 146 | + key: ACCESS_SECRET_KEY |
| 147 | + wal: |
| 148 | + compression: gzip |
| 149 | +``` |
| 150 | +
|
| 151 | +The `objectstore.spec.configuration` API is the same api used by the [in-tree |
| 152 | +barman-cloud |
| 153 | +support](https://pkg.go.dev/github.com/cloudnative-pg/barman-cloud/pkg/api#BarmanObjectStoreConfiguration) and can be used like discussed in [the relative documentation page](https://cloudnative-pg.io/documentation/preview/backup_barmanobjectstore/). |
| 154 | + |
| 155 | +### WAL Archiving |
| 156 | + |
| 157 | +Once the `BarmanObjectStore` has been defined, a cluster using it to archive |
| 158 | +WALs will reference it: |
| 159 | + |
| 160 | +```yaml |
| 161 | +apiVersion: postgresql.cnpg.io/v1 |
| 162 | +kind: Cluster |
| 163 | +metadata: |
| 164 | + name: cluster-example |
| 165 | +spec: |
| 166 | + instances: 3 |
| 167 | + imagePullPolicy: Always |
| 168 | + plugins: |
| 169 | + - name: barman-cloud.cloudnative-pg.io |
| 170 | + parameters: |
| 171 | + barmanObjectName: minio-store |
| 172 | +
|
| 173 | + storage: |
| 174 | + size: 1Gi |
| 175 | +``` |
| 176 | + |
| 177 | +### Backup |
| 178 | + |
| 179 | +To request a backup of the cluster, the `backup.spec.pluginConfiguration` stanza |
| 180 | +must be set with the name of this plugin, like in the following example: |
| 181 | + |
| 182 | +```yaml |
| 183 | +apiVersion: postgresql.cnpg.io/v1 |
| 184 | +kind: Backup |
| 185 | +metadata: |
| 186 | + name: backup-example |
| 187 | +spec: |
| 188 | + method: plugin |
| 189 | +
|
| 190 | + cluster: |
| 191 | + name: cluster-example |
| 192 | +
|
| 193 | + pluginConfiguration: |
| 194 | + name: barman-cloud.cloudnative-pg.io |
| 195 | +``` |
| 196 | + |
| 197 | +### Restore |
| 198 | + |
| 199 | +To recovery a cluster from an object store, an external cluster definition is |
| 200 | +needed like in the following example: |
| 201 | + |
| 202 | +```yaml |
| 203 | +apiVersion: postgresql.cnpg.io/v1 |
| 204 | +kind: Cluster |
| 205 | +metadata: |
| 206 | + name: cluster-restore |
| 207 | +spec: |
| 208 | + instances: 3 |
| 209 | + imagePullPolicy: IfNotPresent |
| 210 | +
|
| 211 | + bootstrap: |
| 212 | + recovery: |
| 213 | + source: source |
| 214 | +
|
| 215 | + externalClusters: |
| 216 | + - name: source |
| 217 | + plugin: |
| 218 | + name: barman-cloud.cloudnative-pg.io |
| 219 | + parameters: |
| 220 | + barmanObjectName: minio-store |
| 221 | + serverName: cluster-example |
| 222 | +
|
| 223 | + storage: |
| 224 | + size: 1Gi |
| 225 | +``` |
| 226 | + |
| 227 | +The previous definition can be combined with WAL archiving even that requires |
| 228 | +multiple BarmanObjectStores to be referred: |
| 229 | + |
| 230 | +```yaml |
| 231 | +apiVersion: postgresql.cnpg.io/v1 |
| 232 | +kind: Cluster |
| 233 | +metadata: |
| 234 | + name: cluster-restore |
| 235 | +spec: |
| 236 | + instances: 3 |
| 237 | + imagePullPolicy: IfNotPresent |
| 238 | +
|
| 239 | + bootstrap: |
| 240 | + recovery: |
| 241 | + source: source |
| 242 | +
|
| 243 | + plugins: |
| 244 | + - name: barman-cloud.cloudnative-pg.io |
| 245 | + parameters: |
| 246 | + barmanObjectName: minio-store-bis |
| 247 | +
|
| 248 | + externalClusters: |
| 249 | + - name: source |
| 250 | + plugin: |
| 251 | + name: barman-cloud.cloudnative-pg.io |
| 252 | + parameters: |
| 253 | + barmanObjectName: minio-store |
| 254 | + serverName: cluster-example |
| 255 | +
|
| 256 | + storage: |
| 257 | + size: 1Gi |
| 258 | +``` |
| 259 | + |
| 260 | +### Replica clusters |
| 261 | + |
| 262 | +The previous definition can be combined to setup a distributed topology like in |
| 263 | +the following example: |
| 264 | + |
| 265 | +```yaml |
| 266 | +apiVersion: postgresql.cnpg.io/v1 |
| 267 | +kind: Cluster |
| 268 | +metadata: |
| 269 | + name: cluster-dc-a |
| 270 | +spec: |
| 271 | + instances: 3 |
| 272 | + primaryUpdateStrategy: unsupervised |
| 273 | +
|
| 274 | + storage: |
| 275 | + storageClass: csi-hostpath-sc |
| 276 | + size: 1Gi |
| 277 | +
|
| 278 | + plugins: |
| 279 | + - name: barman-cloud.cloudnative-pg.io |
| 280 | + parameters: |
| 281 | + barmanObjectName: minio-store-a |
| 282 | +
|
| 283 | + replica: |
| 284 | + self: cluster-dc-a |
| 285 | + primary: cluster-dc-a |
| 286 | + source: cluster-dc-b |
| 287 | +
|
| 288 | + externalClusters: |
| 289 | + - name: cluster-dc-a |
| 290 | + plugin: |
| 291 | + name: barman-cloud.cloudnative-pg.io |
| 292 | + parameters: |
| 293 | + barmanObjectName: minio-store-a |
| 294 | +
|
| 295 | + - name: cluster-dc-b |
| 296 | + plugin: |
| 297 | + name: barman-cloud.cloudnative-pg.io |
| 298 | + parameters: |
| 299 | + barmanObjectName: minio-store-b |
| 300 | +``` |
0 commit comments