This repository contains a Velero plugin. Thanks to the plugin, Velero can correctly backup and restore VirtualMachines, DataVolumes and other resources managed by KubeVirt and CDI.
For more information on Velero check https://velero.io/.
The plugin registers backup and restore actions that operate on following resources: DataVolume, PersistentVolumeClaim, Pod, VirtualMachine, VirtualMachineInstance.
An action that backs up the PersistentVolumeClaim and DataVolume
Finds the PVC for DV and adds the "cdi.kubevirt.io/storage.prePopulated" or "cdi.kubevirt.io/storage.populatedFor" annotations
An action that backs up the VirtualMachine
It checks if a VM can be safely backed up and if the backup contains all required objects for the successful restore.
The action also makes sure that every object in the vm and VMI graph will be added the the backup, for example: instancetype, different types of volumes, access credentials, etc..
It also returns the underlying DataVolume if a VM has DataVolumeTemplate and virtualmachineinstances as extra items to back up.
Note: any cluster scoped objects and network objects and configurations are not backed up and they should be available when restoring the VM.
An action that backs up the VirtualMachineInstance
It checks if a VMI can be safely backed up and if the backup contains all required objects for the successful restore.
The action also returns the underlying VM volumes (DataVolume and PersistentVolumeClaim) and launcher pod as extra items to back up.
An action that restores the VirtualMachine
Adds a datavolumes to list of restored items.
An action that restores the VirtualMachineInstance
Skips the VMI if owned by a VM. The plugin also clears restricted labels, so the VMI is not rejected by kubevirt. The restricted labels contain runtime information about the underlying KVM object.
An action that handles the virt-launcher Pod. It makes sure virt-launcher pod is always skipped.
Plugin versions and respective Velero/Kubevirt/CDI versions that are tested to be compatible.
| Plugin Version | Velero Version | Kubevirt Version | CDI Version |
|---|---|---|---|
| v0.2.0 | v1.6.x, v1.7.x | v0.48.x | >= v1.37.0 |
| v0.6.x | v1.12.x | >= v1.0.0 | >= v1.57.0 |
To install the plugin check current velero documentation https://velero.io/docs/main/overview-plugins/. Below example for kubevirt-velero-plugin version v0.2.0 on Velero 1.7.0
velero plugin add quay.io/kubevirt/kubevirt-velero-plugin:v0.2.0When the plugin is deployed it is already effective. There is nothing special required to make it work.
kubectl create namespace demo
kubectl create -f example/datavolume.yaml -n demo
kubectl create -f example/vm.yaml -n demoWait for Vm running and with condition AgentConnected. Then login and add some data:
virtctl console example-vm -n demo
./velero backup create demobackup1 --include-namespaces demo --wait
kubectl delete vm example-vm -n demo
kubectl delete dv example-vm -n demoTry to login, to find a vm a dv or a pvc
virtctl console example-vm -n demo
./velero restore create --from-backup demobackup1 --wait
The velero-example repository contains some basic examples of backup/restore using Velero.
To build the plugin, run
$ make build-allTo build the image, run
$ make build-imageThis builds an image tagged as registry:5000/kubevirt-velero-plugin:0.1. If you want to specify a different name or version/tag, run:
$ DOCKER_PREFIX=your-repo/your-name DOCKER_TAG=your-version-tag make build-imageDevelopment version of the plugin is intended to work in local cluster build with KubeVirt's or CDI's make cluster-up.
To deploy the plugin:
make cluster-push-imageto build and push image to local clustermake local-deploy-veleroto deploy Velero to local clustermake add-pluginto add the plugin to Velero.