×

Create and manage resource quotas for virtual machines.

Setting resource quota limits for virtual machines

By default, OKD Virtualization automatically manages CPU and memory limits for virtual machines (VMs) if a namespace enforces resource quotas that require limits to be set. The memory limit is automatically set to twice the requested memory 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 to the namespace. For example, the following command sets the memory limit ratio to 1.2:

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

Avoid managing resource quota limits manually. To prevent misconfigurations or scheduling issues, rely on the automatic resource limit management provided by OKD Virtualization unless you have a specific need to override the defaults.

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.

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.