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.
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.
The installation is now complete. OpenShift Virtualization operator is now installed successfully and available in Operators.
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.
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.
HyperConverged instance is now created.
Now under Workloads, Virtualization option is available.
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
Am going to name it redhattesttemplate. Template provider as Red Hat
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.
Just leave the default options for Networking, Storage.
Click Create Virtual Machine template
Now that we have virtual machine template ready, click on See virtual machine template details. And click Create Virtual Machine
Mention the Project name (namespace), Virtual Machine Name. And click on Create 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.
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.
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.