Skip to content

Commit b7daaac

Browse files
docs: provide usage instructions (#89)
Update the `README` file with usage instructions. Signed-off-by: Leonardo Cecchi <[email protected]> Signed-off-by: Gabriele Bartolini <[email protected]> Co-authored-by: Gabriele Bartolini <[email protected]>
1 parent 2a413c7 commit b7daaac

File tree

4 files changed

+388
-7
lines changed

4 files changed

+388
-7
lines changed

.wordlist.txt

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,59 @@
1-
cnpg
1+
Azurite
2+
BarmanObjectStore
3+
BarmanObjectStores
24
CloudNativePG
5+
Gi
6+
IfNotPresent
7+
MinIO
8+
PITR
39
TODO
10+
TLS
11+
WAL
12+
WALs
13+
api
14+
apiVersion
15+
apiextensions
16+
auth
17+
backends
18+
barmanObjectName
19+
barmancloud
20+
cd
21+
cloudnative
22+
clusterrole
23+
clusterrolebinding
24+
cmctl
25+
cnpg
26+
codebase
27+
csi
28+
customresourcedefinition
29+
externalClusters
30+
gcs
31+
gf
32+
github
33+
hostpath
34+
https
35+
imagePullPolicy
36+
io
37+
kubectl
38+
kubernetes
39+
minio
40+
namespace
41+
namespaces
42+
objectstore
43+
objectstores
44+
pluginConfiguration
45+
postgresql
46+
primaryUpdateStrategy
47+
rbac
48+
rc
49+
repos
50+
rolebinding
51+
sc
52+
selfsigned
53+
serverName
54+
serviceaccount
55+
storageClass
56+
tfddg
57+
tgz
58+
xvzf
59+
yaml

README.md

Lines changed: 326 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,330 @@
11
[![CloudNativePG](./logo/cloudnativepg.png)](https://cloudnative-pg.io/)
22

3-
# New Component for CloudNativePG
3+
# Barman Cloud CNPG-I plugin
44

5-
TODO
5+
Welcome to the codebase of the [barman-cloud](https://pgbarman.org/) CNPG-I
6+
plugin for [CloudNativePG](https://cloudnative-pg.io/).
67

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 enables continuous backup to object storage for a PostgreSQL
22+
cluster using the [barman-cloud](https://pgbarman.org/) tool suite.
23+
24+
The features provided by this plugin are:
25+
26+
- Data Directory Backup
27+
- Data Directory Restore
28+
- WAL Archiving
29+
- WAL Restoring
30+
- Point-in-Time Recovery (PITR)
31+
- Replica Clusters
32+
33+
This plugin is compatible with all object storage services supported by
34+
barman-cloud, including:
35+
36+
- Amazon AWS S3
37+
- Google Cloud Storage
38+
- Microsoft Azure Blob Storage
39+
40+
The following storage solutions have been tested and confirmed to work with
41+
this implementation:
42+
43+
- [MinIO](https://min.io/) – An S3-compatible object storage solution.
44+
- [Azurite](https://github.com/Azure/Azurite) – A simulator for Microsoft Azure Blob Storage.
45+
- [fake-gcs-server](https://github.com/fsouza/fake-gcs-server) – A simulator for Google Cloud Storage.
46+
47+
Backups created with in-tree object store support can be restored using this
48+
plugin, ensuring compatibility and reliability across environments.
49+
50+
## Prerequisites
51+
52+
To use this plugin, ensure the following prerequisites are met:
53+
54+
- [**CloudNativePG**](https://cloudnative-pg.io) version **1.25** or newer.
55+
- [**cert-manager**](https://cert-manager.io/) for enabling **TLS communication** between the plugin and the operator.
56+
57+
## Installation
58+
59+
**IMPORTANT NOTES:**
60+
61+
1. The plugin **must** be installed in the same namespace where the operator is
62+
installed (typically `cnpg-system`).
63+
64+
2. Be aware that the operator's **listening namespaces** may differ from its
65+
installation namespace. Ensure you verify this distinction to avoid
66+
configuration issues.
67+
68+
Here’s an enhanced version of your instructions for verifying the prerequisites:
69+
70+
### Step 1 - Verify the Prerequisites
71+
72+
If CloudNativePG is installed in the default `cnpg-system` namespace, verify its version using the following command:
73+
74+
```sh
75+
kubectl get deployment -n cnpg-system cnpg-controller-manager \
76+
| grep ghcr.io/cloudnative-pg/cloudnative-pg
77+
```
78+
79+
Example output:
80+
81+
```output
82+
image: ghcr.io/cloudnative-pg/cloudnative-pg:1.25.0-rc1
83+
```
84+
85+
Ensure that the version displayed is **1.25** or newer.
86+
87+
Then, use the [cmctl](https://cert-manager.io/v1.6-docs/usage/cmctl/#installation)
88+
tool to confirm that `cert-manager` is correctly installed:
89+
90+
```sh
91+
cmctl check api
92+
```
93+
94+
Example output:
95+
96+
```output
97+
The cert-manager API is ready
98+
```
99+
100+
Both checks are necessary to proceed with the installation.
101+
102+
### Step 2 - Install the barman-cloud Plugin
103+
104+
Use `kubectl` to apply the manifest for the latest commit in the `main` branch:
105+
106+
```sh
107+
kubectl apply -f \
108+
https://raw.githubusercontent.com/cloudnative-pg/plugin-barman-cloud/refs/heads/main/manifest.yaml
109+
```
110+
111+
Example output:
112+
113+
```output
114+
customresourcedefinition.apiextensions.k8s.io/objectstores.barmancloud.cnpg.io created
115+
serviceaccount/plugin-barman-cloud created
116+
role.rbac.authorization.k8s.io/leader-election-role created
117+
clusterrole.rbac.authorization.k8s.io/metrics-auth-role created
118+
clusterrole.rbac.authorization.k8s.io/metrics-reader created
119+
clusterrole.rbac.authorization.k8s.io/objectstore-editor-role created
120+
clusterrole.rbac.authorization.k8s.io/objectstore-viewer-role created
121+
clusterrole.rbac.authorization.k8s.io/plugin-barman-cloud created
122+
rolebinding.rbac.authorization.k8s.io/leader-election-rolebinding created
123+
clusterrolebinding.rbac.authorization.k8s.io/metrics-auth-rolebinding created
124+
clusterrolebinding.rbac.authorization.k8s.io/plugin-barman-cloud-binding created
125+
secret/plugin-barman-cloud-8tfddg42gf created
126+
service/barman-cloud created
127+
deployment.apps/barman-cloud configured
128+
certificate.cert-manager.io/barman-cloud-client created
129+
certificate.cert-manager.io/barman-cloud-server created
130+
issuer.cert-manager.io/selfsigned-issuer created
131+
```
132+
133+
After these steps, the plugin will be successfully installed. Make sure it is
134+
ready to use by checking the deployment status as follows:
135+
136+
```sh
137+
kubectl rollout status deployment \
138+
-n cnpg-system barman-cloud
139+
```
140+
141+
Example output:
142+
143+
```output
144+
deployment "barman-cloud" successfully rolled out
145+
```
146+
147+
This confirms that the plugin is deployed and operational.
148+
149+
## Usage
150+
151+
### Defining the `BarmanObjectStore`
152+
153+
A `BarmanObjectStore` object should be created for each object store used in
154+
your PostgreSQL architecture. Below is an example configuration for using
155+
MinIO:
156+
157+
```yaml
158+
apiVersion: barmancloud.cnpg.io/v1
159+
kind: ObjectStore
160+
metadata:
161+
name: minio-store
162+
spec:
163+
configuration:
164+
destinationPath: s3://backups/
165+
endpointURL: http://minio:9000
166+
s3Credentials:
167+
accessKeyId:
168+
name: minio
169+
key: ACCESS_KEY_ID
170+
secretAccessKey:
171+
name: minio
172+
key: ACCESS_SECRET_KEY
173+
wal:
174+
compression: gzip
175+
```
176+
177+
The `.spec.configuration` API follows the same schema as the
178+
[in-tree barman-cloud support](https://pkg.go.dev/github.com/cloudnative-pg/barman-cloud/pkg/api#BarmanObjectStoreConfiguration).
179+
Refer to [the CloudNativePG documentation](https://cloudnative-pg.io/documentation/preview/backup_barmanobjectstore/)
180+
for detailed usage.
181+
182+
### Configuring WAL Archiving
183+
184+
Once the `BarmanObjectStore` is defined, you can configure a PostgreSQL cluster
185+
to archive WALs by referencing the store in the `.spec.plugins` section, as
186+
shown below:
187+
188+
```yaml
189+
apiVersion: postgresql.cnpg.io/v1
190+
kind: Cluster
191+
metadata:
192+
name: cluster-example
193+
spec:
194+
instances: 3
195+
imagePullPolicy: Always
196+
plugins:
197+
- name: barman-cloud.cloudnative-pg.io
198+
parameters:
199+
barmanObjectName: minio-store
200+
storage:
201+
size: 1Gi
202+
```
203+
204+
This configuration enables both WAL archiving and data directory backups.
205+
206+
### Performing a Base Backup
207+
208+
Once WAL archiving is enabled, the cluster is ready for backups. To create a
209+
backup, configure the `backup.spec.pluginConfiguration` section to specify this
210+
plugin:
211+
212+
```yaml
213+
apiVersion: postgresql.cnpg.io/v1
214+
kind: Backup
215+
metadata:
216+
name: backup-example
217+
spec:
218+
method: plugin
219+
cluster:
220+
name: cluster-example
221+
pluginConfiguration:
222+
name: barman-cloud.cloudnative-pg.io
223+
```
224+
225+
### Restoring a Cluster
226+
227+
To restore a cluster from an object store, create a new `Cluster` resource that
228+
references the store containing the backup. Below is an example configuration:
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+
bootstrap:
239+
recovery:
240+
source: source
241+
externalClusters:
242+
- name: source
243+
plugin:
244+
name: barman-cloud.cloudnative-pg.io
245+
parameters:
246+
barmanObjectName: minio-store
247+
serverName: cluster-example
248+
storage:
249+
size: 1Gi
250+
```
251+
252+
**NOTE:** The above configuration does **not** enable WAL archiving for the
253+
restored cluster.
254+
255+
To enable WAL archiving for the restored cluster, include the `.spec.plugins`
256+
section alongside the `externalClusters.plugin` section, as shown below:
257+
258+
```yaml
259+
apiVersion: postgresql.cnpg.io/v1
260+
kind: Cluster
261+
metadata:
262+
name: cluster-restore
263+
spec:
264+
instances: 3
265+
imagePullPolicy: IfNotPresent
266+
bootstrap:
267+
recovery:
268+
source: source
269+
plugins:
270+
- name: barman-cloud.cloudnative-pg.io
271+
parameters:
272+
# Backup Object Store (push, read-write)
273+
barmanObjectName: minio-store-bis
274+
externalClusters:
275+
- name: source
276+
plugin:
277+
name: barman-cloud.cloudnative-pg.io
278+
parameters:
279+
# Recovery Object Store (pull, read-only)
280+
barmanObjectName: minio-store
281+
serverName: cluster-example
282+
storage:
283+
size: 1Gi
284+
```
285+
286+
The same object store may be used for both transaction log archiving and
287+
restoring a cluster, or you can configure separate stores for these purposes.
288+
289+
### Configuring Replica Clusters
290+
291+
You can set up a distributed topology by combining the previously defined
292+
configurations with the `.spec.replica` section. Below is an example of how to
293+
define a replica cluster:
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

Comments
 (0)