Senior LevelDocker & Deployment
How does Velero execute Kubernetes cluster backup and disaster recovery to cloud storage?
❓ Interview Prompt: Explain Velero backup architecture — API resource export, volume snapshot hooks, restore sequencing, and cross-cluster migration strategies.
Velero (formerly Ark) is a CNCF project for Kubernetes disaster recovery — backing up and restoring entire clusters or specific namespaces to cloud object storage.
What Velero Backs Up:
1
Kubernetes API Resources: All K8s objects (Deployments, Services, ConfigMaps, Secrets, CRDs) serialized to JSON/YAML and stored in a cloud bucket (S3, GCS, Azure Blob).
2
Persistent Volume Data: Volume snapshots via cloud provider CSI snapshot APIs (AWS EBS snapshots, GCP Persistent Disk snapshots) or file-level backup using restic/kopia agents.
Velero Architecture:
•
Backup Controller: Watches BackupStorageLocation CRD and executes backups.
•
Restore Controller: Reads backup from object storage and applies resources to cluster.
•
VolumeSnapshotLocation: Where to store cloud volume snapshots.
•
BackupStorageLocation: S3/GCS/Azure bucket for API resource backups.
Backup Hooks (Application Consistency):
For stateful apps (databases), Velero supports PreBackup and PostBackup hooks — run commands inside containers before/after snapshot to flush writes to disk (quiesce).
Use Cases:
•
Disaster Recovery: Restore cluster after accidental
kubectl delete or namespace deletion.•
Cluster Migration: Migrate workloads between cloud providers.
•
Environment Cloning: Copy production to staging for testing.
Code Implementation Example
bash
# Install Velero with AWS S3 storage
velero install \
--provider aws \
--plugins velero/velero-plugin-for-aws:v1.9.0 \
--bucket my-k8s-backups \
--backup-location-config region=us-east-1 \
--snapshot-location-config region=us-east-1 \
--secret-file ./credentials-velero
# Backup entire cluster (all namespaces)
velero backup create full-cluster-backup \
--include-namespaces='*' \
--include-cluster-resources=true \
--storage-location aws-s3
# Scheduled daily backup (2 AM UTC, 30-day retention)
velero schedule create daily-backup \
--schedule="0 2 * * *" \
--ttl 720h \
--include-namespaces production,staging
# Application-consistent PostgreSQL backup with hooks
velero backup create postgres-backup \
--include-namespaces database \
--default-volumes-to-fs-backup \
--pod-volume-backup-pod-annotations='
backup.velero.io/backup-volumes: pgdata,
pre.hook.backup.velero.io/command=["/bin/bash","-c","pg_dumpall > /backup/dump.sql"],
pre.hook.backup.velero.io/container=postgres'
# Restore from backup (to same or different cluster)
velero restore create --from-backup full-cluster-backup
# Restore only specific namespace
velero restore create --from-backup full-cluster-backup \
--include-namespaces production💡Velero: daily scheduled backup to S3, application-consistent DB backup with PreBackup hooks, restore specific namespace.
🎯 Interview Key Takeaway
Velero backs up K8s API resources to S3 and cloud volume snapshots. Use PreBackup hooks for database consistency (pg_dumpall). Schedule daily backups with 30-day retention for production clusters.
#Velero#Disaster Recovery#Backup#Kubernetes#S3#Senior
Back to all Docker & Deployment Questions→