8.8.3.3. Creating a VM from a cloned PVC by using a data volume template
You can create a virtual machine (VM) that clones the persistent volume claim (PVC) of an existing VM by using a data volume template. This method creates a data volume whose lifecycle is independent on the original VM.
Prerequisites
- The VM with the source PVC must be powered down.
-
You have installed the
virtctlCLI. -
You have installed the OpenShift CLI (
oc).
Procedure
Create a
VirtualMachinemanifest for your VM and save it as a YAML file, for example:$ virtctl create vm --name rhel-9-clone --volume-import type:pvc,src:my-project/imported-volume-q5pr9Review the
VirtualMachinemanifest for your VM:apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: rhel-9-clone1 spec: dataVolumeTemplates: - metadata: name: imported-volume-h4qn8 spec: source: pvc: name: imported-volume-q5pr92 namespace: my-project3 storage: resources: {} instancetype: inferFromVolume: imported-volume-h4qn84 inferFromVolumeFailurePolicy: Ignore preference: inferFromVolume: imported-volume-h4qn85 inferFromVolumeFailurePolicy: Ignore runStrategy: Always template: spec: domain: devices: {} memory: guest: 512Mi resources: {} terminationGracePeriodSeconds: 180 volumes: - dataVolume: name: imported-volume-h4qn8 name: imported-volume-h4qn8Create the virtual machine with the PVC-cloned data volume:
$ oc create -f <vm_manifest_file>.yaml