mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-06 15:46:57 +01:00
96 lines
2.4 KiB
Plaintext
96 lines
2.4 KiB
Plaintext
// Module included in the following assemblies:
|
|
//
|
|
// * nodes/nodes-scheduler-node-affinity.adoc
|
|
|
|
[id="nodes-scheduler-node-affinity-examples_{context}"]
|
|
= Sample node affinity rules
|
|
|
|
The following examples demonstrate node affinity.
|
|
|
|
[id="admin-guide-sched-affinity-examples1_{context}"]
|
|
== Node Affinity with Matching Labels
|
|
|
|
The following example demonstrates node affinity for a node and pod with matching labels:
|
|
|
|
* The *Node1* node has the label `zone:us`:
|
|
+
|
|
----
|
|
$ oc label node node1 zone=us
|
|
----
|
|
|
|
* The pod *pod-s1* has the `zone` and `us` key/value pair under a required node affinity rule:
|
|
+
|
|
----
|
|
$ cat pod-s1.yaml
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: pod-s1
|
|
spec:
|
|
containers:
|
|
- image: "docker.io/ocpqe/hello-pod"
|
|
name: hello-pod
|
|
affinity:
|
|
nodeAffinity:
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
nodeSelectorTerms:
|
|
- matchExpressions:
|
|
- key: "zone"
|
|
operator: In
|
|
values:
|
|
- us
|
|
----
|
|
|
|
* The pod *pod-s1* can be scheduled on *Node1*:
|
|
+
|
|
----
|
|
$ oc get pod -o wide
|
|
NAME READY STATUS RESTARTS AGE IP NODE
|
|
pod-s1 1/1 Running 0 4m IP1 node1
|
|
----
|
|
|
|
[id="admin-guide-sched-affinity-examples2_{context}"]
|
|
== Node Affinity with No Matching Labels
|
|
|
|
The following example demonstrates node affinity for a node and pod without matching labels:
|
|
|
|
* The *Node1* node has the label `zone:emea`:
|
|
+
|
|
----
|
|
$ oc label node node1 zone=emea
|
|
----
|
|
|
|
* The pod *pod-s1* has the `zone` and `us` key/value pair under a required node affinity rule:
|
|
+
|
|
----
|
|
$ cat pod-s1.yaml
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
name: pod-s1
|
|
spec:
|
|
containers:
|
|
- image: "docker.io/ocpqe/hello-pod"
|
|
name: hello-pod
|
|
affinity:
|
|
nodeAffinity:
|
|
requiredDuringSchedulingIgnoredDuringExecution:
|
|
nodeSelectorTerms:
|
|
- matchExpressions:
|
|
- key: "zone"
|
|
operator: In
|
|
values:
|
|
- us
|
|
----
|
|
|
|
* The pod *pod-s1* cannot be scheduled on *Node1*:
|
|
+
|
|
----
|
|
$ oc describe pod pod-s1
|
|
<---snip--->
|
|
Events:
|
|
FirstSeen LastSeen Count From SubObjectPath Type Reason
|
|
--------- -------- ----- ---- ------------- -------- ------
|
|
1m 33s 8 default-scheduler Warning FailedScheduling No nodes are available that match all of the following predicates:: MatchNodeSelector (1).
|
|
----
|