KubeVirt VM Backup and Restore using Replicated PV Mayastor VolumeSnapshots and Velero - FileSystem
Overview#
As Kubernetes continues to gain traction in enterprise environments, there is a growing need to support traditional workloads like virtual machines (VMs) alongside containerized applications. KubeVirt extends Kubernetes by enabling the deployment and management of VMs within a Kubernetes-native ecosystem.
To protect KubeVirt-based VMs, a robust backup strategy is essential. This document outlines a step-by-step method to back up KubeVirt virtual machines using Velero, a popular backup and disaster recovery tool for Kubernetes, in combination with Replicated PV Mayastor VolumeSnapshots. This approach provides consistent, point-in-time VM backups that are fully integrated with Kubernetes storage primitives and cloud-native workflows.
Environment#
| Component | Version | 
|---|---|
| KubeVirt | v1.5.0 | 
| Kubernetes (3 nodes) | v1.29.6 | 
| OpenEBS | v4.2.0 | 
| NFS CSI Driver | v4.11.0 | 
| Containerized Data Importer (CDI) | v1.62.0 | 
| kubectl-mayastor Plugin | v2.7.4+0 | 
| virtctl | v1.5.0 | 
Prerequisites#
Setup OpenEBS#
Install OpenEBS
Ensure that OpenEBS is installed in your cluster. Refer to the OpenEBS Installation Documentation for step-by-step instructions.
Install the
kubectl-mayastorPluginEnsure that
kubectl-mayastorplugin is installed. Refer to the Mayastor Kubectl Plugin Documentation to install the plugin.Create a StorageClass
- Create a file named 
StorageClass.yaml. 
StorageClass.yaml
- Apply the configuration.
 
Create a VolumeSnapshotClass#
- Create a file named 
VolumeSnapshotClass.yaml. 
- Apply the configuration.
 
KubeVirt Setup#
- Install KubeVirt Operator.
 
Sample Output
- Create KubeVirt Custom Resource.
 
Sample Output
- Patch to Use Emulation (Optional).
 
- Verify KubeVirt Installation.
 
Sample Output
CDI Setup#
- Install CDI Operator and Custom Resource.
 
Sample Output - CDI
Sample Output - CR
- Configure Scratch Space StorageClass.
 
Add the following under spec.config:
important
CDI always requests scratch space with a Filesystem volume mode regardless of the volume mode of the related DataVolume. It also always requests it with a ReadWriteOnce accessMode. Therefore, when using block mode DataVolumes, you must ensure that a storage class capable of provisioning Filesystem mode PVCs with ReadWriteOnce accessMode is configured.
- Verify CDI Installation.
 
Sample Output
Deploying a Virtual Machine#
- Create DataVolume
 
- Create a file named 
dv.yaml. 
dv.yaml
- Apply the Configuration.
 
- Monitor the Import.
 
- Create a Virtual Machine
 
- Create a file named 
vm1_pvc.yamlto use the PVC prepared by DataVolume as a root disk. 
vm1_pvc.yaml
- Apply the configuration.
 
- Connect to the VM Console.
 
- Login credentials:
Username: 
rootPassword:MySecurePassword123 
- Install Guest Agent.
 
Check Agent Status
- Insert Sample Data: Connect to the VM and create sample files in the root user home directory for backup verification.
 
Velero Setup#
- Configuring an AWS S3 Bucket for Velero Backup-Location
 
Configure AWS CLI (Optionally you can use the AWS GUI). Refer to the AWS CLI Setup Guide for setting up AWS CLI.
Create an AWS S3 Bucket.
- Create Velero User.
 
- Create an IAM policy with appropriate permissions.
 
- Assign the IAM policy to velero user.
 
- Generate Access Keys.
 
Sample Output
- Install Velero Utility
 
Install the Velero utility with Homebrew.
- Install Velero
 
- Create 
credentials-velerofile with the access key and secret access key. 
- Install Velero.
 
- Verify the Installation.
 
Command
Sample Output
- Check Velero backup storage location details.
 
Command
Sample Output
- Add KubeVirt-Velero Plugin
 
The KubeVirt-Velero plugin automates reliable backups of KubeVirt and CDI objects.
- Add the plugin.
 
- Verify the plugin installation.