Skip to main content
Cluster operationsLesson 12 of 16

Backing Up and Restoring a Cluster

A cluster keeps state in several places, and each place needs its own backup. Follow an etcd snapshot and a Velero backup from the source cluster to object storage, and back into a new cluster.

API objectsetcd
Volume dataPV disks
Consistency—
Restore—
Cluster A · sourceCluster B · restoreetcdAPI objectsAPI serverReads and writes etcdVeleroBackup controllerPodpostgresPVDisk with datanode-agentFile copyObject storageBackup bucketVolume snapshotCSI snapshotetcd snapshotsnapshot.dbVeleroSame bucketRestored appObjects + PVCGit repoManifestsOutside stateCloud DB · DNS · vault
RequestResponse / reportAppears in a later step

What you will learn

  • Three kinds of state: API objects, volume data, outside systems
  • What an etcd snapshot restores, and what it rewinds
  • How Velero backs up objects and volumes to object storage
  • Crash-consistent versus app-consistent backups with hooks
  • Restoring into another cluster, and why restores must be tested

What each method covers​

MethodAPI objectsVolume dataScopeGood for
etcd snapshotAll, at one momentNoWhole clusterLosing the control plane
Velero (objects only)Selected namespaces or labelsNoNamespace, labelDeleted resources, migration
Velero + CSI snapshotsYesYes, in the same storage systemNamespaceFast restore in the same region
Velero + data mover or File System BackupYesYes, copied to the bucketNamespaceRestore in another region or cluster
Database dump or replicationNoThe database only, consistentOne databaseDatabases, point-in-time recovery
Git (GitOps)Manifests you wroteNoWhatever is in the repoRebuilding config, not data

Try it yourself​

# etcd snapshot (kubeadm paths; run on a control plane node)
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
snapshot save /backup/snapshot.db
etcdutl --write-out=table snapshot status /backup/snapshot.db # Hash, revision, keys, size

# Velero
velero backup create shop-test --include-namespaces shop --wait
velero backup describe shop-test --details # Objects, volume snapshots, warnings
velero backup logs shop-test | grep -i error
velero restore create --from-backup shop-test --namespace-mappings shop:shop-restore-test # Restore beside the original
velero restore describe <restore-name> # Skipped and failed items

Check yourself

  1. Someone deleted one Deployment in the shop namespace. Why is an etcd snapshot restore the wrong tool?
  2. After restoring an etcd snapshot, the database PVC and PV objects are back but the database is empty. What is most likely?
  3. You back up with Velero and CSI snapshots only. The whole storage system in that region fails. What happens?

Further reading: Operating etcd clusters: backup and restore · etcd disaster recovery · Velero docs · Velero backup hooks · Velero File System Backup · Control Plane HA and etcd Quorum · Multi-region disaster recovery · How Object Storage Works