Skip to main content
  1. Posts/

Create a VM Class with Nested Virtualization Enabled

·441 words·3 mins

VMware has recently been pushing vSphere Supervisor in a big way. If you’re not familiar with vSphere Supervisor, it’s a Kubernetes API that’s deployed directly on top of vSphere. This allows you to manage some vSphere resources, such as VMs, by using Kubernetes tools. VCF Automation in particular is a really big user of vSphere Supervisor. The new All Apps organization requires vSphere Supervisor and NSX VPCs to use it.

If you looked into using this to create a VM with nested virtualization, you might have noticed that there’s no option to enable that setting in the VM resource manifest. While it’s possible to manually enable hardware virtualization from the vSphere UI after deploying a VM, that’s clearly not the preferred way to do it.

What you need to do instead is create a custom VM class with hardware virtualization enabled. If you try to create it through the vSphere UI, you’ll notice that the box to enable hardware virtualization is greyed out and disabled by default.

Hardware virtualization option cannot be selected
Hardware virtualization option cannot be selected

What you need to do is create the VM class through the API, instead. If you don’t want to dig out Postman, you can simply navigate to the API Explorer in the Developer Center of vSphere. Search for the API endpoint /api/vcenter/namespace-management/virtual-machine-classes that uses the POST method.

List of API endpoints used to managed VM classes
List of API endpoints used to manage VM classes

The key thing the API lets us do is specify a config_spec. There we include the nestedHVEnabled setting to control whether hardware virtualization is enabled for a VM. See below for an example.

{
    "id": "nested-small",
    "description": "Class for nested virutalization",
    "cpu_count": 2,
    "cpu_reservation": 0,
    "memory_MB": 8192,
    "memory_reservation": 0,
    "config_spec": { 
        "_typeName": "VirtualMachineConfigSpec",
        "nestedHVEnabled": true,
        "memoryMB": 8192,
        "numCPUs": 2
    }
}

config_spec would probably work without the memoryMB and numCPUs settings. But the default VM classes include those settings in their own config_spec blocks, so I figured it’s better to stay consistent.

Modify this block with your desired settings and paste it into the request_body parameter of API Explorer. Now click the “execute” button. If all goes well, you should see Status: 204, OK in the response field.

Creating the nested virtualization VM class using the API
Creating the nested virtualization VM class using the API

You should now see this VM class available within the VM Service menu.

Nested virtualization VM class in the available VM classes
Nested virtualization VM class in the available VM classes

If you edit it and look at the CPU configuration, you can confirm that hardware virtualization is enabled.

VM class has hardware virtualization enabled
VM class has hardware virtualization enabled

Associate this new VM class with your desired supervisor namespace and you can begin deploying VMs that use nested virtualization!

Associating the nested virtualization VM class with a namespace
Associating the nested virtualization VM class with a namespace