Sunday, December 22, 2024
Containers Kubernetes Linux OpenShift Red Hat Virtualization

Running virtual machines in OpenShift

This is a quick and interesting session to show how easy is to install a virtual machine on OpenShift.  OpenShift allows us to install virtual machines using Operators. We can have vms and containers running in parallel.  This is a huge benefit, as some of the legacy applications which cannot be containerised can be deployed in OpenShift using virtualization Operator.

We can also directly migrate (lift & shift) an existing production virtual machine to the OpenShift cluster.  As everything is stored in persistent volumes, we can migrate a VM anytime to another cluster.  Think of an application running in a container in the cluster connecting to a virtual machine running in the same cluster. Say may be the backend database is running in the VM, and the containerised application can easily access the database which is hosted in the VM.
Am not going to more technical details here.  Lets get started.

Am now connected to OpenShift console. Am using OpenShift 4.7. At the moment, we do not have “virtualization” option available under Workloads. Lets go to Operators -> OperatorHub and search for “Openshift virtualization”. Click install.

Operators tab in Red Hat OpenShift console
OpenShift Virtualization Operator

In the Install Operator select the default options and click install. Note that the virtualization operator will be installed on a new namespace openshift-cnv, which will also be automatically created by this step.

OpenShift Virtualization Operator install page
OpenShift Virtualization installation in progress

The installation is now complete. OpenShift Virtualization operator is now installed successfully and available in Operators.

OpenShift Virtualization Operator installation succeeded

Click on the OpenShift Virtualization operator. And now we have to create HyperConverged instance. HyperConverged is required for installing virtual machine. You can read more on Red Hat® Hyperconverged Infrastructure for Virtualization here.

Openshift HyperConverged installation option
Openshift HyperConverged installation page

Leave the default options and click install. Note that am not creating a Storage Class Name here, however I would suggest creating a Storage Class Name & when creating Storage do mention this name.

Openshift HyperConverged installation page 2

HyperConverged instance is now created.

Openshift HyperConverged installation succeeded

Now under Workloads, Virtualization option is available.

Virtualization option is now available under Workloads in the openshift console

Now in Virtualization, am going to create a custom Template using the Red Hat Enterprise Linux 7,0+VM. Click on the Create new Template from

under virtualization templates, select "Create new Template from" on the template Red Hat Enterprise Linux 7.0+VM

Am going to name it redhattesttemplate. Template provider as Red Hat

on Create Virtual Machine template page fill in details like name, operating system

For the Boot Source , select Import via URL (creates PVC). And mention the URL for the image. I have provided the download link for Red Hat 7.9 KVM image. You can use any other templates like CentOS, Fedora or Microsoft Windows, and mention the corresponding URL for download. Remember this is one way of uploading the image, you can also create your own PVC and PV and upload the disk image in prior to this setup. You can also clone the image for an existing virtual machine running in OpenShift.

on Create Virtual Machine template page fill in details like Boot source and image url

Just leave the default options for Networking, Storage.

on Create Virtual Machine template page leave the default option for Network interfaces
on Create Virtual Machine template page leave the default option for Advanced tab

Click Create Virtual Machine template

on Create Virtual Machine template page recheck the final view of the selections and click Create virtual machine template
virtual machine template is successfully created

Now that we have virtual machine template ready, click on See virtual machine template details. And click Create Virtual Machine

under the newly created template, on actions select Create Virtual Machine

Mention the Project name (namespace), Virtual Machine Name. And click on Create virtual machine.

on create virtual machine from template page, fill in details like Project name, virtual machine name and click Create virtual machine
Successfully created virtual machine

You can see the the Red Hat VM image is now being downloaded for the installation to start. Remember I skipped the part showing creation of Persistent Volume, as I cannot have too many screenshots here. By default for small virtual machine is will create a PVC for 15GB for storage. All you have to do it go to PV and create a 15GB storage, and make sure the created storage is bound to the PVC.

on the newly created virtual machine page,  Red Hat VM image is now being downloaded for the installation to start
 Red Hat VM image is now being downloaded, 53% complete
 Red Hat VM image is now downloaded and the installation is complete.

The install is now complete, and now if you go to Console tab, you can see Red Hat Linux is running and we can connect.

On the new virtual machine, select the Console tab and you can see virtual machine is now ready and you can connect
run few commands in the newly created virtual machine

All these tasks can be performed using OpenShift CLI as well. Using oc commands we can automate VM creation, using custom yaml files. Here are some commands which I use regularly.

oc get vm #Lists the virtual machines in the project
oc get vmi #List all running virtual machine instances
oc delete vmi #To delete a vmi
oc describe vmi #To describe a vmi

That’s all about installing a Virtual machine in OpenShift. Keep visiting itech-blog.com, we have more technical articles coming every week.

Back To Top
error: Content is protected !!