Automated CloudNative-PG backup configuration deployment for Kubernetes clusters.
This repository contains GitHub Actions workflows to automatically configure PostgreSQL backups using CloudNative-PG operator across all notebook-link Kubernetes environments. It follows the same deployment pattern as Grafana Alloy, deploying to one environment at a time.
- Auto-discovery: Automatically finds all PostgreSQL clusters in each environment
- S3 Backup: Configures backups to environment-specific Scaleway S3 buckets
- WAL Archiving: Continuous archiving of Write-Ahead Logs for point-in-time recovery
- Scheduled Backups: Daily backups at 2 AM UTC
- Environment Isolation: Each environment has its own S3 bucket and credentials
dev → qa → prod
Use the GitHub Actions UI to trigger deployment to specific environments:
- test
- infra
Each environment has its own S3 bucket:
notebook-link-cnpg-backups-dev
notebook-link-cnpg-backups-qa
notebook-link-cnpg-backups-prod
notebook-link-cnpg-backups-test
notebook-link-cnpg-backups-infra
Within each bucket, backups are organized by namespace:
notebook-link-cnpg-backups-{env}/
└── {namespace}/
├── base/ # Full backups
└── wal/ # WAL archives
-
Infrastructure Setup (managed by notebook-link-infra):
- Creates S3 buckets for each environment
- Generates IAM credentials with access to the bucket
- Stores credentials in Scaleway Secret Manager
-
Deployment (this repository):
- Connects to the environment's Kubernetes cluster
- Discovers all CloudNative-PG clusters
- For each cluster:
- Creates S3 credentials secret in the namespace
- Patches the cluster to add backup configuration
- Creates a scheduled backup resource
-
Backup Configuration Applied:
spec: backup: barmanObjectStore: destinationPath: s3://notebook-link-cnpg-backups-{env}/{namespace} endpointURL: https://s3.fr-par.scw.cloud wal: retention: "7d"
After deployment, verify backups are configured:
# Connect to cluster
scw k8s kubeconfig install {cluster-id}
# Check scheduled backups
kubectl get scheduledbackups.postgresql.cnpg.io --all-namespaces
# Check backup status
kubectl get backups.postgresql.cnpg.io --all-namespaces
# View S3 bucket contents
scw object bucket list
To restore a PostgreSQL cluster from backup:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: restored-cluster
namespace: target-namespace
spec:
instances: 3
bootstrap:
recovery:
source: s3-backup
externalClusters:
- name: s3-backup
barmanObjectStore:
destinationPath: s3://notebook-link-cnpg-backups-{env}/{namespace}
endpointURL: https://s3.fr-par.scw.cloud
s3Credentials:
accessKeyId:
name: cnpg-s3-credentials
key: ACCESS_KEY
secretAccessKey:
name: cnpg-s3-credentials
key: SECRET_KEY
Each environment's configuration is managed through GitHub environment secrets:
TF_MANAGED_K8S_API_SERVER_URL
: Kubernetes API server URLTF_MANAGED_K8S_CA_CERT
: Kubernetes CA certificateTF_MANAGED_K8S_SA_TOKEN
: Service account tokenTF_MANAGED_SCALEWAY_APP_ACCESS_KEY
: Scaleway access keyTF_MANAGED_SCALEWAY_APP_SECRET_KEY
: Scaleway secret keyTF_MANAGED_SCALEWAY_PROJECT_ID
: Scaleway project IDTF_MANAGED_SCALEWAY_ORG_ID
: Scaleway organization ID
These secrets are automatically configured by the notebook-link-infra repository.
- notebook-link-infra: Infrastructure configuration
- notebook-link-grafana-alloy: Similar deployment pattern for observability
- notebook-link-supabase: Contains the PostgreSQL clusters being backed up
For issues or questions, please open an issue in this repository.