×

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 annotation.

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

$ oc annotate namespace 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 virtual machines (VMs). If your resource quota uses limits, you must manually set resource limits on VMs. Resource limits must be at least 100 MiB larger than resource requests.

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:
    # ...
            resources:
              requests:
                memory: 128Mi
              limits:
                memory: 256Mi  (1)
    1 This configuration is supported because the limits.memory value is at least 100Mi larger than the requests.memory value.
  2. Save the VirtualMachine manifest.