Reputation: 504
I have the following affinity defined on a pod. When this pod gets scheduled, it is always respecting the NodeAffinity first. Even if both pod affinities are satisfied, they are ignored. Are weights between node and pod affinity always ignored and node affinity always wins? or am I doing something else wrong?
K3d v5.7.5
Kubernetes Version: v1.30.6+k3s1
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: example.com/capacity-remaining
operator: Gt
values:
- "2457600"
weight: 1
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: example.com/lead-pod
operator: In
values:
- "receiver-0"
topologyKey: kubernetes.io/hostname
weight: 100
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: example.com/imagery-destination
operator: In
values:
- live-stitcher
topologyKey: kubernetes.io/hostname
weight: 80
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: example.com/regime
operator: In
values:
- ingest
topologyKey: kubernetes.io/hostname
Upvotes: 0
Views: 28
Reputation: 197
Pod affinity are not ignored, it's just that weights for soft affinity are important and respected first because it influences the scheduler to find a node that meets the rule as concept of node affinity:
preferredDuringSchedulingIgnoredDuringExecution
Configs are good. I suggest removing your weights with your pod affinity as it is only applicable with preferred affinity config and experiment with your affinity. Setting pod affinity as hard affinity for stricter conditions wherein if pod conditions aren’t met it will not be scheduled at all:
requiredDuringSchedulingIgnoredDuringExecution
Upvotes: 0