Skip to content

Commit 6622060

Browse files
author
Jonathan S. Katz
committed
Add custom resource example for pgBackRest repo in S3
This examples shows how one can create a new PostgreSQL cluster where the pgBackRest backups and archives exist in a S3 repository via creating a custom resource.
1 parent 14dc9c8 commit 6622060

File tree

1 file changed

+192
-0
lines changed

1 file changed

+192
-0
lines changed

docs/content/custom-resources/_index.md

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,198 @@ EOF
212212
kubectl apply -f "${pgo_cluster_name}-pgcluster.yaml"
213213
```
214214

215+
### Create a PostgreSQL Cluster With Backups in S3
216+
217+
A frequent use case is to create a PostgreSQL cluster with S3 or a S3-like
218+
storage system for storing backups. This requires adding a Secret that contains
219+
the S3 key and key secret for your account, and adding some additional
220+
information into the custom resource.
221+
222+
#### Step 1: Create the pgBackRest S3 Secrets
223+
224+
As mentioned above, it is necessary to create a Secret containing the S3 key and
225+
key secret that will allow a user to create backups in S3.
226+
227+
The below code will help you set up this Secret.
228+
229+
```
230+
# this variable is the name of the cluster being created
231+
pgo_cluster_name=hippo
232+
# this variable is the namespace the cluster is being deployed into
233+
cluster_namespace=pgo
234+
# the following variables are your S3 key and key secret
235+
backrest_s3_key=yours3key
236+
backrest_s3_key_secret=yours3keysecret
237+
238+
kubectl -n "${cluster_namespace}" create secret generic "${pgo_cluster_name}-backrest-repo-config" \
239+
--from-literal="aws-s3-key=${backrest_s3_key}" \
240+
--from-literal="aws-s3-key-secret=${backrest_s3_key_secret}"
241+
242+
unset backrest_s3_key
243+
unset backrest_s3_key_secret
244+
```
245+
246+
#### Step 2: Creating the PostgreSQL User Secrets
247+
248+
Similar to the basic create cluster example, there are a minimum of three
249+
PostgreSQL user accounts that you must create in order to bootstrap a PostgreSQL
250+
cluster. These are:
251+
252+
- A PostgreSQL superuser
253+
- A replication user
254+
- A standard PostgreSQL user
255+
256+
The below code will help you set up these Secrets.
257+
258+
```
259+
# this variable is the name of the cluster being created
260+
pgo_cluster_name=hippo
261+
# this variable is the namespace the cluster is being deployed into
262+
cluster_namespace=pgo
263+
264+
# this is the superuser secret
265+
kubectl create secret generic -n "${cluster_namespace}" "${pgo_cluster_name}-postgres-secret" \
266+
--from-literal=username=postgres \
267+
--from-literal=password=Supersecurepassword*
268+
269+
# this is the replication user secret
270+
kubectl create secret generic -n "${cluster_namespace}" "${pgo_cluster_name}-primaryuser-secret" \
271+
--from-literal=username=primaryuser \
272+
--from-literal=password=Anothersecurepassword*
273+
274+
# this is the standard user secret
275+
kubectl create secret generic -n "${cluster_namespace}" "${pgo_cluster_name}-hippo-secret" \
276+
--from-literal=username=hippo \
277+
--from-literal=password=Moresecurepassword*
278+
279+
280+
kubectl label secrets -n "${cluster_namespace}" "${pgo_cluster_name}-postgres-secret" "pg-cluster=${pgo_cluster_name}"
281+
kubectl label secrets -n "${cluster_namespace}" "${pgo_cluster_name}-primaryuser-secret" "pg-cluster=${pgo_cluster_name}"
282+
kubectl label secrets -n "${cluster_namespace}" "${pgo_cluster_name}-hippo-secret" "pg-cluster=${pgo_cluster_name}"
283+
```
284+
285+
#### Step 3: Create the PostgreSQL Cluster
286+
287+
With the Secrets in place. It is now time to create the PostgreSQL cluster.
288+
289+
The below manifest references the Secrets created in the previous step to add a
290+
custom resource to the `pgclusters.crunchydata.com` custom resource definition.
291+
There are some additions in this example specifically for storing backups in S3.
292+
293+
```
294+
# this variable is the name of the cluster being created
295+
export pgo_cluster_name=hippo
296+
# this variable is the namespace the cluster is being deployed into
297+
export cluster_namespace=pgo
298+
# the following variables store the information for your S3 cluster. You may
299+
# need to adjust them for your actual settings
300+
export backrest_s3_bucket=your-bucket
301+
export backrest_s3_endpoint=s3.region-name.amazonaws.com
302+
export backrest_s3_region=region-name
303+
304+
cat <<-EOF > "${pgo_cluster_name}-pgcluster.yaml"
305+
apiVersion: crunchydata.com/v1
306+
kind: Pgcluster
307+
metadata:
308+
annotations:
309+
current-primary: ${pgo_cluster_name}
310+
labels:
311+
autofail: "true"
312+
backrest-storage-type: "s3"
313+
crunchy-pgbadger: "false"
314+
crunchy-pgha-scope: ${pgo_cluster_name}
315+
crunchy-postgres-exporter: "false"
316+
deployment-name: ${pgo_cluster_name}
317+
name: ${pgo_cluster_name}
318+
pg-cluster: ${pgo_cluster_name}
319+
pg-pod-anti-affinity: ""
320+
pgo-backrest: "true"
321+
pgo-version: {{< param operatorVersion >}}
322+
pgouser: admin
323+
name: ${pgo_cluster_name}
324+
namespace: ${cluster_namespace}
325+
spec:
326+
BackrestStorage:
327+
accessmode: ReadWriteMany
328+
matchLabels: ""
329+
name: ""
330+
size: 1G
331+
storageclass: ""
332+
storagetype: dynamic
333+
supplementalgroups: ""
334+
PrimaryStorage:
335+
accessmode: ReadWriteMany
336+
matchLabels: ""
337+
name: ${pgo_cluster_name}
338+
size: 1G
339+
storageclass: ""
340+
storagetype: dynamic
341+
supplementalgroups: ""
342+
ReplicaStorage:
343+
accessmode: ReadWriteMany
344+
matchLabels: ""
345+
name: ""
346+
size: 1G
347+
storageclass: ""
348+
storagetype: dynamic
349+
supplementalgroups: ""
350+
annotations:
351+
backrestLimits: {}
352+
backrestRepoPath: ""
353+
backrestResources:
354+
memory: 48Mi
355+
backrestS3Bucket: ${backrest_s3_bucket}
356+
backrestS3Endpoint: ${backrest_s3_endpoint}
357+
backrestS3Region: ${backrest_s3_region}
358+
backrestS3URIStyle: ""
359+
backrestS3VerifyTLS: ""
360+
ccpimage: crunchy-postgres-ha
361+
ccpimageprefix: registry.developers.crunchydata.com/crunchydata
362+
ccpimagetag: {{< param centosBase >}}-{{< param postgresVersion >}}-{{< param operatorVersion >}}
363+
clustername: ${pgo_cluster_name}
364+
customconfig: ""
365+
database: ${pgo_cluster_name}
366+
exporterport: "9187"
367+
limits: {}
368+
name: ${pgo_cluster_name}
369+
namespace: ${cluster_namespace}
370+
pgBouncer:
371+
limits: {}
372+
replicas: 0
373+
pgDataSource:
374+
restoreFrom: ""
375+
restoreOpts: ""
376+
pgbadgerport: "10000"
377+
pgoimageprefix: registry.developers.crunchydata.com/crunchydata
378+
podAntiAffinity:
379+
default: preferred
380+
pgBackRest: preferred
381+
pgBouncer: preferred
382+
policies: ""
383+
port: "5432"
384+
primarysecretname: ${pgo_cluster_name}-primaryuser-secret
385+
replicas: "0"
386+
rootsecretname: ${pgo_cluster_name}-postgres-secret
387+
shutdown: false
388+
standby: false
389+
tablespaceMounts: {}
390+
tls:
391+
caSecret: ""
392+
replicationTLSSecret: ""
393+
tlsSecret: ""
394+
tlsOnly: false
395+
user: hippo
396+
userlabels:
397+
backrest-storage-type: "s3"
398+
crunchy-postgres-exporter: "false"
399+
pg-pod-anti-affinity: ""
400+
pgo-version: {{< param operatorVersion >}}
401+
usersecretname: ${pgo_cluster_name}-hippo-secret
402+
EOF
403+
404+
kubectl apply -f "${pgo_cluster_name}-pgcluster.yaml"
405+
```
406+
215407
### Modify a Cluster
216408

217409
There following modification operations are supported on the

0 commit comments

Comments
 (0)