<commit_before>// Module included in the following assemblies:
//
// * nodes/nodes-nodes-rebooting.adoc

[id="nodes-nodes-rebooting-affinity_{context}"]
= Rebooting a node using pod anti-affinity

Pod anti-affinity is slightly different than node anti-affinity. Node anti-affinity can be
violated if there are no other suitable locations to deploy a pod. Pod
anti-affinity can be set to either required or preferred.

With this in place, if only two infrastructure nodes are available and one is rebooted, the container image registry
pod is prevented from running on the other node. `*oc get pods*` reports the pod as unready until a suitable node is available. 
Once a node is available and all pods are back in ready state, the next node can be restarted.

.Procedure 

To reboot a node using pod anti-affinity:

. Edit the node specification to configure pod anti-affinity:
+
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
  name: with-pod-antiaffinity
spec:
  affinity:
    podAntiAffinity: <1>
      preferredDuringSchedulingIgnoredDuringExecution: <2>
      - weight: 100 <3>
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: registry <4>
              operator: In <5>
              values: 
              - default
          topologyKey: kubernetes.io/hostname
----
<1> Stanza to configure pod anti-affinity.
<2> Defines a preferred rule.
<3> Specifies a weight for a preferred rule. The node with the highest weight is preferred.
<4> Description of the pod label that determines when the anti-affinity rule applies. Specify a key and value for the label.
<5> The operator represents the relationship between the label on the existing pod and the set of values in the `matchExpression` parameters in the specification for the new pod. Can be `In`, `NotIn`, `Exists`, or `DoesNotExist`.
+
This example assumes the container image registry pod has a label of
`*registry=default*`. Pod anti-affinity can use any Kubernetes match
expression.

. Enable the `*MatchInterPodAffinity*` scheduler predicate in the scheduling policy file. 
For more information, see xref:../../nodes/scheduling/nodes-scheduler-default.adoc#nodes-scheduler-default[Configuring the Default Scheduler].
<commit_msg>Remove xref from Rebooting a node using pod anti-affinity module<commit_after>// Module included in the following assemblies:
//
// * nodes/nodes-nodes-rebooting.adoc

[id="nodes-nodes-rebooting-affinity_{context}"]
= Rebooting a node using pod anti-affinity

Pod anti-affinity is slightly different than node anti-affinity. Node anti-affinity can be
violated if there are no other suitable locations to deploy a pod. Pod
anti-affinity can be set to either required or preferred.

With this in place, if only two infrastructure nodes are available and one is rebooted, the container image registry
pod is prevented from running on the other node. `*oc get pods*` reports the pod as unready until a suitable node is available. 
Once a node is available and all pods are back in ready state, the next node can be restarted.

.Procedure 

To reboot a node using pod anti-affinity:

. Edit the node specification to configure pod anti-affinity:
+
[source,yaml]
----
apiVersion: v1
kind: Pod
metadata:
  name: with-pod-antiaffinity
spec:
  affinity:
    podAntiAffinity: <1>
      preferredDuringSchedulingIgnoredDuringExecution: <2>
      - weight: 100 <3>
        podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: registry <4>
              operator: In <5>
              values: 
              - default
          topologyKey: kubernetes.io/hostname
----
<1> Stanza to configure pod anti-affinity.
<2> Defines a preferred rule.
<3> Specifies a weight for a preferred rule. The node with the highest weight is preferred.
<4> Description of the pod label that determines when the anti-affinity rule applies. Specify a key and value for the label.
<5> The operator represents the relationship between the label on the existing pod and the set of values in the `matchExpression` parameters in the specification for the new pod. Can be `In`, `NotIn`, `Exists`, or `DoesNotExist`.
+
This example assumes the container image registry pod has a label of
`*registry=default*`. Pod anti-affinity can use any Kubernetes match
expression.

. Enable the `*MatchInterPodAffinity*` scheduler predicate in the scheduling policy file. 


{'fraction_non_alphanumeric': 0.06940349285552279, 'fraction_numerical': 0.0063506464050805175, 'mean_word_length': 3.5557851239669422, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6530001', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1141, 'n_words': 559}