此内容没有您所选择的语言版本。
Chapter 6. Creating virtual machines
6.1. Creating virtual machines by using the CLI 复制链接链接已复制到粘贴板!
You can create virtual machines (VMs) from the command line by editing or creating a VirtualMachine manifest. You can simplify VM configuration by using an instance type in your VM manifest.
You can also create VMs from instance types by using the OpenShift Dedicated web console.
6.1.1. Creating a VM from a VirtualMachine manifest 复制链接链接已复制到粘贴板!
You can create a virtual machine (VM) from a VirtualMachine manifest. To simplify the creation of these manifests, you can use the virtctl command-line tool.
Prerequisites
-
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, to create a minimal Red Hat Enterprise Linux (RHEL) VM, run the following command:$ virtctl create vm --name rhel-9-minimal --volume-import type:ds,src:openshift-virtualization-os-images/rhel9Review the
VirtualMachinemanifest for your VM:NoteThis example manifest does not configure VM authentication.
Example manifest for a RHEL VM
apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: rhel-9-minimal spec: dataVolumeTemplates: - metadata: name: imported-volume-mk4lj spec: sourceRef: kind: DataSource name: rhel9 namespace: openshift-virtualization-os-images storage: resources: {} instancetype: inferFromVolume: imported-volume-mk4lj inferFromVolumeFailurePolicy: Ignore preference: inferFromVolume: imported-volume-mk4lj inferFromVolumeFailurePolicy: Ignore runStrategy: Always template: spec: domain: devices: video: type: virtio memory: guest: 512Mi resources: {} terminationGracePeriodSeconds: 180 volumes: - dataVolume: name: imported-volume-mk4lj name: imported-volume-mk4lj-
name: rhel-9-minimalspecifies the name of the VM. -
name: rhel9specifies the boot source for the guest operating system in thesourceRefsection. -
namespace: openshift-virtualization-os-imagesspecifies the namespace for the boot source. Golden images are stored in theopenshift-virtualization-os-imagesnamespace. -
instancetype: inferFromVolume: imported-volume-mk4ljspecifies the instance type inferred from the selectedDataSourceobject. -
preference: inferFromVolume: imported-volume-mk4ljspecifies that the preference is inferred from the selectedDataSourceobject. -
type: virtiospecifies the use of a custom video device (a VirtIO device in this example) to enable hardware graphics acceleration. Enabling a custom video device is in Technology Preview for OpenShift Virtualization 4.21.
-
Create a virtual machine by using the manifest file:
$ oc create -f <vm_manifest_file>.yamlOptional: Start the virtual machine:
$ virtctl start <vm_name>
You can upload an operating system image by using the virtctl command-line tool. You can use an existing data volume or create a new data volume for the image.
Prerequisites
-
You must have an
ISO,IMG, orQCOW2operating system image file. -
For best performance, compress the image file by using the virt-sparsify tool or the
xzorgziputilities. - The client machine must be configured to trust the OpenShift Dedicated router’s certificate.
-
You have installed the
virtctlCLI. -
You have installed the OpenShift CLI (
oc).
Procedure
Upload the image by running the
virtctl image-uploadcommand:$ virtctl image-upload dv <datavolume_name> \ --size=<datavolume_size> \ --image-path=</path/to/image><datavolume_name>- The name of the data volume.
<datavolume_size>-
The size of the data volume. For example:
--size=500Mi,--size=1G </path/to/image>The file path of the image.
Note-
If you do not want to create a new data volume, omit the
--sizeparameter and include the--no-createflag. - When uploading a disk image to a PVC, the PVC size must be larger than the size of the uncompressed virtual disk.
-
To allow insecure server connections when using HTTPS, use the
--insecureparameter. When you use the--insecureflag, the authenticity of the upload endpoint is not verified.
-
If you do not want to create a new data volume, omit the
Optional. To verify that a data volume was created, view all data volumes by running the following command:
$ oc get dvs
6.1.2.1. Supported custom video device types 复制链接链接已复制到粘贴板!
When creating a virtual machine (VM), you can configure a custom video device type to override the default video configuration.
Configuring a custom video device allows you to specify different video devices, based on your guest operating system requirements and performance needs.
Custom video device support is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
Using a custom video device provides several advantages:
- Performance
- Certain video devices provide better performance than the default configuration. For example, VirtIO is a more efficient video device on AMD/x86_64 architecture than legacy VGA.
- Resolution flexibility
- With some video device types, you can set custom display resolutions.
- Memory efficiency
- Some video types are more memory efficient for headless or console-only operations.
You can configure the following video device types:
-
VirtIO: provides improved performance, and hardware-accelerated video decoding and encoding by offloading tasks to the host. Recommended for modern guest operating systems with available
VirtIOdrivers. - VGA: the standard for analog video display (default on AMD/x86_64 with BIOS).
- Bochs: an emulated graphics adapter that provides a simple interface for guest operating systems to manage display settings (default on AMD/x86_64 with EFI).
- Cirrus: a legacy video device that provides stable video output.
- ramfb: a simple, unaccelerated virtual display device primarily used in the QEMU emulator, and useful for ARM architecture.
| Architecture | Boot mode | Default type | Supported types |
|---|---|---|---|
| AMD/x86_64 | BIOS |
|
|
| AMD/x86_64 | EFI |
|
|
| ARM64 | BIOS/EFI |
|
|
| s390x | BIOS/EFI |
|
|
6.2. Creating VMs by importing images from web pages 复制链接链接已复制到粘贴板!
You can create virtual machines (VMs) by importing operating system images from web pages.
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 importing an image from a web page by using the OpenShift Dedicated web console.
Prerequisites
- You must have access to the web page that contains the image.
Procedure
-
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 URL (creates PVC) from the Disk source list.
-
Enter the image URL. Example:
https://access.redhat.com/downloads/content/69/ver=/rhel---7/7.9/x86_64/product-software - Set the disk size.
- Click Next.
- Click Create VirtualMachine.
You can create a virtual machine (VM) from an image on a web page by using the command line.
When the VM is created, the data volume with the image is imported into persistent storage.
Prerequisites
- You must have access credentials for the web page that contains the image.
-
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, to create a minimal Red Hat Enterprise Linux (RHEL) VM from an image on a web page, run the following command:$ virtctl create vm --name vm-rhel-9 --instancetype u1.small --preference rhel.9 --volume-import type:http,url:https://example.com/rhel9.qcow2,size:10GiReview the
VirtualMachinemanifest for your VM:apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: vm-rhel-9 spec: dataVolumeTemplates: - metadata: name: imported-volume-6dcpf spec: source: http: url: https://example.com/rhel9.qcow2 storage: resources: requests: storage: 10Gi instancetype: name: u1.small preference: name: rhel.9 runStrategy: Always template: spec: domain: devices: {} resources: {} terminationGracePeriodSeconds: 180 volumes: - dataVolume: name: imported-volume-6dcpf name: imported-volume-6dcpf-
metadata.namedefines the VM name. -
spec.dataVolumeTemplates.metadata.namedefines the data volume name. -
spec.dataVolumeTemplates.spec.source.http.urldefines the URL of the image. -
spec.dataVolumeTemplates.spec.storage.resources.requests.storagedefines the size of the storage requested for the data volume. -
spec.instancetype.namedefines the instance type to use to control resource sizing of the VM. -
spec.preference.namedefines the preference to use.
-
Create the VM by running the following command:
$ oc create -f <vm_manifest_file>.yamlThe
oc createcommand creates the data volume and the VM. The CDI controller creates an underlying PVC with the correct annotation and the import process begins. When the import is complete, the data volume status changes toSucceeded. You can start the VM.Data volume provisioning happens in the background, so there is no need to monitor the process.
Verification
The importer pod downloads the image from the specified URL and stores it on the provisioned persistent volume. View the status of the importer pod:
$ oc get podsMonitor the status of the data volume:
$ oc get dv <data_volume_name>If the provisioning is successful, the data volume phase is
Succeeded.Example output:
NAME PHASE PROGRESS RESTARTS AGE imported-volume-6dcpf Succeeded 100.0% 18sVerify that provisioning is complete and that the VM has started by accessing its serial console:
$ virtctl console <vm_name>If the VM is running and the serial console is accessible, the output looks as follows:
Successfully connected to vm-rhel-9 console. The escape sequence is ^]
6.3. Creating VMs by uploading images 复制链接链接已复制到粘贴板!
You can create virtual machines (VMs) by uploading operating system images from your local machine.
You can create a Windows VM by uploading a Windows image to a PVC. Then you clone the PVC when you create the VM.
You must install the QEMU guest agent on VMs created from operating system images that are not provided by Red Hat.
You must also install VirtIO drivers on Windows VMs. Download VirtIO drivers only from official Red Hat sources. For more information, see "Additional resources".
You can create a virtual machine (VM) from an uploaded operating system image by using the OpenShift Dedicated web console.
Prerequisites
-
You must have an
IMG,ISO, orQCOW2image file.
Procedure
-
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 Upload (Upload a new file to a PVC) from the Disk source list.
- Browse to the image on your local machine and set the disk size.
- Click Customize VirtualMachine.
- Click Create VirtualMachine.
6.3.1.1. Generalizing a VM image 复制链接链接已复制到粘贴板!
You can generalize a Red Hat Enterprise Linux (RHEL) image to remove all system-specific configuration data before you use the image to create a boot source image, a preconfigured snapshot of a virtual machine (VM). You can use a boot source image to deploy new VMs.
You can generalize a RHEL VM by using the virtctl, guestfs, and virt-sysprep tools.
Prerequisites
- You have a RHEL virtual machine (VM) to use as a base VM.
-
You have installed the OpenShift CLI (
oc). -
You have installed the
virtctltool.
Procedure
Stop the RHEL VM if it is running, by entering the following command:
$ virtctl stop <my_vm_name>- Optional: Clone the virtual machine to avoid losing the data from your original VM. You can then generalize the cloned VM.
Retrieve the
dataVolumethat stores the root filesystem for the VM by running the following command:$ oc get vm <my_vm_name> -o jsonpath="{.spec.template.spec.volumes}{'\n'}"Example output:
[{"dataVolume":{"name":"<my_vm_volume>"},"name":"rootdisk"},{"cloudInitNoCloud":{...}]Retrieve the persistent volume claim (PVC) that matches the listed
dataVolumeby running the followimg command:$ oc get pvcExample output:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE <my_vm_volume> Bound …NoteIf your cluster configuration does not enable you to clone a VM, to avoid losing the data from your original VM, you can clone the VM PVC to a data volume instead. You can then use the cloned PVC to create a boot source image.
If you are creating a boot source image by cloning a PVC, continue with the next steps, using the cloned PVC.
Deploy a new interactive container with
libguestfs-toolsand attach the PVC to it by running the following command:$ virtctl guestfs <my-vm-volume> --uid 107This command opens a shell for you to run the next command.
Remove all configurations specific to your system by running the following command:
$ virt-sysprep -a disk.img-
In the OpenShift Dedicated console, click Virtualization
Catalog. - Click Add volume.
In the Add volume window:
- From the Source type list, select Use existing Volume.
- From the Volume project list, select your project.
- From the Volume name list, select the correct PVC.
- In the Volume name field, enter a name for the new boot source image.
- From the Preference list, select the RHEL version you are using.
- From the Default Instance Type list, select the instance type with the correct CPU and memory requirements for the version of RHEL you selected previously.
- Heterogeneous clusters only: From the Architecture list, select the architecture that corresponds with the selected volume.
- Click Save.
Result
The new volume appears in the Select volume to boot from list. This is your new boot source image. You can use this volume to create new VMs.
6.3.2. Creating a Windows VM 复制链接链接已复制到粘贴板!
You can create a Windows virtual machine (VM) by uploading a Windows image to a persistent volume claim (PVC) and then cloning the PVC when you create a VM by using the OpenShift Dedicated web console.
Prerequisites
- You created a Windows installation DVD or USB with the Windows Media Creation Tool. See Create Windows 10 installation media in the Microsoft documentation.
-
You created an
autounattend.xmlanswer file. See Answer files (unattend.xml) in the Microsoft documentation.
Procedure
Upload the Windows image as a new PVC:
-
Navigate to Storage
PersistentVolumeClaims in the web console. -
Click Create PersistentVolumeClaim
With Data upload form. - Browse to the Windows image and select it.
Enter the PVC name, select the storage class and size and then click Upload.
The Windows image is uploaded to a PVC.
-
Navigate to Storage
Configure a new VM by cloning the uploaded PVC:
-
Navigate to Virtualization
Catalog. - Select a Windows template tile and click Customize VirtualMachine.
- Select Clone (clone PVC) from the Disk source list.
- Select the PVC project, the Windows image PVC, and the disk size.
-
Navigate to Virtualization
Apply the answer file to the VM:
- Click Customize VirtualMachine parameters.
- On the Sysprep section of the Scripts tab, click Edit.
-
Browse to the
autounattend.xmlanswer file and click Save.
Set the run strategy of the VM:
- Clear Start this VirtualMachine after creation so that the VM does not start immediately.
- Click Create VirtualMachine.
-
On the YAML tab, replace
running:falsewithrunStrategy: RerunOnFailureand click Save.
Click the Options menu
and select Control Start. The VM boots from the
sysprepdisk containing theautounattend.xmlanswer file.
6.3.2.1. Generalizing a Windows VM image 复制链接链接已复制到粘贴板!
You can generalize a Windows operating system image to remove all system-specific configuration data before you use the image to create a new virtual machine (VM).
Before generalizing the VM, you must ensure the sysprep tool cannot detect an answer file after the unattended Windows installation.
Prerequisites
- A running Windows VM with the QEMU guest agent installed.
Procedure
-
In the OpenShift Dedicated console, click Virtualization
VirtualMachines. - Select a Windows VM to open the VirtualMachine details page.
-
Click Configuration
Disks. -
Click the Options menu
beside the sysprepdisk and select Detach. - Click Detach.
-
Rename
C:\Windows\Panther\unattend.xmlto avoid detection by thesyspreptool. Start the
sysprepprogram by running the following command:%WINDIR%\System32\Sysprep\sysprep.exe /generalize /shutdown /oobe /mode:vm-
After the
syspreptool completes, the Windows VM shuts down. The disk image of the VM is now available to use as an installation image for Windows VMs.
Result
You can now specialize the VM.
6.3.2.2. Specializing a Windows VM image 复制链接链接已复制到粘贴板!
Specializing a Windows virtual machine (VM) configures the computer-specific information from a generalized Windows image onto the VM.
Prerequisites
- You must have a generalized Windows disk image.
-
You must create an
unattend.xmlanswer file. See the Microsoft documentation for details.
Procedure
-
In the OpenShift Dedicated console, click Virtualization
Catalog. - Select a Windows template and click Customize VirtualMachine.
- Select PVC (clone PVC) from the Disk source list.
- Select the PVC project and PVC name of the generalized Windows image.
- Click Customize VirtualMachine parameters.
- Click the Scripts tab.
-
In the Sysprep section, click Edit, browse to the
unattend.xmlanswer file, and click Save. - Click Create VirtualMachine.
Result
During the initial boot, Windows uses the unattend.xml answer file to specialize the VM. The VM is now ready to use.
You can upload an operating system image by using the virtctl command-line tool. You can use an existing data volume or create a new data volume for the image.
Prerequisites
-
You must have an
ISO,IMG, orQCOW2operating system image file. -
For best performance, compress the image file by using the virt-sparsify tool or the
xzorgziputilities. - The client machine must be configured to trust the OpenShift Dedicated router’s certificate.
-
You have installed the
virtctlCLI. -
You have installed the OpenShift CLI (
oc).
Procedure
Upload the image by running the
virtctl image-uploadcommand:$ virtctl image-upload dv <datavolume_name> \ --size=<datavolume_size> \ --image-path=</path/to/image><datavolume_name>- The name of the data volume.
<datavolume_size>-
The size of the data volume. For example:
--size=500Mi,--size=1G </path/to/image>The file path of the image.
Note-
If you do not want to create a new data volume, omit the
--sizeparameter and include the--no-createflag. - When uploading a disk image to a PVC, the PVC size must be larger than the size of the uncompressed virtual disk.
-
To allow insecure server connections when using HTTPS, use the
--insecureparameter. When you use the--insecureflag, the authenticity of the upload endpoint is not verified.
-
If you do not want to create a new data volume, omit the
Optional. To verify that a data volume was created, view all data volumes by running the following command:
$ oc get dvs
6.4. Creating VMs by using container disks 复制链接链接已复制到粘贴板!
You can create virtual machines (VMs) by using container disks built from operating system images.
You can enable auto updates for your container disks. For more information, see "Additional resources".
If the container disks are large, the I/O traffic might increase and cause worker nodes to be unavailable. You can prune DeploymentConfig objects to resolve this issue:
You create a VM from a container disk by performing the following steps:
- Build an operating system image into a container disk and upload it to your container registry.
- If your container registry does not have TLS, configure your environment to disable TLS for your registry.
- Create a VM with the container disk as the disk source by using the OpenShift Dedicated web console or the command line.
You must install the QEMU guest agent on VMs created from operating system images that are not provided by Red Hat.
6.4.1. Building and uploading a container disk 复制链接链接已复制到粘贴板!
You can build a virtual machine (VM) image into a container disk and upload it to a registry.
The size of a container disk is limited by the maximum layer size of the registry where the container disk is hosted.
For Red Hat Quay, you can change the maximum layer size by editing the YAML configuration file that is created when Red Hat Quay is first deployed.
Prerequisites
-
You must have
podmaninstalled. - You must have a QCOW2 or RAW image file.
Procedure
Create a Dockerfile to build the VM image into a container image. The VM image must be owned by QEMU, which has a UID of
107, and placed in the/disk/directory inside the container. Permissions for the/disk/directory must then be set to0440.The following example uses the Red Hat Universal Base Image (UBI) to handle these configuration changes in the first stage, and uses the minimal
scratchimage in the second stage to store the result:$ cat > Dockerfile << EOF FROM registry.access.redhat.com/ubi8/ubi:latest AS builder ADD --chown=107:107 <vm_image>.qcow2 /disk/ // RUN chmod 0440 /disk/* FROM scratch COPY --from=builder /disk/* /disk/ EOFwhere:
<vm_image>-
Specifies the image in either QCOW2 or RAW format. If you use a remote image, replace
<vm_image>.qcow2with the complete URL.
Build and tag the container:
$ podman build -t <registry>/<container_disk_name>:latest .Push the container image to the registry:
$ podman push <registry>/<container_disk_name>:latest
6.4.2. Disabling TLS for a container registry 复制链接链接已复制到粘贴板!
You can disable TLS (transport layer security) for one or more container registries by editing the insecureRegistries field of the HyperConverged custom resource.
Prerequisites
-
You have installed the OpenShift CLI (
oc).
Procedure
Open the
HyperConvergedCR in your default editor by running the following command:$ oc edit hyperconvergeds.v1beta1.hco.kubevirt.io kubevirt-hyperconverged -n openshift-cnvAdd a list of insecure registries to the
spec.storageImport.insecureRegistriesfield.Example
HyperConvergedcustom resource:apiVersion: hco.kubevirt.io/v1beta1 kind: HyperConverged metadata: name: kubevirt-hyperconverged namespace: openshift-cnv spec: storageImport: insecureRegistries: - "private-registry-example-1:5000" - "private-registry-example-2:5000"Replace the examples in the
insecureRegistrieslist with valid registry hostnames.
You can create a virtual machine (VM) by importing a container disk from a container registry by using the OpenShift Dedicated web console.
Procedure
-
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 Registry (creates PVC) from the Disk source list.
-
Enter the container image URL. Example:
https://mirror.arizona.edu/fedora/linux/releases/38/Cloud/x86_64/images/Fedora-Cloud-Base-38-1.6.x86_64.qcow2 - Set the disk size.
- Click Next.
- Click Create VirtualMachine.
You can create a virtual machine (VM) from a container disk by using the command line.
Prerequisites
- You must have access credentials for the container registry that contains the container disk.
-
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, to create a minimal Red Hat Enterprise Linux (RHEL) VM from a container disk, run the following command:$ virtctl create vm --name vm-rhel-9 --instancetype u1.small --preference rhel.9 --volume-containerdisk src:registry.redhat.io/rhel9/rhel-guest-image:9.5Review the
VirtualMachinemanifest for your VM:apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata: name: vm-rhel-9 spec: instancetype: name: u1.small preference: name: rhel.9 runStrategy: Always template: metadata: creationTimestamp: null spec: domain: devices: {} resources: {} terminationGracePeriodSeconds: 180 volumes: - containerDisk: image: registry.redhat.io/rhel9/rhel-guest-image:9.5 name: vm-rhel-9-containerdisk-0-
metadata.namedefines the VM name. -
spec.instancetype.namedefines the instance type to use to control resource sizing of the VM. -
spec.preference.namedefines the preference to use. -
spec.template.spec.volumes.containerDisk.imagedefines the URL of the container disk.
-
Create the VM by running the following command:
$ oc create -f <vm_manifest_file>.yaml
Verification
Monitor the status of the VM:
$ oc get vm <vm_name>If the provisioning is successful, the VM status is
Running. Example output:NAME AGE STATUS READY vm-rhel-9 18s Running TrueVerify that provisioning is complete and that the VM has started by accessing its serial console:
$ virtctl console <vm_name>If the VM is running and the serial console is accessible, the output looks as follows:
Successfully connected to vm-rhel-9 console. The escape sequence is ^]
6.5. Creating VMs by cloning PVCs 复制链接链接已复制到粘贴板!
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.
6.5.1. About cloning 复制链接链接已复制到粘贴板!
When cloning a data volume, the Containerized Data Importer (CDI) chooses one of the Container Storage Interface (CSI) clone methods: CSI volume cloning or smart cloning. Both methods are efficient but have certain requirements. 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.
6.5.1.1. CSI volume cloning 复制链接链接已复制到粘贴板!
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
cloneStrategyset 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/sourceresource in the source namespace. - The source volume must not be in use.
6.5.1.2. Smart cloning 复制链接链接已复制到粘贴板!
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/sourceresource in the source namespace. - The source volume must not be in use.
6.5.1.3. Host-assisted cloning 复制链接链接已复制到粘贴板!
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.
Example PVC target annotation:
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
Example event:
NAMESPACE LAST SEEN TYPE REASON OBJECT MESSAGE
test-ns 0s Warning IncompatibleVolumeModes persistentvolumeclaim/test-target The volume modes of source and target are incompatible
6.5.2. Creating a VM from a PVC by using the web console 复制链接链接已复制到粘贴板!
You can create a virtual machine (VM) by cloning a persistent volume claim (PVC) by using the OpenShift Dedicated web console.
Prerequisites
- You must have access to the namespace that contains the source PVC.
Procedure
-
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.
6.5.3. Creating a VM from a PVC by using the CLI 复制链接链接已复制到粘贴板!
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
VirtualMachinemanifest with adataVolumeTemplatesstanza.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.
When you use OpenShift Data Foundation, the storage profile configures the default cloning strategy as csi-clone. However, this method has limitations, as shown in the following link.
After a certain number of clones are created from a persistent volume claim (PVC), a background flattening process begins, which can significantly reduce clone creation performance at scale.
To improve performance when creating hundreds of clones from a single source PVC, use the VolumeSnapshot cloning method instead of the default csi-clone strategy.
Procedure
Create a
VolumeSnapshotcustom resource (CR) of the source image by using the following content:apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot metadata: name: golden-volumesnapshot namespace: golden-ns spec: volumeSnapshotClassName: ocs-storagecluster-rbdplugin-snapclass source: persistentVolumeClaimName: golden-snap-sourceAdd the
spec.source.snapshotstanza to reference theVolumeSnapshotas the source for theDataVolume clone:spec: source: snapshot: namespace: golden-ns name: golden-volumesnapshot
6.5.3.2. Cloning a PVC to a data volume 复制链接链接已复制到粘贴板!
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.
Prerequisites
-
You have installed the OpenShift CLI (
oc). - 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
driverkey of theVolumeSnapshotClassobject must match the value of theprovisionerkey of theStorageClassobject as shown in the following example:Example
VolumeSnapshotClassobject:kind: VolumeSnapshotClass apiVersion: snapshot.storage.k8s.io/v1 driver: openshift-storage.rbd.csi.ceph.com # ...Example
StorageClassobject:kind: StorageClass apiVersion: storage.k8s.io/v1 # ... provisioner: openshift-storage.rbd.csi.ceph.com
Procedure
Create a
DataVolumemanifest as shown in the following example:apiVersion: cdi.kubevirt.io/v1beta1 kind: DataVolume metadata: name: <datavolume> spec: source: pvc: namespace: "<source_namespace>" name: "<my_vm_disk>" storage: {}where:
<datavolume>- Specifies the name of the new data volume.
<source_namespace>- Specifies the namespace of the source PVC.
<my_vm_disk>- Specifies the name of the source PVC.
Create the data volume by running the following command:
$ oc create -f <datavolume>.yamlNoteData 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 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-clone spec: dataVolumeTemplates: - metadata: name: imported-volume-h4qn8 spec: source: pvc: name: imported-volume-q5pr9 namespace: my-project storage: resources: {} instancetype: inferFromVolume: imported-volume-h4qn8 inferFromVolumeFailurePolicy: Ignore preference: inferFromVolume: imported-volume-h4qn8 inferFromVolumeFailurePolicy: Ignore runStrategy: Always template: spec: domain: devices: {} memory: guest: 512Mi resources: {} terminationGracePeriodSeconds: 180 volumes: - dataVolume: name: imported-volume-h4qn8 name: imported-volume-h4qn8-
metadata.namedefines the VM name. -
spec.dataVolumeTemplates.spec.source.pvc.namedefines the name of the source PVC. -
spec.dataVolumeTemplates.spec.source.pvc.namespacedefines the namespace of the source PVC. -
spec.instancetype.inferFromVolumedefines that if the PVC source has appropriate labels, the instance type is inferred from the selectedDataSourceobject. -
spec.preference.inferFromVolumedefines that if the PVC source has appropriate labels, the preference is inferred from the selectedDataSourceobject.
-
Create the virtual machine with the PVC-cloned data volume:
$ oc create -f <vm_manifest_file>.yaml
6.6. Creating virtual machines from instance types 复制链接链接已复制到粘贴板!
You can simplify virtual machine (VM) creation by using instance types, whether you use the OpenShift Dedicated web console or the CLI to create VMs.
6.6.1. About instance types 复制链接链接已复制到粘贴板!
An instance type is a reusable object where you can define resources and characteristics to apply to new VMs. You can define custom instance types or use the variety that are included when you install OpenShift Virtualization.
To create a new instance type, you must first create a manifest, either manually or by using the virtctl CLI tool. You then create the instance type object by applying the manifest to your cluster.
OpenShift Virtualization provides two CRDs for configuring instance types:
-
A namespaced object:
VirtualMachineInstancetype -
A cluster-wide object:
VirtualMachineClusterInstancetype
These objects use the same VirtualMachineInstancetypeSpec.
6.6.1.1. Required attributes 复制链接链接已复制到粘贴板!
When you configure an instance type, you must define the cpu and memory attributes. Other attributes are optional.
When you create a VM from an instance type, you cannot override any parameters defined in the instance type.
Because instance types require defined CPU and memory attributes, OpenShift Virtualization always rejects additional requests for these resources when creating a VM from an instance type.
You can manually create an instance type manifest. For example:
apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachineInstancetype
metadata:
name: example-instancetype
spec:
cpu:
guest: 1
memory:
guest: 128Mi
-
spec.cpu.guestis a required field that specifies the number of vCPUs to allocate to the guest. -
spec.memory.guestis a required field that specifies an amount of memory to allocate to the guest.
You can create an instance type manifest by using the virtctl CLI utility. For example:
$ virtctl create instancetype --cpu 2 --memory 256Mi
where:
--cpu <value>- Specifies the number of vCPUs to allocate to the guest. Required.
--memory <value>- Specifies an amount of memory to allocate to the guest. Required.
You can immediately create the object from the new manifest by running the following command:
$ virtctl create instancetype --cpu 2 --memory 256Mi | oc apply -f -
6.6.1.2. Optional attributes 复制链接链接已复制到粘贴板!
In addition to the required cpu and memory attributes, you can include the following optional attributes in the VirtualMachineInstancetypeSpec:
annotations- List annotations to apply to the VM.
gpus- List vGPUs for passthrough.
hostDevices- List host devices for passthrough.
ioThreadsPolicy- Define an IO threads policy for managing dedicated disk access.
launchSecurity- Configure Secure Encrypted Virtualization (SEV).
nodeSelector- Specify node selectors to control the nodes where this VM is scheduled.
schedulerName- Define a custom scheduler to use for this VM instead of the default scheduler.
6.6.1.3. Controller revisions 复制链接链接已复制到粘贴板!
When you create a VM by using an instance type, a ControllerRevision object retains an immutable snapshot of the instance type object. This snapshot locks in resource-related characteristics defined in the instance type object, such as the required guest CPU and memory. The VM status also contains a reference to the ControllerRevision object.
This snapshot is essential for versioning, and ensures that the VM instance created when starting a VM does not change if the underlying instance type object is updated while the VM is running.
6.6.2. Pre-defined instance types 复制链接链接已复制到粘贴板!
OpenShift Virtualization includes a set of pre-defined instance types called common-instancetypes. Some are specialized for specific workloads and others are workload-agnostic.
These instance type resources are named according to their series, version, and size. The size value follows the . delimiter and ranges from nano to 8xlarge.
| Use case | Series | Characteristics | vCPU to memory ratio | Example resource |
|---|---|---|---|---|
| Network | N |
| 1:2 |
|
| Overcommitted | O |
| 1:4 |
|
| Compute Exclusive | CX |
| 1:2 |
|
| General Purpose | U |
| 1:4 |
|
| Memory Intensive | M |
| 1:8 |
|
| Dedicated | D |
| 1:4 |
|
6.6.3. Specifying an instance type or preference 复制链接链接已复制到粘贴板!
You can specify an instance type, a preference, or both to define a set of workload sizing and runtime characteristics for reuse across multiple VMs.
You can specify instance types and preferences by using flags.
Prerequisites
- You must have an instance type, preference, or both on the cluster.
Procedure
To specify an instance type when creating a VM, use the
--instancetypeflag. To specify a preference, use the--preferenceflag. The following example includes both flags:$ virtctl create vm --instancetype <my_instancetype> --preference <my_preference>Optional: To specify a namespaced instance type or preference, include the
kindin the value passed to the--instancetypeor--preferenceflag command. The namespaced instance type or preference must be in the same namespace you are creating the VM in. The following example includes flags for a namespaced instance type and a namespaced preference:$ virtctl create vm --instancetype virtualmachineinstancetype/<my_instancetype> --preference virtualmachinepreference/<my_preference>
6.6.3.2. Inferring an instance type or preference 复制链接链接已复制到粘贴板!
Inferring instance types, preferences, or both is enabled by default, and the inferFromVolumeFailure policy of the inferFromVolume attribute is set to Ignore. When inferring from the boot volume, errors are ignored, and the VM is created with the instance type and preference left unset.
However, when flags are applied, the inferFromVolumeFailure policy defaults to Reject. When inferring from the boot volume, errors result in the rejection of the creation of that VM.
You can use the --infer-instancetype and --infer-preference flags to infer which instance type, preference, or both to use to define the workload sizing and runtime characteristics of a VM.
Prerequisites
-
You have installed the
virtctltool.
Procedure
To explicitly infer instance types from the volume used to boot the VM, use the
--infer-instancetypeflag. To explicitly infer preferences, use the--infer-preferenceflag. The following command includes both flags:$ virtctl create vm --volume-import type:pvc,src:my-ns/my-pvc --infer-instancetype --infer-preferenceTo infer an instance type or preference from a volume other than the volume used to boot the VM, use the
--infer-instancetype-fromand--infer-preference-fromflags to specify any of the virtual machine’s volumes. In the example below, the virtual machine boots fromvolume-abut infers the instancetype and preference fromvolume-b.$ virtctl create vm \ --volume-import=type:pvc,src:my-ns/my-pvc-a,name:volume-a \ --volume-import=type:pvc,src:my-ns/my-pvc-b,name:volume-b \ --infer-instancetype-from volume-b \ --infer-preference-from volume-b
6.6.3.3. Setting the inferFromVolume labels 复制链接链接已复制到粘贴板!
Use the following labels on your PVC, data source, or data volume to instruct the inference mechanism which instance type, preference, or both to use when trying to boot from a volume.
-
A cluster-wide instance type:
instancetype.kubevirt.io/default-instancetypelabel. -
A namespaced instance type:
instancetype.kubevirt.io/default-instancetype-kindlabel. Defaults to theVirtualMachineClusterInstancetypelabel if left empty. -
A cluster-wide preference:
instancetype.kubevirt.io/default-preferencelabel. -
A namespaced preference:
instancetype.kubevirt.io/default-preference-kindlabel. Defaults toVirtualMachineClusterPreferencelabel, if left empty.
Prerequisites
- You must have an instance type, preference, or both on the cluster.
-
You have installed the OpenShift CLI (
oc).
Procedure
To apply a label to a data source, use
oc label. The following command applies a label that points to a cluster-wide instance type:$ oc label DataSource foo instancetype.kubevirt.io/default-instancetype=<my_instancetype>
You can create a virtual machine (VM) from an instance type by using the OpenShift Dedicated web console. You can also use the web console to create a VM by copying an existing snapshot or to clone a VM.
You can create a VM from a list of available bootable volumes. You can add Linux- or Windows-based volumes to the list.
Procedure
In the web console, navigate to Virtualization
Catalog. The InstanceTypes tab opens by default.
- Heterogeneous clusters only: To filter the bootable volumes using the options provided, click Architecture.
Select either of the following options:
Select a suitable bootable volume from the list. If the list is truncated, click the Show all button to display the entire list.
NoteThe bootable volume table lists only those volumes in the
openshift-virtualization-os-imagesnamespace that have theinstancetype.kubevirt.io/default-preferencelabel.- Optional: Click the star icon to designate a bootable volume as a favorite. Starred bootable volumes appear first in the volume list.
Click Add volume to upload a new volume or to use an existing persistent volume claim (PVC), a volume snapshot, or a
containerDiskvolume. Click Save.Logos of operating systems that are not available in the cluster are shown at the bottom of the list. You can add a volume for the required operating system by clicking the Add volume link.
In addition, there is a link to the Create a Windows bootable volume quick start. The same link appears in a popover if you hover the pointer over the question mark icon next to the Select volume to boot from line.
Immediately after you install the environment or when the environment is disconnected, the list of volumes to boot from is empty. In that case, three operating system logos are displayed: Windows, RHEL, and Linux. You can add a new volume that meets your requirements by clicking the Add volume button.
- Click an instance type tile and select the resource size appropriate for your workload. You can select huge pages for Red Hat-provided instance types of the M and CX series. Huge page options are identified by names that end with 1gi.
Optional: Choose the virtual machine details, including the VM’s name, that apply to the volume you are booting from:
For a Linux-based volume, follow these steps to configure SSH:
- If you have not already added a public SSH key to your project, click the edit icon beside Authorized SSH key in the VirtualMachine details section.
Select one of the following options:
- Use existing: Select a secret from the secrets list.
Add new: Follow these steps:
- Browse to the public SSH key file or paste the file in the key field.
- Enter the secret name.
- Optional: Select Automatically apply this key to any new VirtualMachine you create in this project.
- Click Save.
For a Windows volume, follow either of these set of steps to configure sysprep options:
If you have not already added sysprep options for the Windows volume, follow these steps:
- Click the edit icon beside Sysprep in the VirtualMachine details section.
- Add the Autoattend.xml answer file.
- Add the Unattend.xml answer file.
- Click Save.
If you want to use existing sysprep options for the Windows volume, follow these steps:
- Click Attach existing sysprep.
- Enter the name of the existing sysprep Unattend.xml answer file.
- Click Save.
Optional: If you are creating a Windows VM, you can mount a Windows driver disk:
- Click the Customize VirtualMachine button.
- On the VirtualMachine details page, click Storage.
- Select the Mount Windows drivers disk checkbox.
- Optional: Click View YAML & CLI to view the YAML file. Click CLI to view the CLI commands. You can also download or copy either the YAML file contents or the CLI commands.
- Click Create VirtualMachine.
Result
After the VM is created, you can monitor the status on the VirtualMachine details page.
6.6.5. Change the instance type for a VM 复制链接链接已复制到粘贴板!
Cluster administrators and VM owners can change the instance type for existing virtual machines to adjust resources or optimize performance for specific workloads.
Changing the instance type for a VM allows you to adapt to evolving workload requirements without recreating the virtual machine. When a VM’s workload increases over time, you can switch to an instance type with more CPU, additional memory, or specific hardware resources to prevent performance bottlenecks and ensure the VM continues to meet demand.
Different instance types are optimized for specific use cases, so switching to a specialized instance type can improve performance for particular workloads. For example, you might transition to a compute-optimized instance type for CPU-intensive applications or to a memory-optimized type for workloads that require larger memory allocations.
You can change the instance type for an existing VM using either the OpenShift Dedicated web console or the OpenShift CLI (oc).
You can change the instance type associated with a running virtual machine (VM) by using the web console. The change takes effect immediately.
Prerequisites
- You created the VM by using an instance type.
Procedure
-
In the OpenShift Dedicated web console, click Virtualization
VirtualMachines. - Select a VM to open the VirtualMachine details page.
- Click the Configuration tab.
- On the Details tab, click the instance type text to open the Edit Instancetype dialog. For example, click 1 CPU | 2 GiB Memory.
Edit the instance type by using the Series and Size lists.
- Select an item from the Series list to show the relevant sizes for that series. For example, select General Purpose.
- Select the new instance type for the VM from the Size list. For example, select medium: 1 CPUs, 4Gi Memory, which is available in the General Purpose series.
- Click Save.
Verification
- Click the YAML tab.
- Click Reload.
- Review the VM YAML to confirm that the instance type changed.
To change the instance type of a VM, change the name field in the VM spec. This triggers the update logic, which ensures that a new, immutable controller revision snapshot is taken of the new resource configuration.
Prerequisites
-
You have installed the OpenShift CLI (
oc). - You created the VM by using an instance type, or have administrator privileges for the VM that you want to modify.
Procedure
- Stop the VM.
Run the following command, and replace
<vm_name>with the name of your VM, and<new_instancetype>with the name of the instance type you want to change to:$ oc patch vm/<vm_name> --type merge -p '{"spec":{"instancetype":{"name": "<new_instancetype>"}}}'
Verification
Check the controller revision reference in the updated VM
statusfield. Run the following command and verify that the revision name is updated in the output:$ oc get vms/<vm_name> -o json | jq .status.instancetypeRefExample output:
{ "controllerRevisionRef": { "name": "vm-cirros-csmall-csmall-3e86e367-9cd7-4426-9507-b14c27a08671-2" }, "kind": "VirtualMachineInstancetype", "name": "csmall" }Optional: Check that the VM instance is running the new configuration defined in the latest controller revision. For example, if you updated the instance type to use 2 vCPUs instead of 1, run the following command and check the output:
$ oc get vmi/<vm_name> -o json | jq .spec.domain.cpuExample output that verifies that the revision uses 2 vCPUs:
{ "cores": 1, "model": "host-model", "sockets": 2, "threads": 1 }
6.7. Creating virtual machines from templates 复制链接链接已复制到粘贴板!
You can create virtual machines (VMs) from Red Hat templates by using the OpenShift Dedicated web console.
6.7.1. About VM templates 复制链接链接已复制到粘贴板!
You can use VM templates to help you easily create VMs.
- Expedite creation with boot sources
You can expedite VM creation by using templates that have an available boot source. Templates with a boot source are labeled Available boot source if they do not have a custom label.
Templates without a boot source are labeled Boot source required. See "Managing automatic boot source updates" for details.
- Customize before starting the VM
You can customize the disk source and VM parameters before you start the VM.
NoteIf you copy a VM template with all its labels and annotations, your version of the template is marked as deprecated when a new version of the Scheduling, Scale, and Performance (SSP) Operator is deployed. You can remove this designation. See "Removing a deprecated designation from a customized VM template by using the web console".
- Single-node OpenShift
-
Due to differences in storage behavior, some templates are incompatible with single-node OpenShift. To ensure compatibility, do not set the
evictionStrategyfield for templates or VMs that use data volumes or storage profiles.
6.7.2. Creating a VM from a template 复制链接链接已复制到粘贴板!
You can create a virtual machine (VM) from a template with an available boot source by using the OpenShift Dedicated web console. You can customize template or VM parameters, such as data sources, Cloud-init, or SSH keys, before you start the VM.
You can choose between two views in the web console to create the VM:
- A virtualization-focused view, which provides a concise list of virtualization-related options at the top of the view
- A general view, which provides access to the various web console options, including Virtualization
Procedure
From the OpenShift Dedicated web console, choose your view:
-
For a virtualization-focused view, select Administrator
Virtualization Catalog. -
For a general view, navigate to Virtualization
Catalog.
-
For a virtualization-focused view, select Administrator
- Click the Template catalog tab.
- Click the Boot source available checkbox to filter templates with boot sources. The catalog displays the default templates.
- Heterogeneous clusters only: To filter the search results to show templates associated with a particular architecture, click Architecture Type .
Click All templates to view the available templates for your filters.
-
To focus on particular templates, enter the keyword in the
Filter by keywordfield. - Choose a template project from the All projects dropdown menu, or view all projects.
-
To focus on particular templates, enter the keyword in the
Click a template tile to view its details.
- Optional: If you are using a Windows template, you can mount a Windows driver disk by selecting the Mount Windows drivers disk checkbox.
- If you do not need to customize the template or VM parameters, click Quick create VirtualMachine to create a VM from the template.
If you need to customize the template or VM parameters, do the following:
- Click Customize VirtualMachine. The Customize and create VirtualMachine page displays the Overview, YAML, Scheduling, Environment, Network interfaces, Disks, Scripts, and Metadata tabs.
-
Click the Scripts tab to edit the parameters that must be set before the VM boots, such as
Cloud-init,SSH key, orSysprep(Windows VM only). - Optional: Click the Start this virtualmachine after creation (Always) checkbox.
Click Create VirtualMachine.
The VirtualMachine details page displays the provisioning status.
You can customize an existing virtual machine (VM) template before you start the VM, by modifying the VM or template parameters, such as data sources, cloud-init, or SSH keys.
If you customize a template by copying it and including all of its labels and annotations, the customized template is marked as deprecated when a new version of the Scheduling, Scale, and Performance (SSP) Operator is deployed. You can remove the deprecated designation from the customized template.
Procedure
-
Navigate to Virtualization
Templates in the web console. - From the list of VM templates, click the template marked as deprecated.
- Click Edit next to the pencil icon beside Labels.
Remove the following two labels:
-
template.kubevirt.io/type: "base" -
template.kubevirt.io/version: "version"
-
- Click Save.
- Click the pencil icon beside the number of existing Annotations.
Remove the following annotation:
-
template.kubevirt.io/deprecated
-
- Click Save.
You can create a virtual machine template by editing a YAML file example in the OpenShift Dedicated web console.
Procedure
-
In the web console, click Virtualization
Templates in the side menu. -
Optional: Use the Project drop-down menu to change the project associated with the new template. All templates are saved to the
openshiftproject by default. - Click Create Template.
- Specify the template parameters by editing the YAML file.
Click Create.
The template is displayed on the Templates page.
- Optional: Click Download to download and save the YAML file.
You can enable dedicated resources for a virtual machine (VM) template in the OpenShift Dedicated web console. VMs that are created from this template will be scheduled with dedicated resources.
Procedure
-
In the OpenShift Dedicated web console, click Virtualization
Templates in the side menu. - Select the template that you want to edit to open the Template details page.
- On the Scheduling tab, click the edit icon beside Dedicated Resources.
- Select Schedule this workload with dedicated resources (guaranteed policy).
- Click Save.
6.8. Creating virtual machines from Red Hat images 复制链接链接已复制到粘贴板!
RHEL golden images are published as container disks in a secure registry. The Containerized Data Importer (CDI) polls imports golden images into your cluster and stores them in the openshift-virtualization-os-images project as snapshots or persistent volume claims (PVCs).
RHEL images are automatically updated. You can disable and re-enable automatic updates for these images. For more information, see "Additional resources".
Cluster administrators can enable automatic subscription for RHEL virtual machines in the OpenShift Dedicated web console.
You can create virtual machines (VMs) from operating system images provided by Red Hat by using one of the following methods:
- Create a VM from a template by using the web console.
- Create a VM from an instance type by using the web console.
-
Create a VM from a
VirtualMachinemanifest by using the command line.
Do not create VMs in the default openshift-* namespaces. Instead, create a new namespace or use an existing namespace without the openshift prefix.
6.8.1. About golden images 复制链接链接已复制到粘贴板!
A golden image is a preconfigured snapshot of a virtual machine (VM) that you can use as a resource to deploy new VMs. For example, you can use golden images to provision the same system environment consistently and deploy systems more quickly and efficiently.
6.8.1.1. How do golden images work? 复制链接链接已复制到粘贴板!
Golden images are created by installing and configuring an operating system and software applications on a reference machine or virtual machine. This includes setting up the system, installing required drivers, applying patches and updates, and configuring specific options and preferences.
After the golden image is created, it is saved as a template or image file that can be replicated and deployed across multiple clusters. The golden image can be updated by its maintainer periodically to incorporate necessary software updates and patches, ensuring that the image remains up to date and secure, and newly created VMs are based on this updated image.
6.8.1.2. Red Hat implementation of golden images 复制链接链接已复制到粘贴板!
Red Hat publishes golden images as container disks in the registry for versions of Red Hat Enterprise Linux (RHEL). Container disks are virtual machine images that are stored as a container image in a container image registry. Any published image will automatically be made available in connected clusters after the installation of OpenShift Virtualization. After the images are available in a cluster, they are ready to use to create VMs.
6.8.2. About VM boot sources 复制链接链接已复制到粘贴板!
Virtual machines (VMs) consist of a VM definition and one or more disks that are backed by data volumes. VM templates enable you to create VMs using predefined specifications.
Every template requires a boot source, which is a fully configured disk image including configured drivers. Each template contains a VM definition with a pointer to the boot source. Each boot source has a predefined name and namespace. For some operating systems, a boot source is automatically provided. If it is not provided, then an administrator must prepare a custom boot source.
Provided boot sources are updated automatically to the latest version of the operating system. For auto-updated boot sources, persistent volume claims (PVCs) and volume snapshots are created with the cluster’s default storage class. If you select a different default storage class after configuration, you must delete the existing boot sources in the cluster namespace that are configured with the previous default storage class.
You can configure a custom namespace for boot source images in your cluster by using the OpenShift Dedicated web console.
Procedure
-
In the web console, select Virtualization
Settings. -
On the Cluster tab, select General settings
Templates and images management. - Click Bootable volumes project.
Select a namespace to use for boot source images.
- If you already created a namespace, select it from the Project list.
If you did not create a namespace, scroll to the bottom of the list and click Create project.
- Enter a name for your new namespace in the Name field of the Create project dialog.
- Click Create.
You can configure a custom namespace for boot source images in your cluster by setting the spec.commonBootImageNamespace field in the HyperConverged custom resource (CR).
Prerequisites
-
You installed the OpenShift CLI (
oc). - You created a namespace to use for boot source images.
Procedure
Open the
HyperConvergedCR in your default editor by running the following command:$ oc edit hyperconvergeds.v1beta1.hco.kubevirt.io kubevirt-hyperconverged -n openshift-cnvConfigure the custom namespace by updating the value of the
spec.commonBootImageNamespacefield.Example configuration file:
apiVersion: hco.kubevirt.io/v1beta1 kind: HyperConverged metadata: name: kubevirt-hyperconverged namespace: openshift-cnv spec: commonBootImageNamespace: <custom_namespace> # ...where:
spec.commonBootImageNamespace- Specifies the namespace to use for boot source images.
- Save your changes and exit the editor.
6.9. Cloning VMs 复制链接链接已复制到粘贴板!
You can clone virtual machines (VMs) or create new VMs from snapshots.
Cloning a VM with a vTPM device attached to it or creating a new VM from its snapshot is not supported.
6.9.1. Cloning a VM by using the web console 复制链接链接已复制到粘贴板!
You can clone an existing VM by using the web console.
Procedure
-
Navigate to Virtualization
VirtualMachines in the web console. - Select a VM to open the VirtualMachine details page.
Click Actions.
Alternatively, access the same menu in the tree view by right-clicking the VM.
- Select Clone.
- On the Clone VirtualMachine page, enter the name of the new VM.
- Optional: Select the Start cloned VM checkbox to start the cloned VM.
Optional: In the Volume name policy section, select how cloned persistent volume claims (PVCs) are named:
- Randomize names - The cloned PVC names are randomly generated. This is the default setting.
- Prefix target name - The cloned PVC names use the target VM name as a prefix.
- Click Clone.
You can create a new VM by copying an existing snapshot.
Procedure
-
Navigate to Virtualization
VirtualMachines in the web console. - Select a VM to open the VirtualMachine details page.
- Click the Snapshots tab.
-
Click the Options menu
for the snapshot you want to copy.
- Select Create VirtualMachine.
- Enter the name of the VM.
- Optional: Select the Start this VM after creation checkbox to start the new VM.
Optional: In the Volume name policy section, select how cloned persistent volume claims (PVCs) are named:
- Randomize names - The cloned PVC names are randomly generated. This is the default setting.
- Prefix target name - The cloned PVC names use the target VM name as a prefix.
- Click Create.