Backup & Restore Kubernetes resources with VELERO

Firat Yasar
adessoTurkey
Published in
4 min readMar 13, 2022

Velero is an open-source tool to safely back up and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes. (Definition comes from Velero official site)

It’s easy to use and integration is so simple. You can manage backup&restore tasks with it easily and also it would be fit your BCDR needs.

Key objectives for Velero;

  • Velero extends Kubernetes APIs to manage backup & restore operations. Each operation is defined ad CRD in Kubernetes and stored in ETCD.
  • Velero also has controllers to perform backups, restores, and all other operations defined in CRD.
  • Velero can backup all objects in the cluster or you can filter objects by namespace, label, or type.
  • It would be useful to use Velero for disaster recovery scenarios. And also it’s ideal to use it for snapshotting your workload state. (for upgrade operations etc.)

After a short overview of Velero’s next move on to backup operations.

Backup Operations

  • It keeps Kubernetes objects backup in cloud-based storage as a tarball.
  • to create disk snapshots of persistent volumes it communicates with cloud provider API.

You can also configure backup hooks before or after backup operations. It would be great to have some jobs to prepare the database before or after backup operations. For example, you want to flush the database in memory buffers before backup operations. It would be useful for that kind of scenario.

Scheduled backup option?

Backup operations can be triggered with manual operations. But you may want to backup your data in scheduled recurring intervals. Velero allows you to schedule backup at any time. Backup intervals can be specified by Cron expression.

Restore Operations

With restore operations, you can restore objects and persistent volumes from backups. It also allows you to restore a specific subset of objects and persistent volumes.

By default Velero allows you to restore objects in different namespaces.

You can integrate restore hooks before or after restore operations. So maybe you want to restart the application containers that used the database after the restore operation.

After explaining some basic operations of Velero let’s dig into the backup workflow to understand the process of backup.

Backup workflow

Creating a backup file with velero, you can use this simple command to start the operation.

velero backup create test-backup

After this basic command the backup process continues with these steps:

  1. To start the backup process Velero client makes a call to the K8S API to create a backup object.
  2. The backup controller is aware of that and starts the validation process.
  3. After validation backup controller triggers the backup process. For object backup, it communicates K8S API server to collect data.
  4. It also communicates with the cloud storage service to upload the backup file.

You can see the detailed backup workflow in the picture below.

By default, “velero backup create” creates disk snapshots of persistent volumes.

You can adjust the snapshots by specifying additional flags.

to see available flags;

velero backup create — help

Snapshots can be disabled with the option below.

— snapshot-volumes=false

TTL for backup resources

You can specify TTL for your backup resources. You have to use — ttl <DURATION> flag with the backup command. If backup resource expired it removes,

  • The backup resource and backup file from cloud storage.
  • Persistent volumes and snapshots
  • All associated restores

The default TTL duration for the backup files is 30 days. You can update it with a custom TTL configuration. the value assigned as TTL can be specified in hours, minutes, and seconds. ( — ttl 24h0m0s)

What is the Object Storage Sync?

Velero accepts cloud storage as the source of truth. So the situation of Kubernetes should be the same with backup resources. It continuously checks the storage to realize that the correct backup file exists over there. If it doesn’t find the correct backup resource in the Kubernetes API, it syncs the data from storage to Kubernetes. It allows using the restore function in a cluster migration scenario. If the backup object exists on Kubernetes but not in cloud storage, it will be deleted from Kubernetes by Velero.

Conclusion

Velero is an open-source backup tool that allows to backup Kubernetes resources to the cloud storage. It also supports disaster recovery scenarios for Kubernetes resources.

It’s easy to use and deployment is not complex. It also provides advanced options like backup TTL and synchronization. If you have a plan to integrate backup&restore and disaster recovery capabilities for your Kubernetes cluster you should give it a chance to try it.

Source:

--

--

Firat Yasar
adessoTurkey

DevOps Lead at adesso Turkey CKA & CKAD & CKS Microsoft MVP