Junior — Middle
How can you bind a Pod to a specific node in Kubernetes?
sobes.tech AI
Answer from AI
To pin a Pod to a specific node in Kubernetes, several approaches can be used:
- nodeSelector — the simplest method. In the Pod manifest, specify the label of the node where you want to run the Pod.
spec:
nodeSelector:
disktype: ssd
- nodeAffinity — a more flexible method, allows setting rules with operators (In, NotIn, Exists, etc.).
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node-name
-
Pod affinity/anti-affinity — for setting preferences regarding other Pods.
-
Taints and Tolerations — nodes can be "tainted" so that only Pods with matching tolerations are scheduled on them.
To pin a Pod to a specific node, most often nodeSelector or nodeAffinity with the node's name or label are used.