kind: VolumeSnapshotClass
apiVersion: snapshot.storage.k8s.io/v1
driver: openshift-storage.rbd.csi.ceph.com
# ...
You can create virtual machines (VMs) by cloning existing persistent volume claims (PVCs) with custom images.
You clone a PVC by creating a data volume that references a source PVC.
You must install the QEMU guest agent on VMs created from operating system images that are not provided by Red Hat.
You can create a virtual machine (VM) by cloning a persistent volume claim (PVC) by using the OKD web console.
You must have access to the namespace that contains the source PVC.
Navigate to Virtualization → Catalog in the web console.
Click a template tile without an available boot source.
Click Customize VirtualMachine.
On the Customize template parameters page, expand Storage and select PVC (clone PVC) from the Disk source list.
Select the PVC project and the PVC name.
Set the disk size.
Click Next.
Click Create VirtualMachine.
You can create a virtual machine (VM) by cloning the persistent volume claim (PVC) of an existing VM by using the command line.
You can clone a PVC by using one of the following options:
Cloning a PVC to a new data volume.
This method creates a data volume whose lifecycle is independent of the original VM. Deleting the original VM does not affect the new data volume or its associated PVC.
Cloning a PVC by creating a VirtualMachine
manifest with a dataVolumeTemplates
stanza.
This method creates a data volume whose lifecycle is dependent on the original VM. Deleting the original VM deletes the cloned data volume and its associated PVC.
You can clone the persistent volume claim (PVC) of an existing virtual machine (VM) disk to a data volume by using the command line.
You create a data volume that references the original source PVC. The lifecycle of the new data volume is independent of the original VM. Deleting the original VM does not affect the new data volume or its associated PVC.
Cloning between different volume modes is supported for host-assisted cloning, such as cloning from a block persistent volume (PV) to a file system PV, as long as the source and target PVs belong to the kubevirt
content type.
Smart-cloning is faster and more efficient than host-assisted cloning because it uses snapshots to clone PVCs. Smart-cloning is supported by storage providers that support snapshots, such as Red Hat OpenShift Data Foundation. Cloning between different volume modes is not supported for smart-cloning. |
The VM with the source PVC must be powered down.
If you clone a PVC to a different namespace, you must have permissions to create resources in the target namespace.
Additional prerequisites for smart-cloning:
Your storage provider must support snapshots.
The source and target PVCs must have the same storage provider and volume mode.
The value of the driver
key of the VolumeSnapshotClass
object must match the value of the provisioner
key of the StorageClass
object as shown in the following example:
VolumeSnapshotClass
objectkind: VolumeSnapshotClass
apiVersion: snapshot.storage.k8s.io/v1
driver: openshift-storage.rbd.csi.ceph.com
# ...
StorageClass
objectkind: StorageClass
apiVersion: storage.k8s.io/v1
# ...
provisioner: openshift-storage.rbd.csi.ceph.com
Create a DataVolume
manifest as shown in the following example:
apiVersion: cdi.kubevirt.io/v1beta1
kind: DataVolume
metadata:
name: <datavolume> (1)
spec:
source:
pvc:
namespace: "<source_namespace>" (2)
name: "<my_vm_disk>" (3)
storage: {}
1 | Specify the name of the new data volume. |
2 | Specify the namespace of the source PVC. |
3 | Specify the name of the source PVC. |
Create the data volume by running the following command:
$ oc create -f <datavolume>.yaml
Data volumes prevent a VM from starting before the PVC is prepared. You can create a VM that references the new data volume while the PVC is being cloned. |
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 dependent on the original VM. Deleting the original VM deletes the cloned data volume and its associated PVC.
The VM with the source PVC must be powered down.
Create a VirtualMachine
manifest as shown in the following example:
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
labels:
kubevirt.io/vm: vm-dv-clone
name: vm-dv-clone (1)
spec:
running: false
template:
metadata:
labels:
kubevirt.io/vm: vm-dv-clone
spec:
domain:
devices:
disks:
- disk:
bus: virtio
name: root-disk
resources:
requests:
memory: 64M
volumes:
- dataVolume:
name: favorite-clone
name: root-disk
dataVolumeTemplates:
- metadata:
name: favorite-clone
spec:
storage:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
source:
pvc:
namespace: <source_namespace> (2)
name: "<source_pvc>" (3)
1 | Specify the name of the VM. |
2 | Specify the namespace of the source PVC. |
3 | Specify the name of the source PVC. |
Create the virtual machine with the PVC-cloned data volume:
$ oc create -f <vm-clone-datavolumetemplate>.yaml