Creating virtual machine templates
About virtual machine templates
Preconfigured Red Hat virtual machine templates are listed in the Virtualization → Templates page. These templates are available for different versions of Red Hat Enterprise Linux, Fedora, Microsoft Windows 10, and Microsoft Windows Servers. Each Red Hat virtual machine template is preconfigured with the operating system image, default settings for the operating system, flavor (CPU and memory), and workload type (server).
The Templates page displays four types of virtual machine templates:
Red Hat Supported templates are fully supported by Red Hat.
User Supported templates are Red Hat Supported templates that were cloned and created by users.
Red Hat Provided templates have limited support from Red Hat.
User Provided templates are Red Hat Provided templates that were cloned and created by users.
You can use the filters in the template Catalog to sort the templates by attributes such as boot source availability, operating system, and workload.
You cannot edit or delete a Red Hat Supported or Red Hat Provided template. You can clone the template, save it as a custom virtual machine template, and then edit it.
You can also create a custom virtual machine template by editing a YAML file example.
About virtual machines and boot sources
Virtual machines consist of a virtual machine definition and one or more disks that are backed by data volumes. Virtual machine templates enable you to create virtual machines using predefined virtual machine specifications.
Every virtual machine template requires a boot source, which is a fully configured virtual machine disk image including configured drivers. Each virtual machine template contains a virtual machine 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) are created with the cluster’s default storage class. If you select a different default storage class after configuration, you must delete the existing data volumes in the cluster namespace that are configured with the previous default storage class.
To use the boot sources feature, install the latest release of OKD Virtualization. The namespace openshift-virtualization-os-images
enables the feature and is installed with the OKD Virtualization Operator. Once the boot source feature is installed, you can create boot sources, attach them to templates, and create virtual machines from the templates.
Define a boot source by using a persistent volume claim (PVC) that is populated by uploading a local file, cloning an existing PVC, importing from a registry, or by URL. Attach a boot source to a virtual machine template by using the web console. After the boot source is attached to a virtual machine template, you create any number of fully configured ready-to-use virtual machines from the template.
Creating a virtual machine template in the web console
You create a virtual machine template by editing a YAML file example in the OKD 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
openshift
project 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.
Adding a boot source for a virtual machine template
A boot source can be configured for any virtual machine template that you want to use for creating virtual machines or custom templates. When virtual machine templates are configured with a boot source, they are labeled Source available on the Templates page. After you add a boot source to a template, you can create a new virtual machine from the template.
There are four methods for selecting and adding a boot source in the web console:
Upload local file (creates PVC)
URL (creates PVC)
Clone (creates PVC)
Registry (creates PVC)
Prerequisites
To add a boot source, you must be logged in as a user with the
os-images.kubevirt.io:edit
RBAC role or as an administrator. You do not need special privileges to create a virtual machine from a template with a boot source added.To upload a local file, the operating system image file must exist on your local machine.
To import via URL, access to the web server with the operating system image is required. For example: the Red Hat Enterprise Linux web page with images.
To clone an existing PVC, access to the project with a PVC is required.
To import via registry, access to the container registry is required.
Procedure
In the OKD console, click Virtualization → Templates from the side menu.
Click the options menu beside a template and select Edit boot source.
Click Add disk.
In the Add disk window, select Use this disk as a boot source.
Enter the disk name and select a Source, for example, Blank (creates PVC) or Use an existing PVC.
Enter a value for Persistent Volume Claim size to specify the PVC size that is adequate for the uncompressed image and any additional space that is required.
Select a Type, for example, Disk or CD-ROM.
Optional: Click Storage class and select the storage class that is used to create the disk. Typically, this storage class is the default storage class that is created for use by all PVCs.
Provided boot sources are updated automatically to the latest version of the operating system. For auto-updated boot sources, persistent volume claims (PVCs) are created with the cluster’s default storage class. If you select a different default storage class after configuration, you must delete the existing data volumes in the cluster namespace that are configured with the previous default storage class.
Optional: Clear Apply optimized StorageProfile settings to edit the access mode or volume mode.
Select the appropriate method to save your boot source:
Click Save and upload if you uploaded a local file.
Click Save and import if you imported content from a URL or the registry.
Click Save and clone if you cloned an existing PVC.
Your custom virtual machine template with a boot source is listed on the Catalog page. You can use this template to create a virtual machine.
Virtual machine template fields for adding a boot source
The following table describes the fields for Add boot source to template window. This window displays when you click Add source for a virtual machine template on the Virtualization → Templates page.
Name | Parameter | Description | |
---|---|---|---|
Boot source type | Upload local file (creates PVC) | Upload a file from your local device. Supported file types include gz, xz, tar, and qcow2. | |
URL (creates PVC) | Import content from an image available from an HTTP or HTTPS endpoint. Obtain the download link URL from the web page where the image download is available and enter that URL link in the Import URL field. Example: For a Red Hat Enterprise Linux image, log on to the Red Hat Customer Portal, access the image download page, and copy the download link URL for the KVM guest image. | ||
PVC (creates PVC) | Use a PVC that is already available in the cluster and clone it. | ||
Registry (creates PVC) | Specify the bootable operating system container that is located in a registry and accessible from the cluster. Example: kubevirt/cirros-registry-dis-demo. | ||
Source provider | Optional field. Add descriptive text about the source for the template or the name of the user who created the template. Example: Red Hat. | ||
Advanced Storage settings | StorageClass | The storage class that is used to create the disk. | |
Access mode | Access mode of the persistent volume. Supported access modes are Single User (RWO), Shared Access (RWX), Read Only (ROX). If Single User (RWO) is selected, the disk can be mounted as read/write by a single node. If Shared Access (RWX) is selected, the disk can be mounted as read-write by many nodes. The
| ||
Volume mode | Defines whether the persistent volume uses a formatted file system or raw block state. Supported modes are Block and Filesystem. The |