Deploy a Virtual Machine (VM) with KubeVirt
Objectives
This tutorial aims to provide clear steps for deploying and configuring virtual machines (VMs) in KubeVirt on your OpenShift cluster.
Two scenarios will be covered:
- Creating and deploying a Fedora virtual machine with NGINX.
- Creating a customized Windows Server 2022 virtual machine with IIS.
Known Limitations
- Missing templates in the OpenShift catalog can be retrieved from the official KubeVirt repository:
https://github.com/kubevirt/common-templates/tree/master. - Deployed virtual machines must be compatible with KubeVirt (virtio drivers, disk formats, etc.).
- Configuration depends on the privileges assigned within the corresponding OpenShift project.
- Advanced network configuration (for example: port forwarding) is required to access services hosted on the VMs.
Key Benefits
- Flexibility: Enables direct deployment of VMs from OpenShift, simplifying hosting of applications requiring a VM environment.
- Windows and Linux Compatibility: Supports Fedora and Windows Server.
- Easy Integration: Leverages built-in KubeVirt and OpenShift services (PVC, port forwarding, ingress).
Software Versions
- OpenShift: v4.15 or later
- Kubernetes: v1.24 or later
- KubeVirt: v0.56 or later
- VMware Workstation (for Windows Server conversion): Version 16 or later
- qemu-img: Version 6.1 or later
Prerequisites
Before you begin, ensure that:
- KubeVirt is correctly installed in OpenShift.
- You have administrator access to the OpenShift project where the VM will be deployed.
- You have SSH keys to access the Fedora virtual machine.
- The following tools are installed and configured:
- OpenShift CLI (
oc) - qemu-img (for converting disks to the
qcow2format)
- OpenShift CLI (
- You have access to the Azure blob where the Windows Server image will be stored.
Demonstration Plan
Overview of Steps
- Deploy a Fedora VM with NGINX.
- Deploy a Windows Server VM with IIS.
- Configure network access (SSH for Fedora, RDP for Windows).
- Verify that the services (NGINX/IIS) are accessible from your browser.
Required Files
You will need the following files for deployment:
- ssh-port-forward.yaml: Manifest to configure SSH access to the Fedora VM.
- nginx-expose.yaml: Manifest to expose NGINX in OpenShift.
- rdp-port-forward.yaml: Manifest to configure RDP access to the Windows VM.
- iis-expose.yaml: Manifest to expose IIS in OpenShift.
Deployment Process
Step 1: Deploy a Fedora VM with NGINX
-
Create a Fedora VM in OpenShift:
- Go to the Administrator view in OpenShift and select Virtualization.
- Navigate to the Catalog tab and click Create a new VM.
- Fill in the following settings:
- Operating System: Fedora
- Instance Type: U Series with 2 CPUs and 8 GB RAM
- VM Name:
fedora-nginx
- Add your public SSH key (
mysshkey) to enable access to the VM. - Click Create.
-
Set up CLI access to OpenShift:
-
Run the following command to work in the correct OpenShift project:
oc project demokubevirt -
Log in to the OpenShift API:
oc login --server=api-ocp01-{your-id}.paas.cloud-temple.com --web
-
-
Configure SSH access to the Fedora VM:
-
Apply the manifest to set up SSH port forwarding:
oc apply -f ssh-port-forward.yaml -
Forward the port locally from your machine:
oc port-forward svc/fedora-service-ssh 2222:22 -
Connect to the VM from a new terminal:
ssh cloud-user@127.0.0.1 -p 2222 -o StrictHostKeyChecking=no
-
-
Deploy NGINX on Fedora:
-
Connect to the VM as described above and run the following commands:
sudo dnf update -y
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx -
Verify that NGINX is running correctly:
sudo systemctl status nginx
-
-
Expose NGINX in OpenShift:
-
Apply the following manifest to expose the service:
oc apply -f nginx-expose.yaml
-
-
Access the NGINX website:
- Open your browser and navigate to:
https://nginx-fedora.apps-ocp01-{your-id}.paas.cloud-temple.com.
- Open your browser and navigate to:
Step 2: Deploy a Windows Server VM with IIS
-
Create a custom Windows image:
-
Deploy a Windows Server VM in VMware Workstation with the following settings:
- Drivers: Virtio, SATA, e1000e, UEFI.
- Run Sysprep.
- Export the image in OVF format.
-
Convert the disk image to qcow2 format using
qemu-img:qemu-img convert -f vmdk -O qcow2 WindowsServer2022-OC-disk1.vmdk output.qcow2 -
Upload the converted image to an Azure blob and retrieve the SAS key.
-
-
Create a custom template for Windows Server in KubeVirt:
- From the Catalog tab in OpenShift, create a template with the following parameters:
- 2 CPUs, 8 GB RAM, 100 GB storage.
- Configure storage to use virtio.
- Use the blob URL as the disk source and include the SAS key.
- From the Catalog tab in OpenShift, create a template with the following parameters:
-
Configure IIS on Windows:
-
Connect to the VM (administrator password, keyboard, etc.).
-
Install IIS via the console:
Install-WindowsFeature -name Web-Server -IncludeManagementTools
-
-
Configure RDP access:
-
Apply the following YAML files:
oc apply -f rdp-port-forward.yaml
oc apply -f iis-expose.yaml -
Forward the RDP port locally:
oc port-forward svc/windows-service-rdp 2222:3389 -
Connect using your RDP client:
mstsc -v 127.0.0.1:2222
-
-
Access the IIS website:
- In your browser, navigate to:
https://iis-windows.apps-ocp01-{your-id}.paas.cloud-temple.com.
- In your browser, navigate to:
Validation Criteria
- The Fedora and Windows Server VMs are deployed without errors.
- SSH access to Fedora and RDP access to Windows work via port forwarding.
- The NGINX and IIS services are publicly accessible via the configured URLs.
Conclusion
This guide has enabled you to deploy Fedora and Windows Server virtual machines on KubeVirt with OpenShift. You've learned how to configure network access (SSH/RDP) and expose web services. These steps can be replicated for various scenarios requiring VMs within the OpenShift Cloud Temple PaaS environment. 🚀