0
0
Kubernetesdevops~5 mins

Node affinity and anti-affinity in Kubernetes - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is node affinity in Kubernetes?
Node affinity is a set of rules used by Kubernetes to schedule pods onto nodes based on node labels. It helps pods prefer or require certain nodes to run on.
Click to reveal answer
beginner
What does node anti-affinity do?
Node anti-affinity tells Kubernetes to avoid placing pods on nodes with certain labels. It helps spread pods across nodes to improve availability.
Click to reveal answer
intermediate
What are the two types of node affinity in Kubernetes?
The two types are requiredDuringSchedulingIgnoredDuringExecution (hard requirement) and preferredDuringSchedulingIgnoredDuringExecution (soft preference).
Click to reveal answer
intermediate
How does Kubernetes treat requiredDuringSchedulingIgnoredDuringExecution node affinity?
It treats it as a hard rule. Pods will only be scheduled on nodes that meet the specified label criteria.
Click to reveal answer
beginner
Give a simple example of node affinity in a pod spec.
Example snippet:<br>
affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: "disktype"
          operator: In
          values:
          - ssd
Click to reveal answer
What does node anti-affinity help achieve?
AIncrease pod resource limits
BForce pods to run on specific nodes
CAvoid placing pods on certain nodes
DAutomatically update pod images
Which node affinity type is a hard requirement?
ApreferredDuringSchedulingIgnoredDuringExecution
BrequiredDuringSchedulingIgnoredDuringExecution
CsoftDuringSchedulingIgnoredDuringExecution
DoptionalDuringSchedulingIgnoredDuringExecution
What Kubernetes object label is used in node affinity to select nodes?
ANode labels
BPod labels
CNamespace labels
DService labels
If a pod has node affinity with preferredDuringSchedulingIgnoredDuringExecution, what happens if no nodes match?
APod will restart
BPod will not be scheduled
CPod will be deleted
DPod will be scheduled on any node
Which section in a pod spec defines node affinity?
Aspec.affinity.nodeAffinity
Bspec.containers
Cmetadata.labels
Dspec.volumes
Explain node affinity and anti-affinity in Kubernetes and how they affect pod scheduling.
Think about how pods choose nodes based on labels and preferences.
You got /4 concepts.
    Describe a scenario where you would use node anti-affinity and why it is useful.
    Consider how spreading pods can prevent single points of failure.
    You got /3 concepts.