
Title
Create new category
Edit page index title
Edit category
Edit link
VM Snapshot & Restore
A virtual machine (VM) snapshot captures the state and data of a virtual machine at the specific time when the snapshot was taken. It acts pretty much like the usual operating system snapshots. A VM snapshot is an exact copy of the VM and can be used for VM migration or for creating multiple instances of the same VM.
The snapshot.kubevirt.io API Group defines resources for snapshotting and restoring KubeVirt Virtual Machines.
Pre-requisites:
CSI Persistent Storage with support for VolumeSnapshot API should be installed with CRDs required for VolumeSnapshot API such as VolumeSnapshot, VolumeSnapshotClass etc.
- KubeVirt leverages the
VolumeSnapshotfunctionality of Kubernetes CSI drivers for capturing persistentVirtualMachinestate. It is required that VMs useDataVolumesorPersistentVolumeClaimsbacked by aStorageClassthat supportsVolumeSnapshotsand aVolumeSnapshotClassis properly configured for thatStorageClass.
- KubeVirt leverages the
KubeVirt looks for Kubernetes Volume Snapshot-related APIs/resources in the
v1version. To make sure that KubeVirt's snapshot controller is able to snapshot the VirtualMachine and referenced volumes as expected, Kubernetes Volume Snapshot APIs must be served fromv1version.Snapshot/Restore support must be enabled in the feature gates to be supported. Platform9 KubeVirt has it enabled by default.
If the persistent TPM feature is used with KubeVirt VM, that VM cannot be snapshotted.
Snapshot a Virtual Machine
To snapshot a VirtualMachine named fedora-vm-1, apply the following yaml on the cluster:
xxxxxxxxxxapiVersion: snapshot.kubevirt.io/v1alpha1kind: VirtualMachineSnapshotmetadata: name: snap-fedora-1spec: source: apiGroup: kubevirt.io kind: VirtualMachine name: fedora-vm-1Checking the snapshot progress:
$ kubectl get vmsnapshot -wNAME SOURCEKIND SOURCENAME PHASE READYTOUSE CREATIONTIME ERRORsnap-fedora-1 VirtualMachine fedora-vm-1snap-fedora-1 VirtualMachine fedora-vm-1 InProgress falsesnap-fedora-1 VirtualMachine fedora-vm-1 InProgress falsesnap-fedora-1 VirtualMachine fedora-vm-1 InProgress falsesnap-fedora-1 VirtualMachine fedora-vm-1 Succeeded true 0s $ kubectl get volumesnapshot -wNAME READYTOUSE SOURCEPVC SOURCESNAPSHOTCONTENT RESTORESIZE SNAPSHOTCLASS SNAPSHOTCONTENT CREATIONTIME AGEvmsnapshot-786c1511-9372-431b-b095-cb9bc494ed44-volume-rootfs fedora-dv-1 csi-cephfsplugin-snapclass 0svmsnapshot-786c1511-9372-431b-b095-cb9bc494ed44-volume-rootfs fedora-dv-1 csi-cephfsplugin-snapclass 0svmsnapshot-786c1511-9372-431b-b095-cb9bc494ed44-volume-rootfs false fedora-dv-1 csi-cephfsplugin-snapclass snapcontent-65f9b955-1b69-4e04-bbc7-edbbd17e9fea 0svmsnapshot-786c1511-9372-431b-b095-cb9bc494ed44-volume-rootfs false fedora-dv-1 csi-cephfsplugin-snapclass snapcontent-65f9b955-1b69-4e04-bbc7-edbbd17e9fea 0svmsnapshot-786c1511-9372-431b-b095-cb9bc494ed44-volume-rootfs true fedora-dv-1 5Gi csi-cephfsplugin-snapclass snapcontent-65f9b955-1b69-4e04-bbc7-edbbd17e9fea 2s 2sRestore a Virtual Machine
To restore the VM fedora-vm-1 from VirtualMachineSnapshot snap-fedora-1, Stop the VM, wait for it to be stopped and then apply the following yaml.
xxxxxxxxxxapiVersion: snapshot.kubevirt.io/v1alpha1kind: VirtualMachineRestoremetadata: name: restore-fedora-1spec: target: apiGroup: kubevirt.io kind: VirtualMachine name: fedora-vm-1 virtualMachineSnapshotName: snap-fedora-1The used csi storageclasses must support volume expansion in order to be able to restore the snapshots. Storageclasses that do not, will be able to make snapshots, but not restore them.
Clean Snapshots
VirtualMachineSnapshots (and their corresponding VirtualMachineSnapshotContents) objects can be deleted when they are no longer required for the restoring.