OpenShift Virtualization 2.6 includes Operating System (OS) templates for recent versions of Fedora, Red Hat Enterprise Linux, CentOS, and Microsoft Windows. This list of operating systems represents the only guest operating systems officially supported by Red Hat on OpenShift; however, because of the power of the underlying KVM infrastructure, any operating system supported by KVM may be run with the right definitions.

In this article, I will demonstrate adding a new operating system (Ubuntu 18.04) to OpenShift Virtualization, provide a default OS image for automatic cloning, and then show how easy it is to start up a new VM as a regular OpenShift user. I should add that any new operating systems added in this manner do not carry the support of Red Hat, which includes updates and possible security fixes. It is the responsibility of the end user to ensure custom templates are updated as necessary.

Adding New OS Templates

In OpenShift Virtualization, the available list of operating systems is determined by a set of templates in the Openshift namespace. These templates are also present in the upstream KubeVirt project with a couple additional operating systems, one of which is Ubuntu 18.04. The upstream templates may be downloaded in one YAML file from the releases section of the common-templates repository under the kubevirt project on GitHub:

curl -OL https://github.com/kubevirt/common-templates/releases/download/v0.13.1/common-templates-v0.13.1.yaml

Note: The Ubuntu 18.04 release codename is actually Bionic Beaver, but due to a hard-coded value in the common-templates repository, it instead gets listed as Xenial Xerus, which actually is a much older Ubuntu 16.04 LTS release. You can safely use Bionic (or newer) OS images to create VMs from this template, even with the mislabel. Uploading the base OS image will be described later in this blog.

The downloaded templates require one modification to work with OpenShift Virtualization. The KubeVirt project uses kubevirt-os-images as the namespace for base OS images, but in OpenShift Virtualization, this is openshift-virtualization-os-images. We could simply create the kubevirt-os-images namespace and import the templates, but some work has gone into OpenShift Virtualization ensuring regular users may access images in openshift-virtualization-os-images for cloning:

sed -i 's/kubevirt-os-images/openshift-virtualization-os-images/' common-templates-v0.13.1.yaml

Now the templates may be imported into the openshift namespace, but there is one challenge. Many of the templates conflict with ones already included by CNV. You could use oc with the create verb to error out on already existing templates while accepting all the new ones, but this has the drawback of adding multiple extra templates. Instead, we will split up the templates into separate files using a handy GNU utility called csplit which is likely already on your system. The following parameters work on RHEL and Fedora versions of csplit, but notably differ on Apple MacOS systems, so consult your documentation if needed. There are 80 separate templates in the 0.13.1 common-templates pack I link to here, so if you are not already working in a subdirectory, you may wish to create one and change directory to it now:

mkdir templates
mv common-templates-v0.13.1.yaml templates
cd templates

To split on the “---” separator between each template, run:

csplit --prefix 'template' \
  --suffix '%02d.yaml' \
  common-templates-v0.13.1.yaml \
  '/^---$/' '{*}'

Find the relevant Ubuntu templates using grep:

grep -l ubuntu *.yaml

common-templates-v0.13.1.yaml
template69.yaml
template70.yaml
template71.yaml
Template72.yaml

Check the names:

grep -m 1 name: template{69..72}.yaml
template69.yaml:  name: ubuntu-desktop-large
template70.yaml:  name: ubuntu-desktop-medium
template71.yaml:  name: ubuntu-desktop-small
template72.yaml:  name: ubuntu-desktop-tiny

Apply the templates to OpenShift Virtualization:

for templ in template{69..72}.yaml
do
  oc -n openshift create -f $templ
Done
template.template.openshift.io/ubuntu-desktop-large created
template.template.openshift.io/ubuntu-desktop-medium created
template.template.openshift.io/ubuntu-desktop-small created
template.template.openshift.io/ubuntu-desktop-tiny created

Notice there is a separate template for each permutation of profile and flavor.

Add a Boot Source Image

With the templates created, you may now create Ubuntu virtual machines at will, but we will add one more step. Preparing a Boot Source Image for the newly added OS will speed up VM creation by cloning that image whenever a new VM with that OS is requested:

We will need a cloneable, cloud-ready OS image for our Ubuntu Bionic VMs. Canonical provides cloud images for Ubuntu Bionic at https://cloud-images.ubuntu.com/bionic/current/. OpenShift Virtualization requires disks in either QCOW2 or RAW format, so I selected a QCOW2 for the amd64 architecture: http://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img. Some operating systems do not provide conveniently pre-installed operating system images for cloud use; in that case, a VM should be created with a blank disk, the operating system installed from ISO, prepared for cloning, and optionally set up with cloud-init and the qemu guest agent. As this is beyond the scope of this blog, this is left as an exercise for the user.

As Canonical provides usable images to download from a public URL, we will have OpenShift Virtualization download the Bionic Beaver cloud image and populate a boot source image for us. Log in as an admin user and browse to the Workloads -> Virtualization -> Templates. Find the entry for Ubuntu 18.04, and click on Add source.

Under Boot source type, select Import via URL. (Feel free to explore the other options; you may also upload from your local file system, clone an existing PVC, or even import a containerized disk from a container registry.) Paste in the URL for the latest Ubuntu Bionic QCOW2 image, and click Save and Import. Other options may be left as default. The cloud image (as of January 2021) requires only 2.2 GiB expanded, so the default of 20GiB PVC will leave plenty of space for additional software and data:

You will be returned to the operating system templates list, and the Boot source entry for Ubuntu 18.04 should change to Preparing PVC then to Importing:

You can monitor the upload by viewing its DataVolume in the openshift-virtualization-os-images namespace:

oc -n openshift-virtualization-os-images get dv ubuntu
NAME     PHASE              PROGRESS   RESTARTS   AGE
ubuntu   ImportInProgress   78.34%                7m12s

Once the upload reaches 100%, the Boot Source will change to Available. Log in as a regular user, navigate to Workloads -> Virtualization, and select a Project. I use sandbox for my example. Click Templates, scroll to Ubuntu 18.04, and click the Create button. OpenShift Virtualization will warn that the template does not have an annotation specifying its support level. This may be safely ignored or fixed as your organization requires.

The Create Virtual Machine from template wizard appears. For demonstration purposes, all the defaults are fine:

Click the buttons for Create, then See virtual machine details.

Once the disk is cloned and the VM starts, you should be able to log in via the Console tab: