This is a cache of https://docs.openshift.com/container-platform/4.10/virt/vm_templates/virt-creating-vm-template.html. It is a snapshot of the page at 2024-11-27T17:58:12.270+0000.
Creating virtual machine templates - Virtual machine templates | Virtualization | OpenShift Container Platform 4.10
×

About virtual machine templates

Preconfigured Red Hat virtual machine templates are listed in the VirtualizationTemplates 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.

Due to differences in storage behavior, some virtual machine templates are incompatible with single-node OpenShift. To ensure compatibility, do not set the evictionStrategy field for any templates or virtual machines that use data volumes or storage profiles.

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 OpenShift Virtualization. The namespace openshift-virtualization-os-images enables the feature and is installed with the OpenShift 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 OpenShift Container Platform web console.

Procedure
  1. In the web console, click VirtualizationTemplates in the side menu.

  2. Click Create Template.

  3. Specify the template parameters by editing the YAML file.

  4. Click Create.

    The template is displayed on the Templates page.

  5. 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
  1. In the OpenShift Container Platform console, click VirtualizationTemplates from the side menu.

  2. Click the options menu beside a template and select Edit boot source.

  3. Click Add disk.

  4. In the Add disk window, select Use this disk as a boot source.

  5. Enter the disk name and select a Source, for example, Blank (creates PVC) or Use an existing PVC.

  6. 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.

  7. Select a Type, for example, Disk or CD-ROM.

  8. 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.

  9. Optional: Clear Apply optimized StorageProfile settings to edit the access mode or volume mode.

  10. Select the appropriate method to save your boot source:

    1. Click Save and upload if you uploaded a local file.

    2. Click Save and import if you imported content from a URL or the registry.

    3. 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 VirtualizationTemplates 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 kubevirt-storage-class-defaults config map provides access mode defaults for data volumes. The default value is set according to the best option for each storage class in the cluster.

Shared Access (RWX) is required for some features, such as live migration of virtual machines between nodes.

Volume mode

Defines whether the persistent volume uses a formatted file system or raw block state. Supported modes are Block and Filesystem. The kubevirt-storage-class-defaults config map provides volume mode defaults for data volumes. The default value is set according to the best option for each storage class in the cluster.

Marking virtual machine templates as favorites

You can mark frequently used templates as favorites.

Procedure
  1. In the OpenShift Container Platform console, click VirtualizationTemplates from the side menu.

  2. Click the star icon next to a template to mark it as a favorite.

    Favorite templates are displayed at the top of the template list.

Filtering the list of virtual machine templates by providers

In the Templates tab, you can use the Search by name field to search for virtual machine templates by specifying either the name of the template or a label that identfies the template. You can also filter templates by the provider, and display only those templates that meet your filtering criteria.

Procedure
  1. In the OpenShift Virtualization console, click WorkloadsVirtualization from the side menu.

  2. Click the Templates tab.

  3. To filter templates, click Filter.

  4. Select the appropriate checkbox from the list to filter the templates: Red Hat Supported, user Supported, Red Hat Provided, and user Provided.