Schedule virtual machines
You can schedule a virtual machine (VM) on a node by ensuring that the VM’s CPU model and policy attribute are matched for compatibility with the CPU models and policy attributes supported by the node.
Set a VM to inherit the node CPU model
Set the CPU model of a virtual machine (VM) to host-model so that the VM inherits the CPU model of the node where it is scheduled, and can use the CPU features that the node provides.
Procedure
-
Edit the
domainspec of your VM configuration file. The following example showshost-modelbeing specified for the virtual machine:apiVersion: kubevirt/v1alpha3kind: VirtualMachinemetadata:name: myvmspec:template:spec:domain:cpu:model: host-modelspec.template.spec.domain.cpu.modeldefines the VM that inherits the CPU model of the node where it is scheduled.
Set a VM to run only on nodes with a named CPU model
Set a named CPU model on a virtual machine (VM) so that the scheduler places the VM only on nodes that support that model.
Procedure
-
Edit the
domainspec of your virtual machine configuration file. The following example shows a specific CPU model defined for a VM:apiVersion: kubevirt.io/v1kind: VirtualMachinemetadata:name: myvmspec:template:spec:domain:cpu:model: Conroe# ...spec.template.spec.domain.cpu.modeldefines the CPU model for the VM.
CPU feature policy attributes
A policy attribute controls how strictly the scheduler enforces a CPU feature that you set on a virtual machine (VM). Use a policy attribute to require a feature, treat it as optional, or forbid it.
| Policy attribute | Description |
|---|---|
| force | The VM is forced to be scheduled on a node. This is true even if the host CPU does not support the VM’s CPU. |
| require | Default policy that applies to a VM if the VM is not configured with a specific CPU model and feature specification. If a node is not configured to support CPU node discovery with this default policy attribute or any one of the other policy attributes, VMs are not scheduled on that node. Either the host CPU must support the VM’s CPU or the hypervisor must be able to emulate the supported CPU model. |
| optional | The VM is added to a node if that VM is supported by the host’s physical machine CPU. |
| disable | The VM cannot be scheduled with CPU node discovery. |
| forbid | The VM is not scheduled even if the feature is supported by the host CPU and CPU node discovery is enabled. |
Set a policy attribute and CPU feature
Set a CPU feature and a policy attribute on a virtual machine (VM) so that the VM runs only where the feature is available. The feature must be supported by the host CPU or emulated by the hypervisor.
Procedure
-
Edit the
domainspec of your VM configuration file. The following example sets the CPU feature and therequirepolicy for a virtual machine (VM):apiVersion: kubevirt.io/v1kind: VirtualMachinemetadata:name: myvmspec:template:spec:domain:cpu:features:- name: apicpolicy: requirespec.template.spec.domain.cpu.features.namedefines the name of the CPU feature for the VM.spec.template.spec.domain.cpu.features.policydefines the policy attribute for the VM.
Schedule VMs with a custom scheduler
You can run a virtual machine (VM) under a custom scheduler instead of the default scheduler, so that your own scheduling logic decides which node runs the VM.
Prerequisites
- A secondary scheduler is configured for your cluster.
- You have installed the OpenShift CLI (
oc).
Procedure
-
Add the custom scheduler to the VM configuration by editing the
VirtualMachinemanifest. For example:apiVersion: kubevirt.io/v1kind: VirtualMachinemetadata:name: vm-fedoraspec:runStrategy: Alwaystemplate:spec:schedulerName: my-schedulerdomain:devices:disks:- name: containerdiskdisk:bus: virtio# ...schedulerName- The name of the custom scheduler. If the
schedulerNamevalue does not match an existing scheduler, thevirt-launcherpod stays in aPendingstate until the specified scheduler is found.
Verification
- Verify that the VM is using the custom scheduler specified in the
VirtualMachinemanifest by checking thevirt-launcherpod events:-
View the list of pods in your cluster by entering the following command:
$ oc get podsExample output:
NAME READY STATUS RESTARTS AGEvirt-launcher-vm-fedora-dpc87 2/2 Running 0 24m -
Run the following command to display the pod events:
$ oc describe pod virt-launcher-vm-fedora-dpc87The value of the
Fromfield in the output verifies that the scheduler name matches the custom scheduler specified in theVirtualMachinemanifest:Example output:
[...]Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Scheduled 21m my-scheduler Successfully assigned default/virt-launcher-vm-fedora-dpc87 to node01[...]
-
Additional resources