0
0
Kubernetesdevops~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What is pod affinity in Kubernetes?
Pod affinity lets you tell Kubernetes to schedule pods close to other pods based on labels. It helps pods run together on the same or nearby nodes.
Click to reveal answer
beginner
What does pod anti-affinity do?
Pod anti-affinity tells Kubernetes to avoid placing pods near certain other pods. It helps spread pods apart for better availability.
Click to reveal answer
intermediate
Which Kubernetes field is used to specify pod affinity rules in a pod spec?
The field is affinity.podAffinity inside the pod spec's spec.affinity section.
Click to reveal answer
intermediate
How do you express that a pod should not be scheduled on the same node as pods with label app=frontend?
Use pod anti-affinity with a rule matching label app=frontend and set topologyKey to kubernetes.io/hostname to avoid the same node.
Click to reveal answer
advanced
What is the difference between requiredDuringSchedulingIgnoredDuringExecution and preferredDuringSchedulingIgnoredDuringExecution in pod affinity?
requiredDuringSchedulingIgnoredDuringExecution means the rule must be met to schedule the pod. preferredDuringSchedulingIgnoredDuringExecution means the rule is a soft preference but not mandatory.
Click to reveal answer
What does pod affinity help you do?
APrevent pods from running on any node
BSchedule pods close to other pods with specific labels
CDelete pods automatically
DScale pods horizontally
Which field defines pod anti-affinity rules?
Aspec.affinity.podAntiAffinity
Bspec.containers.antiAffinity
Cmetadata.labels.antiAffinity
Dspec.nodeSelector
What does setting topologyKey: kubernetes.io/hostname in pod anti-affinity do?
AIgnores node labels
BSchedules pods only on master nodes
CForces pods to run on different clusters
DAvoids scheduling pods on the same node
Which affinity type is a soft preference, not mandatory?
ApreferredDuringSchedulingIgnoredDuringExecution
BrequiredDuringSchedulingIgnoredDuringExecution
CnodeAffinity
DpodSelector
Pod anti-affinity is useful to:
ARun all pods on the same node
BIncrease pod CPU limits
CSpread pods across nodes for high availability
DAutomatically update pods
Explain how pod affinity and anti-affinity affect pod scheduling in Kubernetes.
Think about how pods can be grouped or separated on nodes.
You got /4 concepts.
    Describe the difference between required and preferred rules in pod affinity or anti-affinity.
    Consider how strict Kubernetes is when placing pods.
    You got /3 concepts.