×

Enabling automatic resource quota limits for virtual machines

When the AutoResourceLimits feature gate is enabled, OKD Virtualization automatically manages CPU and memory limits for virtual machines.

By default, OKD Virtualization computes resource requests for a virtual machine. When you enable the AutoResourceLimits feature gate, OKD Virtualization also computes resource limits to meet namespace quota requirements.

If a namespace enforces both CPU and memory quotas and requires limits to be set, enabling the AutoResourceLimits feature gate is recommended. When this feature is enabled, the memory limit is automatically set to double the base memory allocation and the CPU limit is set to one per vCPU.

You can customize the memory limit ratio for a specific namespace by adding the alpha.kubevirt.io/auto-memory-limits-ratio label.

For example, the following command sets the ratio to 1.2 for the my-virtualization-project namespace:

$ oc label ns/my-virtualization-project  alpha.kubevirt.io/auto-memory-limits-ratio=1.2
Procedure

To enable automatic resource quota limits for virtual machines, perform the following steps:

  1. Edit the HyperConverged custom resource (CR) by running the following command:

    $ oc edit hyperconverged kubevirt-hyperconverged -n openshift-cnv
  2. In the spec.featureGates section, add or set the autoResourceLimits parameter to true:

    spec:
      featureGates:
        autoResourceLimits: true
  3. Save the changes and exit the editor.

Manually setting resource quota limits for virtual machines

Resource quotas that only use requests automatically work with VMs. If your resource quota uses limits, you must manually set resource limits on VMs. Memory resource limits, defined by the spec.template.spec.domain.resources.limits.memory value, must be at least 500 MiB, or 2% larger than the spec.template.spec.domain.memory.guest value.

Manual management of resource quota limits is not recommended. It is recommended to enable automatic resource quota limit computation instead, as described in the previous section. Manual limit settings can lead to quota misconfigurations or scheduling issues.

Procedure
  1. Set limits for a VM by editing the VirtualMachine manifest. For example:

    apiVersion: kubevirt.io/v1
    kind: VirtualMachine
    metadata:
      name: with-limits
    spec:
      runStrategy: Halted
      template:
        spec:
          domain:
            memory:
              guest: 128Mi
            resources:
              limits:
                memory: 256Mi

    where

    spec.template.spec.domain.memory.guest

    Specifies the actual amount of RAM that is shown to the guest operating system (OS) in the VM.

    spec.template.spec.domain.resources.limits.memory

    Specifies the hard limit for total memory consumption by the virt-launcher pod that hosts the VM. This limit must account for the guest OS RAM plus the hypervisor overhead.

    This example configuration is supported because the spec.template.spec.domain.resources.limits.memory value is at least 100Mi larger than the spec.template.spec.domain.memory.guest value.

  2. Save the VirtualMachine manifest.