This section will illustrate how to setup backup using Google Cloud Storage. To do so, you will need to have the gsutil installed to create the bucket on Google Cloud.
Create the bucket with following characteristics (that you may change):
gsutil mb \
-p my-project \
-b on \
-l us-west1 \
"gs://backup-demo-of-stackgres-io/"
To proceed, a Kubernetes Secret
with the folling shape needs to be created:
kubectl create namespace stackgres
kubectl create serviceaccount --namespace stackgres stackgres-demo-k8s-sa-user
gcloud iam service-accounts create stackgres-demo-k8s-sa-user --project my-project
## grant access to the bucket
gsutil iam ch \
serviceAccount:stackgres-demo-k8s-sa-user@my-project.iam.gserviceaccount.com:roles/storage.objectAdmin \
"gs://backup-demo-of-stackgres-io/"
gcloud iam service-accounts keys \
create my-creds.json --iam-account stackgres-demo-k8s-sa-user@my-project.iam.gserviceaccount.com
## create secret
kubectl --namespace stackgres create secret \
generic gcp-backup-bucket-secret \
--from-file="my-creds.json"
rm -rfv my-creds.json
Having the credentials secret created, we just need to create the object storage configuration and set the backup configuration. The object storage configuration it is governed by the CRD SGObjectStorage. This CRD allows to specify the object storage technology and parameters required and a reference to the above secret.
Create the file sgobjectstorage-backupconfig1.yaml
:
apiVersion: stackgres.io/v1beta1
kind: SGObjectStorage
metadata:
namespace: demo
name: backupconfig-gcp
spec:
type: "gcs"
gcs:
bucket: backup-demo-of-stackgres-io
gcpCredentials:
secretKeySelectors:
serviceAccountJSON:
name: gcp-backup-bucket-secret
key: my-creds.json
and deploy to Kubernetes:
kubectl apply -f sgobjectstorage-backupconfig1.yaml
The backup configuration can be set unser the section .spec.configurations.backups
of the CRD
SGCluster, among others, the retention window for the automated backups,
when base backups are performed and performance parameters of the backup process.
apiVersion: stackgres.io/v1
kind: SGCluster
spec:
configurations:
backups:
- sgObjectStorage: backupconfig1
cronSchedule: '*/5 * * * *'
retention: 6
Note that for this tutorial and demo purposes, backups are created every 5 minutes. Modify the
.spec.backups[0].cronSchedule
parameter above to adjust to your own needs.
The above configuration will be applied when creating the SGCluster resource.