How to backup Kubernetes persistent data?
· Category: Kubernetes
Short answer
Backup Kubernetes persistent data using volume snapshots, application-level backups, or tools like Velero. Velero backs up cluster resources and persistent volumes to object storage.
Steps
- Use CSI snapshots if your storage driver supports them.
- Install Velero with a cloud object storage backend.
- Schedule regular backups.
- Test restores periodically.
Example
velero backup create my-backup --selector app=database
velero backup get
velero restore create --from-backup my-backup
CSI snapshot:
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: db-snapshot
spec:
volumeSnapshotClassName: csi-snapclass
source:
persistentVolumeClaimName: db-pvc
Tips
- Back up both cluster state and persistent data.
- Store backups in a different region for disaster recovery.
- Automate backup testing with restore drills.
Common issues
- Not all storage drivers support snapshots.
- Inconsistent backups can occur if applications do not quiesce writes.
- Velero requires proper RBAC and cloud credentials.