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