This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.7.13. Cloning virtual machines
The isolating nature of namespaces means that users cannot by default clone resources between namespaces.
To enable a user to clone a virtual machine to another namespace, a user with the cluster-admin
role must create a new ClusterRole. Bind this ClusterRole to a user to enable them to clone virtual machines to the destination namespace.
7.13.1.1. Prerequisites 复制链接链接已复制到粘贴板!
-
Only a user with the
cluster-admin
role can create ClusterRoles.
7.13.1.2. About DataVolumes 复制链接链接已复制到粘贴板!
DataVolume
objects are custom resources that are provided by the Containerized Data Importer (CDI) project. DataVolumes orchestrate import, clone, and upload operations that are associated with an underlying PersistentVolumeClaim (PVC). DataVolumes are integrated with KubeVirt, and they prevent a virtual machine from being started before the PVC has been prepared.
Create a new ClusterRole that enables permissions for all actions for the datavolumes
resource.
Procedure
Create a ClusterRole manifest:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Unique name for the ClusterRole.
Create the ClusterRole in the cluster:
oc create -f <datavolume-cloner.yaml>
$ oc create -f <datavolume-cloner.yaml>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The file name of the ClusterRole manifest created in the previous step.
Create a RoleBinding manifest that applies to both the source and destination namespaces and references the ClusterRole created in the previous step.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the RoleBinding in the cluster:
oc create -f <datavolume-cloner.yaml>
$ oc create -f <datavolume-cloner.yaml>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The file name of the RoleBinding manifest created in the previous step.
You can clone the PersistentVolumeClaim (PVC) of a virtual machine disk into a new DataVolume by referencing the source PVC in your DataVolume configuration file.
Cloning operations between different volume modes are not supported. The volumeMode
values must match in both the source and target specifications.
For example, if you attempt to clone from a PersistentVolume (PV) with volumeMode: Block
to a PV with volumeMode: Filesystem
, the operation fails with an error message.
7.13.2.1. Prerequisites 复制链接链接已复制到粘贴板!
- Users need additional permissions to clone the PVC of a virtual machine disk into another namespace.
7.13.2.2. About DataVolumes 复制链接链接已复制到粘贴板!
DataVolume
objects are custom resources that are provided by the Containerized Data Importer (CDI) project. DataVolumes orchestrate import, clone, and upload operations that are associated with an underlying PersistentVolumeClaim (PVC). DataVolumes are integrated with KubeVirt, and they prevent a virtual machine from being started before the PVC has been prepared.
You can clone a PersistentVolumeClaim (PVC) of an existing virtual machine disk into a new DataVolume. The new DataVolume can then be used for a new virtual machine.
When a DataVolume is created independently of a virtual machine, the lifecycle of the DataVolume is independent of the virtual machine. If the virtual machine is deleted, neither the DataVolume nor its associated PVC is deleted.
Prerequisites
- Determine the PVC of an existing virtual machine disk to use. You must power down the virtual machine that is associated with the PVC before you can clone it.
-
Install the OpenShift CLI (
oc
).
Procedure
- Examine the virtual machine disk you want to clone to identify the name and namespace of the associated PVC.
Create a YAML file for a DataVolume object that specifies the name of the new DataVolume, the name and namespace of the source PVC, and the size of the new DataVolume.
For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start cloning the PVC by creating the DataVolume:
oc create -f <cloner-datavolume>.yaml
$ oc create -f <cloner-datavolume>.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意DataVolumes prevent a virtual machine from starting before the PVC is prepared, so you can create a virtual machine that references the new DataVolume while the PVC clones.
7.13.2.4. Template: DataVolume clone configuration file 复制链接链接已复制到粘贴板!
example-clone-dv.yaml
7.13.2.5. CDI supported operations matrix 复制链接链接已复制到粘贴板!
This matrix shows the supported CDI operations for content types against endpoints, and which of these operations requires scratch space.
Content types | HTTP | HTTPS | HTTP basic auth | Registry | Upload |
---|---|---|---|---|---|
KubeVirt(QCOW2) |
✓ QCOW2 |
✓ QCOW2** |
✓ QCOW2 |
✓ QCOW2* |
✓ QCOW2* |
KubeVirt (RAW) |
✓ RAW |
✓ RAW |
✓ RAW |
✓ RAW* |
✓ RAW* |
✓ Supported operation
□ Unsupported operation
* Requires scratch space
** Requires scratch space if a custom certificate authority is required
You can create a new virtual machine by cloning the PersistentVolumeClaim (PVC) of an existing VM. By including a dataVolumeTemplate
in your virtual machine configuration file, you create a new DataVolume from the original PVC.
Cloning operations between different volume modes are not supported. The volumeMode
values must match in both the source and target specifications.
For example, if you attempt to clone from a PersistentVolume (PV) with volumeMode: Block
to a PV with volumeMode: Filesystem
, the operation fails with an error message.
7.13.3.1. Prerequisites 复制链接链接已复制到粘贴板!
- Users need additional permissions to clone the PVC of a virtual machine disk into another namespace.
7.13.3.2. About DataVolumes 复制链接链接已复制到粘贴板!
DataVolume
objects are custom resources that are provided by the Containerized Data Importer (CDI) project. DataVolumes orchestrate import, clone, and upload operations that are associated with an underlying PersistentVolumeClaim (PVC). DataVolumes are integrated with KubeVirt, and they prevent a virtual machine from being started before the PVC has been prepared.
You can create a virtual machine that clones the PersistentVolumeClaim (PVC) of an existing virtual machine into a DataVolume. By referencing a dataVolumeTemplate
in the virtual machine spec
, the source
PVC is cloned to a DataVolume, which is then automatically used for the creation of the virtual machine.
When a DataVolume is created as part of the DataVolumeTemplate of a virtual machine, the lifecycle of the DataVolume is then dependent on the virtual machine. If the virtual machine is deleted, the DataVolume and associated PVC are also deleted.
Prerequisites
- Determine the PVC of an existing virtual machine disk to use. You must power down the virtual machine that is associated with the PVC before you can clone it.
-
Install the OpenShift CLI (
oc
).
Procedure
- Examine the virtual machine you want to clone to identify the name and namespace of the associated PVC.
Create a YAML file for a
VirtualMachine
object. The following virtual machine example clonesmy-favorite-vm-disk
, which is located in thesource-namespace
namespace. The2Gi
DataVolume calledfavorite-clone
is created frommy-favorite-vm-disk
.For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The virtual machine to create.
Create the virtual machine with the PVC-cloned DataVolume:
oc create -f <vm-clone-datavolumetemplate>.yaml
$ oc create -f <vm-clone-datavolumetemplate>.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
example-dv-vm.yaml
- 1
- The
HTTP
source of the image you want to import, if applicable.
7.13.3.5. CDI supported operations matrix 复制链接链接已复制到粘贴板!
This matrix shows the supported CDI operations for content types against endpoints, and which of these operations requires scratch space.
Content types | HTTP | HTTPS | HTTP basic auth | Registry | Upload |
---|---|---|---|---|---|
KubeVirt(QCOW2) |
✓ QCOW2 |
✓ QCOW2** |
✓ QCOW2 |
✓ QCOW2* |
✓ QCOW2* |
KubeVirt (RAW) |
✓ RAW |
✓ RAW |
✓ RAW |
✓ RAW* |
✓ RAW* |
✓ Supported operation
□ Unsupported operation
* Requires scratch space
** Requires scratch space if a custom certificate authority is required
You can clone the PersistentVolumeClaim (PVC) of a virtual machine disk into a new block DataVolume by referencing the source PVC in your DataVolume configuration file.
Cloning operations between different volume modes are not supported. The volumeMode
values must match in both the source and target specifications.
For example, if you attempt to clone from a PersistentVolume (PV) with volumeMode: Block
to a PV with volumeMode: Filesystem
, the operation fails with an error message.
7.13.4.1. Prerequisites 复制链接链接已复制到粘贴板!
- Users need additional permissions to clone the PVC of a virtual machine disk into another namespace.
7.13.4.2. About DataVolumes 复制链接链接已复制到粘贴板!
DataVolume
objects are custom resources that are provided by the Containerized Data Importer (CDI) project. DataVolumes orchestrate import, clone, and upload operations that are associated with an underlying PersistentVolumeClaim (PVC). DataVolumes are integrated with KubeVirt, and they prevent a virtual machine from being started before the PVC has been prepared.
7.13.4.3. About block PersistentVolumes 复制链接链接已复制到粘贴板!
A block PersistentVolume (PV) is a PV that is backed by a raw block device. These volumes do not have a filesystem and can provide performance benefits for virtual machines by reducing overhead.
Raw block volumes are provisioned by specifying volumeMode: Block
in the PV and PersistentVolumeClaim (PVC) specification.
7.13.4.4. Creating a local block PersistentVolume 复制链接链接已复制到粘贴板!
Create a local block PersistentVolume (PV) on a node by populating a file and mounting it as a loop device. You can then reference this loop device in a PV configuration as a Block
volume and use it as a block device for a virtual machine image.
Procedure
-
Log in as
root
to the node on which to create the local PV. This procedure usesnode01
for its examples. Create a file and populate it with null characters so that it can be used as a block device. The following example creates a file
loop10
with a size of 2Gb (20 100Mb blocks):dd if=/dev/zero of=<loop10> bs=100M count=20
$ dd if=/dev/zero of=<loop10> bs=100M count=20
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Mount the
loop10
file as a loop device.losetup </dev/loop10>d3 <loop10>
$ losetup </dev/loop10>d3 <loop10>
1 2 Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
PersistentVolume
configuration that references the mounted loop device.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the block PV.
oc create -f <local-block-pv10.yaml>
# oc create -f <local-block-pv10.yaml>
1 Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The filename of the PersistentVolume created in the previous step.
You can clone a PersistentVolumeClaim (PVC) of an existing virtual machine disk into a new DataVolume. The new DataVolume can then be used for a new virtual machine.
When a DataVolume is created independently of a virtual machine, the lifecycle of the DataVolume is independent of the virtual machine. If the virtual machine is deleted, neither the DataVolume nor its associated PVC is deleted.
Prerequisites
- Determine the PVC of an existing virtual machine disk to use. You must power down the virtual machine that is associated with the PVC before you can clone it.
-
Install the OpenShift CLI (
oc
). - At least one available block PersistentVolume (PV) that is the same size as or larger than the source PVC.
Procedure
- Examine the virtual machine disk you want to clone to identify the name and namespace of the associated PVC.
Create a YAML file for a DataVolume object that specifies the name of the new DataVolume, the name and namespace of the source PVC,
volumeMode: Block
so that an available block PV is used, and the size of the new DataVolume.For example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- The name of the new DataVolume.
- 2
- The namespace where the source PVC exists.
- 3
- The name of the source PVC.
- 4
- The size of the new DataVolume. You must allocate enough space, or the cloning operation fails. The size must be the same as or larger than the source PVC.
- 5
- Specifies that the destination is a block PV
Start cloning the PVC by creating the DataVolume:
oc create -f <cloner-datavolume>.yaml
$ oc create -f <cloner-datavolume>.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 注意DataVolumes prevent a virtual machine from starting before the PVC is prepared, so you can create a virtual machine that references the new DataVolume while the PVC clones.
7.13.4.6. CDI supported operations matrix 复制链接链接已复制到粘贴板!
This matrix shows the supported CDI operations for content types against endpoints, and which of these operations requires scratch space.
Content types | HTTP | HTTPS | HTTP basic auth | Registry | Upload |
---|---|---|---|---|---|
KubeVirt(QCOW2) |
✓ QCOW2 |
✓ QCOW2** |
✓ QCOW2 |
✓ QCOW2* |
✓ QCOW2* |
KubeVirt (RAW) |
✓ RAW |
✓ RAW |
✓ RAW |
✓ RAW* |
✓ RAW* |
✓ Supported operation
□ Unsupported operation
* Requires scratch space
** Requires scratch space if a custom certificate authority is required