1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/nodes-scheduler-pod-affinity-configuring.adoc

90 lines
2.4 KiB
Plaintext

// Module included in the following assemblies:
//
// * nodes/nodes-scheduler-pod-affinity.adoc
:_mod-docs-content-type: PROCEDURE
[id="nodes-scheduler-pod-affinity-configuring_{context}"]
= Configuring a pod affinity rule
The following steps demonstrate a simple two-pod configuration that creates pod with a label and a pod that uses affinity to allow scheduling with that pod.
[NOTE]
====
You cannot add an affinity directly to a scheduled pod.
====
.Procedure
. Create a pod with a specific label in the pod spec:
+
.. Create a YAML file with the following content:
+
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
name: security-s1
labels:
security: S1
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
containers:
- name: security-s1
image: docker.io/ocpqe/hello-pod
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
----
+
.. Create the pod.
+
[source,terminal]
----
$ oc create -f <pod-spec>.yaml
----
. When creating other pods, configure the following parameters to add the affinity:
+
.. Create a YAML file with the following content:
+
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
name: security-s1-east
# ...
spec:
affinity: <1>
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution: <2>
- labelSelector:
matchExpressions:
- key: security <3>
values:
- S1
operator: In <4>
topologyKey: topology.kubernetes.io/zone <5>
# ...
----
+
--
<1> Adds a pod affinity.
<2> Configures the `requiredDuringSchedulingIgnoredDuringExecution` parameter or the `preferredDuringSchedulingIgnoredDuringExecution` parameter.
<3> Specifies the `key` and `values` that must be met. If you want the new pod to be scheduled with the other pod, use the same `key` and `values` parameters as the label on the first pod.
<4> Specifies an `operator`. The operator can be `In`, `NotIn`, `Exists`, or `DoesNotExist`. For example, use the operator `In` to require the label to be in the node.
<5> Specify a `topologyKey`, which is a prepopulated link:https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#interlude-built-in-node-labels[Kubernetes label] that the system uses to denote such a topology domain.
--
.. Create the pod.
+
[source,terminal]
----
$ oc create -f <pod-spec>.yaml
----