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 VolumeSnapshot functionality of Kubernetes CSI drivers for capturing persistent VirtualMachine state. It is required that VMs use DataVolumes or PersistentVolumeClaims backed by a StorageClass that supports VolumeSnapshots and a VolumeSnapshotClass is properly configured for that StorageClass.
  • KubeVirt looks for Kubernetes Volume Snapshot-related APIs/resources in the v1 version. 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 from v1 version.

  • 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:

snapshot.yaml
Copy

Checking the snapshot progress:

Bash
Copy

Restore 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.

Bash
Copy

The 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.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard