apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
cdi.kubevirt.io/cloneFallbackReason: The volume modes of source and target are incompatible
cdi.kubevirt.io/clonePhase: Succeeded
cdi.kubevirt.io/cloneType: copy
You can create virtual machines (VMs) by cloning existing persistent volume claims (PVCs) with custom images.
You must install the QEMU guest agent on VMs created from operating system images that are not provided by Red Hat.
You clone a PVC by creating a data volume that references a source PVC.
When cloning a data volume, the Containerized Data Importer (CDI) chooses one of the following Container Storage Interface (CSI) clone methods:
CSI volume cloning
Smart cloning
Both CSI volume cloning and smart cloning methods are efficient, but they have certain requirements for use. If the requirements are not met, the CDI uses host-assisted cloning. Host-assisted cloning is the slowest and least efficient method of cloning, but it has fewer requirements than either of the other two cloning methods.
Container Storage Interface (CSI) cloning uses CSI driver features to more efficiently clone a source data volume.
CSI volume cloning has the following requirements:
The CSI driver that backs the storage class of the persistent volume claim (PVC) must support volume cloning.
For provisioners not recognized by the CDI, the corresponding storage profile must have the cloneStrategy
set to CSI Volume Cloning.
The source and target PVCs must have the same storage class and volume mode.
If you create the data volume, you must have permission to create the datavolumes/source
resource in the source namespace.
The source volume must not be in use.
When a Container Storage Interface (CSI) plugin with snapshot capabilities is available, the Containerized Data Importer (CDI) creates a persistent volume claim (PVC) from a snapshot, which then allows efficient cloning of additional PVCs.
Smart cloning has the following requirements:
A snapshot class associated with the storage class must exist.
The source and target PVCs must have the same storage class and volume mode.
If you create the data volume, you must have permission to create the datavolumes/source
resource in the source namespace.
The source volume must not be in use.
When the requirements for neither Container Storage Interface (CSI) volume cloning nor smart cloning have been met, host-assisted cloning is used as a fallback method. Host-assisted cloning is less efficient than either of the two other cloning methods.
Host-assisted cloning uses a source pod and a target pod to copy data from the source volume to the target volume. The target persistent volume claim (PVC) is annotated with the fallback reason that explains why host-assisted cloning has been used, and an event is created.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
annotations:
cdi.kubevirt.io/cloneFallbackReason: The volume modes of source and target are incompatible
cdi.kubevirt.io/clonePhase: Succeeded
cdi.kubevirt.io/cloneType: copy
NAMESPACE LAST SEEN TYPE REASON OBJECT MESSAGE
test-ns 0s Warning IncompatibleVolumeModes persistentvolumeclaim/test-target The volume modes of source and target are incompatible
You can create a virtual machine (VM) by cloning a persistent volume claim (PVC) by using the Red Hat OpenShift service on AWS 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.
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