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 |
| Containerized Data Importer (CDI) | v1.62.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-openebsPluginEnsure that
kubectl-openebsplugin is installed. Refer to the Kubectl OpenEBS 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.
Backing Up a KubeVirt VM#
important
Snapshot creation is subject to Replicated PV Mayastor capacity and commitment limits. Refer Operational Considerations - Snapshot Capacity and Commitment Considerations for more information.
- Create a Velero backup object that includes the KubeVirt VM, CDI objects, and persistent volumes backed by OpenEBS.
- Check Backup Status.
Sample Output
- After the backup is completed, delete the original VM (
vm1) in the default namespace to demonstrate a successful restore.
Sample Output
- Delete the DataVolume.
Sample Output
note
When backing up a running virtual machine with the guest agent installed and the KubeVirt-Velero plugin enabled, Velero automatically executes backup hooks. These hooks freeze the guest file systems before the snapshot is taken and unfreeze them afterward, ensuring application-consistent snapshots. If the guest agent is not present, Velero performs a best-effort snapshot.
Restoring a KubeVirt VM#
- Create a new namespace to restore the virtual machine and associated resources.
- Create a Velero restore object.
- Check the
datadownloadstatus.
Sample Output
Once the restore completes, Velero recreates:
- The KubeVirt virtual machine (vm1)
- The associated DataVolume (fedora)
- All dependent Kubernetes resources
These resources are restored into the restoredvm namespace.
Verification of Restored Data#
After the restore operation completes, verify that both the virtual machine and its data have been successfully recovered.
- Connect to the restored virtual machine using the console.
- Navigate to the root user’s home directory.
- Verify the presence of the sample data that was created before the backup.
Sample Output
This verification confirms that:
- The virtual machine configuration was restored correctly.
- The persistent storage contents were fully preserved.
- The backup and restore workflow functions end-to-end as expected.
Validating restored data is a critical step, as it ensures that the Velero backup accurately captured the VM state along with its underlying persistent volumes.