KubeVirt VM Live Migration with Replicated PV Mayastor and NFS
#
OverviewAs 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.
#
EnvironmentComponent | Version |
---|---|
KubeVirt | v1.5.0 |
Kubernetes (3 nodes) | v1.29.6 |
OpenEBS | v4.2.0 |
Velero | v1.15.2 |
Containerized Data Importer (CDI) | v1.62.0 |
kubectl-mayastor Plugin | v2.7.4+0 |
virtctl | v1.5.0 |
#
Prerequisites#
Setup OpenEBSInstall OpenEBS
Ensure that OpenEBS is installed in your cluster. Refer to the OpenEBS Installation Documentation for step-by-step instructions.
Install the
kubectl-mayastor
PluginEnsure that
kubectl-mayastor
plugin is installed. Refer to the Mayastor Kubectl Plugin Documentation to install the plugin.Create StorageClass for NFS Pod (3 Replicas)
- Create a file named
StorageClass.yaml
.
StorageClass.yaml
- Apply the configuration.
- Create StorageClass for Scratch Space (1 Replica)
- Create a file named
StorageClass2.yaml
.
StorageClass2.yaml
- Apply the configuration.
- Setup VolumeSnapshotClass
- Create a file named
VolumeSnapshotClass.yaml
.
VolumeSnapshotClass.yaml
- Apply the configuration.
#
Deploying an NFS Server Pod- Create a Namespace.
- Create PersistentVolumeClaim (PVC) for NFS Storage.
nfspvc.yaml
- Deploy NFS Server Pod.
nfs-server-deployment.yaml
- Apply the configuration.
- Create NFS Service.
nfs-server-service.yaml
- Apply the configuration.
#
Deploy NFS CSI Driver and StorageClass- Create Namespace.
- Create Helm Values for StorageClass.
values.yaml
- Install Using Helm.
#
KubeVirt Setup- Install KubeVirt Operator.
Sample Output
- Create KubeVirt Custom Resource.
Sample Output
- Patch to Use Emulation (Optional).
note
To perform operations such as accessing the VM console or triggering live migration, you must install the virtctl
CLI tool. Refer to the Official KubeVirt Documentation
- Verify KubeVirt Installation.
Sample Output
#
CDI Setup- Install CDI Operator and Custom Resource.
Sample Output
- 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 with NFS Storage- Create DataVolume
- Create a file named
dv.yaml
.
dv.yaml
- Apply the Configuration.
note
You will see two Scratch PVC being created as NFS Provisioner also creates a scratch PVC before provisioning the orignal KubeVirt Scratch PVC.
- Create a Virtual Machine
- Create a file named
vm1_pvc.yaml
to use the PVC prepared by DataVolume as a root disk.
vm1_pvc.yaml
- Apply the configuration.
- Connect to the VM Console.
- Login credentials:
Username:
root
Password:MySecurePassword123
- Install Guest Agent.
Check Agent Status
#
Enable Live Migration#
Validate Live Migration- Insert Sample Data into VM.
Use the VM console to create test files.
- Verify VM Node Location.
- Trigger Live Migration.
- Monitor Migration Progress.
Sample Output
- Verify Post-Migration State.
Ensure the VM is running on a new node and that all previously created data remains intact.