Google Cloud Bucket Setup

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):

  • Project: my-project
  • Zone: us-west1
  • Bucket name: backup-demo-of-stackgres-io
gsutil mb \
    -p my-project \
    -b on \
    -l us-west1 \

Kubernetes Setup

To proceed, a Kubernetes Secret with the folling shape needs to be created:

  • Project: my-project
  • Zone: us-west1
  • Bucket name: backup-demo-of-stackgres-io
  • K8s Service Account: stackgres-demo-k8s-sa-user
  • K8s Bucket Secret Credentials: gcp-backup-bucket-secret
  • Cluster namespace: stackgres
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 \

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 \

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
  namespace: demo
  name: backupconfig-gcp
    cronSchedule: "*/5 * * * *"
    retention: 6
    type: "gcs"
      bucket: backup-demo-of-stackgres-io
            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.