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 now a backup configuration. It is governed by the CRD SGBackupConfig. This CRD allows to specify, among others, the retention window for the automated backups, when base backups are performed, performance parameters of the backup process, the object storage technology and parameters required and a reference to the above secret.
Create the file sgbackupconfig-backupconfig1.yaml
:
apiVersion: stackgres.io/v1
kind: SGBackupConfig
metadata:
namespace: demo
name: backupconfig-gcp
spec:
baseBackups:
cronSchedule: "*/5 * * * *"
retention: 6
storage:
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 sgbackupconfig-backupconfig1.yaml
Note that for this tutorial and demo purposes, backups are created every 5 minutes. Modify the
.spec.baseBackups.cronSchedule
parameter above to adjust to your own needs.