Pod Affinity
Pod affinity rules specify that pods should be placed near (on the same node or zone) as other pods.
Pod Affinity - Co-location
Pods scheduled on same node
Mental Model
Like wanting to sit near your friends at a concert. Pod affinity tells Kubernetes "put this pod on the same node as other pods from the same application" to improve performance or enable communication.
YAML Example
apiVersion: v1
kind: Pod
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: web
topologyKey: "kubernetes.io/hostname"
containers:
- name: app
image: myappCommon Misconceptions
- ✗Pod affinity affects all pods - FALSE: Only affects pods with the rule
- ✗Affinity is required - FALSE: Optional scheduling constraint
- ✗Affinity prevents node failure issues - TRUE: But also spreads risk
Key Takeaways
- • Pod affinity rules specify that pods should be placed near (on the same node or zone) as other pods.
- • Like wanting to sit near your friends at a concert. Pod affinity tells Kubernetes "put this pod on t...
- • Check the YAML example for implementation details
- • Be aware of the common misconceptions listed above