Skip to content

Commit d316b20

Browse files
authored
Merge pull request #31909 from ousleyp/cnv-7685
CNV-7685: node placement for VMs
2 parents 483b071 + df30dcd commit d316b20

8 files changed

+202
-0
lines changed

_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,8 @@ Topics:
26552655
Dir: advanced_vm_management
26562656
Topics:
26572657
#Advanced virtual machine configuration
2658+
- Name: Specifying nodes for virtual machines
2659+
File: virt-specifying-nodes-for-vms
26582660
- Name: Automating management tasks
26592661
File: virt-automating-management-tasks
26602662
- Name: EFI mode for virtual machines
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/advanced_vm_management/virt-specifying-nodes-for-vms.adoc
4+
5+
[id="virt-about-node-placement-vms_{context}"]
6+
= About node placement for virtual machines
7+
8+
To ensure that virtual machines (VMs) run on appropriate nodes, you can configure node placement rules. You might want to do this if:
9+
10+
* You have several VMs. To ensure fault tolerance, you want them to run on different nodes.
11+
* You have two chatty VMs. To avoid redundant inter-node routing, you want the VMs to run on the same node.
12+
* Your VMs require specific hardware features that are not present on all available nodes.
13+
* You have a pod that adds capabilities to a node, and you want to place a VM on that node so that it can use those capabilities.
14+
15+
[NOTE]
16+
====
17+
Virtual machine placement relies on any existing node placement rules for workloads. If workloads are excluded from specific nodes on the component level, virtual machines cannot be placed on those nodes.
18+
====
19+
20+
You can use the following rule types in the `spec` field of a `VirtualMachine` manifest:
21+
22+
`nodeSelector`:: Allows virtual machines to be scheduled on nodes that are labeled with the key-value pair or pairs that you specify in this field. The node must have labels that exactly match all listed pairs.
23+
`affinity`:: Enables you to use more expressive syntax to set rules that match nodes with virtual machines. For example, you can specify that a rule is a preference, rather than a hard requirement, so that virtual machines are still scheduled if the rule is not satisfied. Pod affinity, pod anti-affinity, and node affinity are supported for virtual machine placement. Pod affinity works for virtual machines because the `VirtualMachine` workload type is based on the `Pod` object.
24+
+
25+
[NOTE]
26+
====
27+
Affinity rules only apply during scheduling. {product-title} does not reschedule running workloads if the constraints are no longer met.
28+
====
29+
`tolerations`:: Allows virtual machines to be scheduled on nodes that have matching taints. If a taint is applied to a node, that node only accepts virtual machines that tolerate the taint.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/advanced_vm_management/virt-specifying-nodes-for-vms.adoc
4+
5+
[id="virt-example-vm-node-placement-node-affinity_{context}"]
6+
= Example: VM node placement with node affinity
7+
8+
In this example, the VM must be scheduled on a node that has the label `example.io/example-key = example-value-1` or the label `example.io/example-key = example-value-2`. The constraint is met if only one of the labels is present on the node. If neither label is present, the VM is not scheduled.
9+
10+
If possible, the scheduler avoids nodes that have the label `example-node-label-key = example-node-label-value`. However, if all candidate nodes have this label, the scheduler ignores this constraint.
11+
12+
.Example VM manifest
13+
[source,yaml]
14+
----
15+
metadata:
16+
name: example-vm-node-affinity
17+
apiVersion: kubevirt.io/v1alpha3
18+
kind: VirtualMachine
19+
spec:
20+
affinity:
21+
nodeAffinity:
22+
requiredDuringSchedulingIgnoredDuringExecution: <1>
23+
nodeSelectorTerms:
24+
- matchExpressions:
25+
- key: example.io/example-key
26+
operator: In
27+
values:
28+
- example-value-1
29+
- example-value-2
30+
preferredDuringSchedulingIgnoredDuringExecution: <2>
31+
- weight: 1
32+
preference:
33+
matchExpressions:
34+
- key: example-node-label-key
35+
operator: In
36+
values:
37+
- example-node-label-value
38+
...
39+
----
40+
<1> If you use the `requiredDuringSchedulingIgnoredDuringExecution` rule type, the VM is not scheduled if the constraint is not met.
41+
<2> If you use the `preferredDuringSchedulingIgnoredDuringExecution` rule type, the VM is still scheduled if the constraint is not met, as long as all required constraints are met.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/advanced_vm_management/virt-specifying-nodes-for-vms.adoc
4+
5+
[id="virt-example-vm-node-placement-node-selector_{context}"]
6+
= Example: VM node placement with nodeSelector
7+
8+
In this example, the virtual machine requires a node that has metadata containing both `example-key-1 = example-value-1` and `example-key-2 = example-value-2` labels.
9+
10+
[WARNING]
11+
====
12+
If there are no nodes that fit this description, the virtual machine is not scheduled.
13+
====
14+
15+
.Example VM manifest
16+
[source,yaml]
17+
----
18+
metadata:
19+
name: example-vm-node-selector
20+
apiVersion: kubevirt.io/v1alpha3
21+
kind: VirtualMachine
22+
spec:
23+
nodeSelector:
24+
example-key-1: example-value-1
25+
example-key-2: example-value-2
26+
...
27+
----
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/advanced_vm_management/virt-specifying-nodes-for-vms.adoc
4+
5+
[id="virt-example-vm-node-placement-pod-affinity_{context}"]
6+
= Example: VM node placement with pod affinity and pod anti-affinity
7+
8+
In this example, the VM must be scheduled on a node that has a running pod with the label `example-key-1 = example-value-1`. If there is no such pod running on any node, the VM is not scheduled.
9+
10+
If possible, the VM is not scheduled on a node that has any pod with the label `example-key-2 = example-value-2`. However, if all candidate nodes have a pod with this label, the scheduler ignores this constraint.
11+
12+
.Example VM manifest
13+
[source,yaml]
14+
----
15+
metadata:
16+
name: example-vm-pod-affinity
17+
apiVersion: kubevirt.io/v1alpha3
18+
kind: VirtualMachine
19+
spec:
20+
affinity:
21+
podAffinity:
22+
requiredDuringSchedulingIgnoredDuringExecution: <1>
23+
- labelSelector:
24+
matchExpressions:
25+
- key: example-key-1
26+
operator: In
27+
values:
28+
- example-value-1
29+
topologyKey: kubernetes.io/hostname
30+
podAntiAffinity:
31+
preferredDuringSchedulingIgnoredDuringExecution: <2>
32+
- weight: 100
33+
podAffinityTerm:
34+
labelSelector:
35+
matchExpressions:
36+
- key: example-key-2
37+
operator: In
38+
values:
39+
- example-value-2
40+
topologyKey: kubernetes.io/hostname
41+
...
42+
----
43+
<1> If you use the `requiredDuringSchedulingIgnoredDuringExecution` rule type, the VM is not scheduled if the constraint is not met.
44+
<2> If you use the `preferredDuringSchedulingIgnoredDuringExecution` rule type, the VM is still scheduled if the constraint is not met, as long as all required constraints are met.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/advanced_vm_management/virt-specifying-nodes-for-vms.adoc
4+
5+
[id="virt-example-vm-node-placement-tolerations_{context}"]
6+
= Example: VM node placement with tolerations
7+
8+
In this example, nodes that are reserved for virtual machines are already labeled with the `key=virtualization:NoSchedule` taint. Because this virtual machine has matching `tolerations`, it can schedule onto the tainted nodes.
9+
10+
[NOTE]
11+
====
12+
A virtual machine that tolerates a taint is not required to schedule onto a node with that taint.
13+
====
14+
15+
.Example VM manifest
16+
[source,yaml]
17+
----
18+
metadata:
19+
name: example-vm-tolerations
20+
apiVersion: kubevirt.io/v1alpha3
21+
kind: VirtualMachine
22+
spec:
23+
tolerations:
24+
- key: "key"
25+
operator: "Equal"
26+
value: "virtualization"
27+
effect: "NoSchedule"
28+
...
29+
----

