Abstract
| Goal |
Create and manage templates to provision virtual machines. |
| Objectives |
|
| Sections |
|
| Lab |
|
RHOCP provides resources to help create and administer workload objects in a cluster. One of these resources is preconfigured templates. Templates contain default parameters that you can customize according to your needs. RHOCP provides templates for several resource types, including network interfaces, PVs, and VMs.
Red Hat OpenShift Virtualization provides a catalog of preconfigured templates to create a virtual machine and its resources. Templates are available for different versions of Red Hat Enterprise Linux, CentOS, Fedora, Microsoft Windows 10 and 11, and Microsoft Windows Servers.
Red Hat provides virtual machine templates that are preconfigured with the operating system image, default settings for the operating system, workload type, and flavor, which specifies CPU and memory resources.
Preconfigured templates include changeable fields to meet your VM's needs. The default parameters suggest a basic configuration that works with any VM. However, if you customize the VM configuration, then some important considerations apply:
This field indicates the source of the image to create your VM, and includes the following options:
: Clone an existing PVC in the cluster to create a PVC.
: Create a PVC by importing content from a container registry.
: Create a PVC by importing content from a URL with an HTTP or an S3 endpoint.
: Create a PVC by uploading a new file to a PVC.
: Create a blank PVC.
This field indicates the flavor, or size, of your VM in terms of CPU and memory. Templates from Red Hat indicate the size of the provisioned VM with the following options:
: Creates a VM with 1 CPU and 1 GiB memory; recommended for testing VM creation.
: Creates a VM with 1 CPU and 2 GiB memory; this option is the default for any preconfigured template.
: Creates a VM with 1 CPU and 4 GiB memory; appropriate for code testing or to store basic application resources.
: Creates a VM with 2 CPU and 8 GiB memory; recommended for systems that require heavy resource consumption.
: Specify custom values of CPU and memory for your VM.
In templates from Red Hat OpenShift Virtualization, you can no longer change the flavor. The template designations for usage and size determine how much memory and CPU are provisioned and can be changed when configuring parameters.
Three instance types are available on Red Hat OpenShift, each with its own variations of CPU and memory:
: The CX Series provides exclusive compute resources for compute-intensive applications. CX is the abbreviation of "Compute Exclusive". The exclusive resources are given to the compute threads of the VM. To ensure these exclusive compute resources, some additional cores (depending on the number of disks and NICs) are requested to offload the I/O threading from cores that are dedicated to the workload. In addition, in this series, the NUMA topology of the used cores is provided to the VM.
: The GN Series provides instance types for VMs with attached NVIDIA GPU resources. GN is the abbreviation of "GPU NVIDIA". This series is intended for VMs that consume GPUs from the NVIDIA GPU Operator, which is available on OpenShift via OperatorHub.
: The M Series provides resources for memory-intensive applications. M is the abbreviation of "Memory".
Navigate to → to view all the available instance types on Red Hat OpenShift.
For more information about instance types, refer to the Red Hat OpenShift Virtualization documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/virtualization/index#virt-creating-vms-from-instance-types
This field indicates the workload type for your VM, and includes the following options:
: A configuration for a desktop system that prioritizes VM density over guaranteed VM performance. Red Hat recommends VMs with this configuration.
: The default option for any preconfigured template, and compatible with various server workloads. This option balances performance and prioritizes VM density over VM performance.
: Optimized for high-performance or high-consumption workloads. This option prioritizes guaranteed VM performance over VM density.
A preconfigured Linux-based template has two partitions by default, cloud-init and root disk.
However, you can configure additional disks.
Each field has several available options for customizing your template:
: You can create or import a disk from an existing or blank PVC, from an external source such as a container registry or URL, or by using a container in a registry that is accessible from the cluster.
: You can customize the storage type, such as a disk or CD-ROM, according to the needs of your VM.
: You can select the communication interface of your disk based on compatibility standards and the intended performance of your VM. The available options are virtio, SATA, or SCSI.
: Select the storage class for the disk. The storage profile sets the optimized access mode and the volume mode for the storage class.
: You can customize the disk's access mode, and override the default storage profile settings. The available access modes are , , or .
: You can choose between and storage volume modes for your VM, depending on the selected storage class.
VMs must have a PVC with a shared ReadWriteMany (RWX) access mode to enable live migration.
Red Hat provides templates with a default network interface that is connected to the pod network. You can configure additional network interfaces for your VM. For each field, you have several options available to customize your template:
: You can choose either virtio or e1000e, based on your VM's needs and required performance.
The virtio model is optimized for performance, and most Linux distributions support it.
Additional drivers are needed for Windows VMs.
Although most operating systems, including Windows, support the e1000e model, its performance is slower than the virtio model.
: You can select from a list of available network attachment definitions to connect to additional networks.
Additional networks must use the bridge binding method.
: You can select from a list of binding methods.
You must use the masquerade binding method on the default pod network.
Additional networks must use the bridge binding method.
: You can specify a custom MAC address for the network interface. MAC addresses are automatically assigned unless you specify a custom address.
In this field, you configure cloud-init on compatible systems, add authorized SSH keys, or configure Sysprep for Microsoft Windows machines.
Both cloud-init and sysprep install tools and packages, configure users and passwords, and manage system applications.
For more information on the cloud-init modules, refer to Red Hat support for cloud-init at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_and_managing_cloud-init_for_rhel_8/index
The Containerized Data Importer (CDI) is an add-on that manages persistent storage for VMs in OpenShift Virtualization.
With CDI, you can import, upload, and clone existing PVCs for your VMs.
CDI provides a custom resource definition (CRD) for DataVolume objects that orchestrate the import, clone, and upload operations that are associated with an underlying PVC.
Data volumes are integrated into your OpenShift cluster when you install the OpenShift Virtualization operator, and prevent a VM from starting until its underlying PVC is ready.
With OpenShift Virtualization, you can create a VM from a data volume, including cloning an existing PVC as a new data volume or uploading a local disk image.
You can use a data volume template to create a VM from an existing PVC by using the OpenShift web console or from the command line. Cloning the PVC of an existing VM in a different namespace produces the following configuration for a new VM:
Additional permissions are required to clone data volumes across namespaces. For more information about the required permissions, refer to the Enabling user permissions to clone data volumes across namespaces section at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/virtualization/index#virt-enabling-user-permissions-to-clone-datavolumes
apiVersion: kubevirt.io/v1 kind: VirtualMachine metadata:name: vm-clone-pvclabels: kubevirt.io/vm: vm-clone-pvc
namespace: backup-vmsspec: running: false template: metadata: labels: kubevirt.io/vm: vm-clone-pvc spec: domain: cpu: cores: 1 devices: disks: - disk: bus: virtio name: root-disk resources: requests: memory: 2Gi terminationGracePeriodSeconds: 0 volumes: - dataVolume:
name: new-pvc-from-clonename: root-disk
dataVolumeTemplates:- apiVersion: cdi.kubevirt.io/v1beta1 metadata:
name: new-pvc-from-clonespec: pvc: accessModes: - ReadWriteOnce resources: requests:
storage: 10Gisource: pvc:
namespace: storage-vm![]()
name: database-storage-pvc
Name of the new VM. | |
Namespace where the new VM is created. | |
Name of the new PVC that is created from the original PVC. | |
Data volume template to specify the new PVC to create. | |
If your PVC uses the Filesystem volume mode, the requested storage must be larger than the storage source to account for file system overhead data. | |
Source namespace where the original VM and PVC exists. | |
Name of the source PVC to create the VM. |
You can apply the completed YAML manifest to you cluster with the oc create -f or oc apply -f commands.
[user@host ~]$ oc create -f virtualmachine-vm-example-clone.yaml
virtualmachine.kubevirt.io/vm-clone-pvc createdYou can create VMs from preconfigured templates in the OpenShift web console. The templates provide default parameters that suggest a basic configuration for your VM's guest operating system. The following example shows how to create a Red Hat Enterprise Linux 8.0 VM from the web console by using a preconfigured template:
From the web console, navigate to → , and click the Red Hat Enterprise Linux 8.0 VM template.
Click .
Complete the form and provide a name for your VM. Select the option in the list. For RHEL, click the link below the input box, log in with your credentials, and then copy the URL of the KVM Guest image download. Leave the form fields under with their default values.
A username and password are created by default.
After creating the VM, you can examine the credentials that the cloud-init service generates, by navigating to → .
Click the tab and then click above your VM console.
Click .
Confirm that the default interface is connected to Pod networking with a Masquerade bonding method in Network interfaces. Leave the disks with their default values. Review the settings of your VM and click .
Navigate to → and click the name of your VM to see its status.
For more information, refer to the Red Hat OpenShift Virtualization documentation at https://access.redhat.com/documentation/en-us/openshift_container_platform/4.14/html-single/virtualization/index