Using Velero to back up and restore Kubernetes cluster resources

2 minute read

Velero is an open source tool that can be used with CloudBees CI on modern cloud platforms to back up and restore Kubernetes cluster resources.

Using Velero for backup and restore is optional. The information provided on this page provides tips for using Velero with CloudBees CI on modern cloud platforms, but does not replace Velero’s documentation.

Use the OSS inject-metadata-velero-plugin to automatically set the RESTORED_FROM_BACKUP environment variable during a restore operation.

For information on restarting builds after a restore, refer to Restarting builds after a restore.

Installing Velero

Follow the Velero installation guide to install the Velero CLI on a machine that has access to the Kubernetes cluster.

Follow the setup instructions for your storage provider to install the cluster components for Velero. Although Velero can be installed without a storage plugin, it cannot back up CloudBees CI on modern cloud platforms until the storage is integrated.

Recommendations for using Velero

Keep the following recommendations in mind while working with Velero:

  • When creating a backup and a schedule, include --snapshot-volumes.

  • For backing up the cluster-scoped resources, use --include-cluster-resources.

  • When creating a restore, use --restore-volumes.

  • During a restore, resources that already exist are not overwritten, so you can’t restore into a Kubernetes cluster on which CloudBees CI is already installed. You must restore into an empty cluster.

  • For Velero version 1.5, restores must be performed in the same availability zone and region in which the backup was created.

Example backup and restore commands for Velero

The following examples show how the CloudBees CI on modern cloud platforms engineering team uses Velero. These are for example purposes only and may need to be adjusted to fit your environment. CloudBees does not guarantee that these examples will work for your environment. Refer to the Velero documentation for specific instructions.

Backup schedule example

velero schedule create daily --schedule=”@every 24h” --snapshot-volumes --include-cluster-resources

The default time-to-live of 720 hours was used. CloudBees CI on modern cloud platforms backups typically have between 1800 and 2000 objects and take approximately 2 minutes to complete.

One-time backup and restore example

velero schedule create cluster-backup --snapshot-volumes --include-cluster-resources

velero restore create --from-backup cluster-backup-<timestamp> --restore-volumes

Testing a backup and restore of a single controller in GKE with a 100GB PVC that had 51GB used, the backups consistently took 7-8 seconds and the restore completed in under 1 minute.