virt/install/virt-specifying-nodes-for-virtualization-components.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ include::modules/virt-about-node-placement-virtualization-components.adoc[levelo
2020

2121
[id="node-placement-resources_{context}"]
2222
==== Node placement rules
23+
* xref:../../virt/virtual_machines/advanced_vm_management/virt-specifying-nodes-for-vms.adoc#virt-specifying-nodes-for-vms[Specifying nodes for virtual machines]
2324
* xref:../../nodes/scheduling/nodes-scheduler-node-selectors.adoc#nodes-scheduler-node-selectors[Placing pods on specific nodes using node selectors]
2425
* xref:../../nodes/scheduling/nodes-scheduler-node-affinity.adoc#nodes-scheduler-node-affinity[Controlling pod placement on nodes using node affinity rules]
2526
* xref:../../nodes/scheduling/nodes-scheduler-taints-tolerations.adoc#nodes-scheduler-taints-tolerations[Controlling pod placement using node taints]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[id="virt-specifying-nodes-for-vms"]
2+
= Specifying nodes for virtual machines
3+
include::modules/virt-document-attributes.adoc[]
4+
include::modules/common-attributes.adoc[]
5+
:context: virt-specifying-nodes-for-vms
6+
7+
toc::[]
8+
9+
You can place virtual machines (VMs) on specific nodes by using node placement rules.
10+
11+
include::modules/virt-about-node-placement-vms.adoc[leveloffset=+1]
12+
13+
[id="node-placement-examples_{context}"]
14+
== Node placement examples
15+
16+
The following example YAML file snippets use `nodePlacement`, `affinity`, and `tolerations` fields to customize node placement for virtual machines.
17+
18+
include::modules/virt-example-vm-node-placement-node-selector.adoc[leveloffset=+2]
19+
include::modules/virt-example-vm-node-placement-pod-affinity.adoc[leveloffset=+2]
20+
include::modules/virt-example-vm-node-placement-node-affinity.adoc[leveloffset=+2]
21+
include::modules/virt-example-vm-node-placement-tolerations.adoc[leveloffset=+2]
22+
23+
[id="additional-resources_{context}"]
24+
== Additional resources
25+
26+
* xref:../../../virt/install/virt-specifying-nodes-for-virtualization-components.adoc#virt-specifying-nodes-for-virtualization-components[Specifying nodes for virtualization components]
27+
* xref:../../../nodes/scheduling/nodes-scheduler-node-selectors.adoc#nodes-scheduler-node-selectors[Placing pods on specific nodes using node selectors]
28+
* xref:../../../nodes/scheduling/nodes-scheduler-node-affinity.adoc#nodes-scheduler-node-affinity[Controlling pod placement on nodes using node affinity rules]
29+
* xref:../../../nodes/scheduling/nodes-scheduler-taints-tolerations.adoc#nodes-scheduler-taints-tolerations[Controlling pod placement using node taints]

0 commit comments

Comments
 (0)