mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
123 lines
2.6 KiB
Plaintext
123 lines
2.6 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`:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc label node node1 zone=us
|
|
----
|
|
|
|
* The pod-s1 pod has the `zone` and `us` key/value pair under a required node affinity rule:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ cat pod-s1.yaml
|
|
----
|
|
+
|
|
.Example output
|
|
[source,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-s1 pod can be scheduled on Node1:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc get pod -o wide
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
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`:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc label node node1 zone=emea
|
|
----
|
|
|
|
* The pod-s1 pod has the `zone` and `us` key/value pair under a required node affinity rule:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ cat pod-s1.yaml
|
|
----
|
|
+
|
|
.Example output
|
|
[source,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-s1 pod cannot be scheduled on Node1:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc describe pod pod-s1
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
...
|
|
|
|
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).
|
|
----
|