How to use Velero for Kubernetes backups
This guide describes how to deploy Velero for Kubernetes and manage backups for Kubernetes-based applications on Virtuozzo Infrastructure.
About Velero
Velero is an open-source tool to backup and restore, perform disaster recovery, and migrate Kubernetes cluster resources and persistent volumes.
Velero lets you:
- Take backups of your cluster and restore in case of loss
- Migrate cluster resources to other clusters
- Replicate your production cluster to development and testing clusters
Velero consists of:
- A server that runs on your cluster
- A command-line client that runs locally
Prerequisites
1. Deploy a Virtuozzo Infrastructure cluster.
2. Create the compute cluster with the Kubernetes and load balancing services.
3. Configure a storage policy named standard for boot volumes on Kubernetes master nodes. Ensure that the selected policy is available for all projects where you are planning to deploy Kubernetes.
4. Create a Kubernetes cluster.
5. Ensure that you have the credentials (the access key and secret key) to the object storage service. In this guide, we will use the S3 object storage and a bucket provided by Virtuozzo Infrastructure.
6. Create a storage class with the snapshot functionality enabled:
6.1. Create the default storage class with the storage policy standard. The storage policy must be available in your project.
| |
Apply the configuration file:
| |
6.2. Install the required custom resource definitions (CRD) for volume snapshots:
6.2.1. Check the existing CRDs:
| |
6.2.2. Install the missing CRDs (install only one version):
| |
6.3. Create a snapshot class:
| |
Apply the configuration file:
| |
Installing Velero in a Kubernetes cluster
1. Download the required configuration files to your local machine:
| |
2. Install the Velero command-line client on your local machine.
3. Connect to the Kubernetes cluster:
| |
4. In the Velero configuration file velero.yaml, change the following parameters:
bucketto the name of your object storage buckets3Urlto the address of your object storage endpoint
5. In the object storage credentials file credentials-velero-example, change the following parameters:
aws_access_key_idto your S3 access keyaws_secret_access_keyto your S3 secret key
5. Add the repository where the Velero Helm chart is located:
| |
6. Install the chart from the added repository:
| |
7. Verify the Velero installation:
| |
The output shows that the backup and snapshot destinations (your S3 bucket) are properly configured.
Creating a test application
We will be using WordPress as a test application deployed using the Bitnami template:
| |
Check that you have the following components deployed:
| |
In the output, the EXTERNAL-IP of your wp-test-wordpress load balancer is the public IP address of your test WordPress instance that you can use to access the application.
Creating the first backup
To create a backup, run the following command:
| |
Where:
wp-test-b1is the name of your backup.--selector app.kubernetes.io/instance=wp-testspecifies the selector to identify Kubernetes entities for backup. All WordPress application components have theinstance=wp-testtag, so Velero will back up all of them, including persistent volumes.--snapshot-volumesspecifies the snapshot approach that will be used to back up your persistent volumes.--snapshot-move-dataspecifies that snapshots will be moved to your backup destination and not stored in the same Kubernetes cluster.
To check that the backup was successfully created and the snapshots were uploaded to S3, run:
| |
Additionally, go to your S3 bucket and verify that your file structure is as follows:

You can also check the backup task status by running:
| |
Phase should have the status Completed.
Restoring the application
To test the restore functionality, let’s destroy the WordPress application. To do this, you can delete the WordPress deployment:
| |
You can check that the WordPress application is no longer available by opening its public IP address in the browser.
You can also delete the WordPress persistent volume:
| |
To restore the application from the created backup, run:
| |
Where:
wp-test-restore1is the name of a restore taskwp-test-b1is the name of your backup
Open the WordPress public IP address in the browser, to verify that the WordPress application is available again.
Creating a backup schedule
For managing backup schedules, Velero uses cron. To learn more, refer to the Velero documentation.
To create backups every hour and send backup files, including snapshots, to your S3 storage, run:
| |
Creating a file system-based backup
Velero also supports file system backup. To learn more about this approach and how it is different from the snapshot-based backup, refer to the Velero documentation.
To create a file system backup, run:
| |
Enjoy!