Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

How to switch Red Hat OpenShift Virtualization from hardware virtualization to software emulation

September 17, 2020
Bryant Son
Related topics:
ContainersDevOpsLinuxKubernetesOperatorsVirtualization
Related products:
Red Hat OpenShift

Share:

    DISCLAIMER: The following setup is not supported by Red Hat, even for dev/test/sandbox environments. It is only meant to demonstrate the technical possibilities. See Configuring your cluster for OpenShift Virtualization for information. In addition, Tiny Code Generator (TCG) is not supported or tested by Red Hat.

    OpenShift Virtualization is a feature of Red Hat OpenShift Container Platform (OCP) and OpenShift Kubernetes Engine that allows you to run and manage virtual machine workloads alongside container workloads. Based on the open source project KubeVirt, the goal of OpenShift Virtualization is to help enterprises move from a VM-based infrastructure to a Kubernetes-and-container-based stack, one application at a time.

    In my previous article, I showed you how to set up and enable OpenShift Virtualization running on Amazon Web Services Elastic Compute Cloud (AWS EC2). In that article, I noted that OpenShift Virtualization looks for hardware virtualization by default, which requires a bare-metal server instance. If you are running OpenShift on AWS EC2, as I do, then you have to enable software emulation over the default hardware virtualization. Otherwise, you need a bare-metal instance from the public cloud provider or a pure bare-metal solution.

    In this article, I show you how to switch OpenShift Virtualization from its default of hardware virtualization to QEMU-based software emulation. You will then be able to start and operate a virtual machine through OpenShift Virtualization, even in a non-bare metal instance such as AWS EC2.

    Hardware versus software virtualization

    By default, OpenShift Virtualization uses the Linux Kernel Virtual Machine (KVM), which is a full-virtualization solution for Linux on x86 hardware. KVM uses the virtualization extensions Intel VT or AMD-V to enable device emulation.

    For performance reasons, hardware virtualization, where the virtual machine uses the hardware directly, is almost always preferable over software virtualization in real-world implementations. Modern CPUs, memory, and hardware components are designed with hardware virtualization in mind. However, hardware virtualization is not always available, especially because it requires a bare-metal instance (physical server) to work as opposed to the approach taken by virtual servers that use cloud computing or shared hardware.

    As an example, the default AWS EC2 uses KVM for AWS Nitro System-based instance types but does not expose nested virtualization, where one virtualized environment runs inside another one. Unless it is a pure bare-metal server, nested virtualization is a work-around, though OpenShift Virtualization can use the popular open source machine emulator and virtualizer, QEMU with its Tiny Code Generator (TCG) to set this configuration up in AWS EC2.

    If you tried to start a virtual machine running on OpenShift on top of AWS EC2 and provisioned with OpenShift Virtualization, using the default hardware emulation in a non-bare-metal instance would fail. In that case, you would see a pod error when you tried to start the new virtual machine, as shown in Figure 1.

    VM start fails if the default hardware emulation is used in non-baremetal instance
    VM start fails if the default hardware emulation is used in non-baremetal instance
    Figure 1: A virtual machine started with OpenShift Virtualization fails if the default hardware emulation is used in a non-bare-metal instance.

    The error message in Figure 1 reads, "0/6 nodes are available: 1 insufficient devices.kubevirt.io/vhost-net." Receiving such an error in Red Hat OpenShift usually suggests that you need to adjust your OpenShift resource limits such as the quota, limit-range, or instance-node capacities. With OpenShift Virtualization, the first question you have to ask is whether your OpenShift instance is or is not running on a bare-metal server.

    Unless you are able to provision Red Hat OpenShift on a bare-metal instance, this approach is only meant for sandbox and testing environments. Running VMs through OpenShift Virtualization's software emulation method can result in performance degradation—which can be fixed by later switching back to hardware virtualization. Software emulation is the process of artificially executing code intended for a "foreign" architecture and hardware profile by converting it to the assembly language that the CPU in use understands. Luckily for us, KVM provides an easier way to switch to software emulation, based on the popular open source machine emulator and virtualizer, QEMU.

    Note: See the difference between virtualization and emulation to better understand the difference between hardware virtualization and software emulation.

    Prerequisites

    By following the examples in this article, you will learn how to switch your OpenShift container-native virtualization configuration from the default of hardware virtualization to software emulation. All it takes is changing one property field—it really is that easy. To follow the instructions, you must meet the following prerequisites in your development environment:

    • Have Red Hat OpenShift 4.4 installed on a non-bare-metal instance like AWS EC2.
    • Have OpenShift Virtualization enabled and available in the default namespace, openshift-cnv.

    Note: See my previous article for a guide to enabling OpenShift Virtualization.

    Step 1: Locate kubevirt-config in openshift-cnv

    Our first step is to locate the ConfigMap called kubevirt-config, which we will use to switch the default hardware virtualization mechanism to software emulation. The kubevirt-config file is located in the default OpenShift Virtualization namespace, openshift-cnv.

    If you are using an OpenShift CLI, open the OpenShift Virtualization project with the command oc project openshift-cnv. Then, use oc get cm to locate kubevirt-config, as shown in Figure 2.

    ConfigMap "kubevirt-config" can make us to switch to software emulation
    ConfigMap "kubevirt-config" can make us to switch to software emulation
    Figure 2: Use the OpenShift CLI to locate the kubevirt-config file.

    Another option is to use OpenShift's web console to locate the ConfigMap. Make sure that you are in the openshift-cnv namespace, then click Workloads -> Config Map, as shown in Figure 3.

    You can also find kubevirt-config in Openshift web console
    You can also find kubevirt-config in Openshift web console
    Figure 3: Locate kubevirt-config in OpenShift's web console.

    Click ConfigMap to view the YAML file for kubevirt-config, which is shown in Figure 4.

    YAML configuration file for CM kubevirt-config in web console
    YAML configuration file for CM kubevirt-config in web console
    Figure 4: The YAML file for the kubevirt-config.

    Step 2: Update the kubevirt-config file for software emulation

    Once you locate the kubevirt-config file, all you have to do is to add a new property to the file, instructing OpenShift Virtualization to use software emulation rather than hardware virtualization. If you are using an OpenShift CLI, you can execute oc edit cm/kubevirt-config to edit the ConfigMap, as shown in Figure 5.

    "oc edit cm kubevirt-config" to modify the Config Map in CLI
    "oc edit cm kubevirt-config" to modify the Config Map in CLI
    Figure 5: Execute oc edit cm kubevirt-config to modify the ConfigMap in the CLI.

    Once you are inside the ConfigMap's YAML file, add a new property called debug.useEmulation under data, then set the value to true, as shown in Figure 6.

    Add "debug.useEmulation" under "data" and set to "true"
    Add "debug.useEmulation" under "data" and set to "true"
    Figure 6: Add the new property debug.useEmulation.

    When you are done with these changes, save the file. That's all there to it! The CNV Operator automatically fetches the ConfigMap and applies the change.

    Step 3: Start the virtual machine using software emulation

    Before we finish, let's test the change to software emulation. Return to the default CNV project namespace and create a new virtual machine. You should not see the previous error; instead, you should see that the VM is starting, as shown in Figure 7.

    VM is successfully getting started
    VM is successfully getting started
    Figure 7: Confirmation that the virtual machine is starting.

    As shown in Figure 8, the virtual machine's status will change to running.

    VM is finally up and running
    VM is finally up and running
    Figure 8: Confirmation that the VM is running.

    You can also see that the server has successfully started through the OpenShift web console screen, as shown in Figure 9. Alternatively, you could use KubeVirt's virtctl tool (which I introduced in my previous article) to connect to the VM.

    You can monitor the new VM getting started in the web console
    You can monitor the new VM getting started in the web console
    Figure 9: Monitor the new virtual machine in OpenShift's web console.

    Conclusion

    That is it! I hope this discussion and short guide have helped you understand how to switch from OpenShift Virtualization's default of hardware virtualization to QEMU-based software emulation. By following the instructions in this article, you can easily operate a virtual machine with OpenShift Virtualization, even in non-bare metal instances such as AWS EC2.

    Last updated: June 4, 2024

    Recent Posts

    • How to run AI models in cloud development environments

    • How Trilio secures OpenShift virtual machines and containers

    • How to implement observability with Node.js and Llama Stack

    • How to encrypt RHEL images for Azure confidential VMs

    • How to manage RHEL virtual machines with Podman Desktop

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue