3.1. Introduction

Use your own instance type

Even if KubeVirt provides advanced options and a lot of configuration options for different VMs, we usually have a common set of VM specifications which we will use for most of our VMs. Therefore, it may make sense to define such specifications as instance types and / or preferences.

To achieve this, KubeVirt provides multiple CustomResourceDefinitions like VirtualMachineInstancetype, VirtualMachineClusterInstancetype or VirtualMachinePreference.

VM VirtualMachineInstancetype

For an instance type we have the option of using the cluster-wide VirtualMachineClusterInstancetype or the namespaced VirtualMachineInstancetype.

With instance types we can define the following resource-related characteristics:

  • CPU - Required number of vCPUs presented to the guest
  • Memory - Required amount of memory presented to the guest
  • GPUs - Optional list of vGPUs to passthrough
  • HostDevices - Optional list of HostDevices to pass through
  • IOThreadsPolicy - Optional IOThreadsPolicy to be used
  • LaunchSecurity - Optional LaunchSecurity to be used

VM preference

KubeVirt also provides a CRD VirtualMachineClusterPreference for cluster-wide preferences as well as a namespaced version VirtualMachinePreference. A preference specification encapsulates every value of the remaining attributes of a VirtualMachine.

Using instance type or preference in a virtual machine

A sample virtual machine referencing an instance type and preference looks like this:

apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
  name: lab03-examplevm
spec:
  instancetype:
    kind: VirtualMachineInstancetype
    name: lab03-example-instancetype
  preference:
    kind: VirtualMachinePreference
    name: lab03-example-preference