Middle — Middle+
What methods can be used to prevent automatic pod deployment on a specific Kubernetes node?
sobes.tech AI
Answer from AI
To prevent automatic Pod deployment on a specific node in Kubernetes, several approaches can be used:
-
Taints and Tolerations
- Add a taint to the node that will "repel" Pods without the corresponding toleration.
- Example:
kubectl taint nodes <node-name> key=value:NoSchedule - Pods without a toleration with this key will not be scheduled on this node.
-
Node Affinity (negative)
- Specify
nodeAffinityin the Pod manifest withrequiredDuringSchedulingIgnoredDuringExecution, excluding the desired node by label. - Example:
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: NotIn values: - <node-name>
- Specify
-
Node Selector
- Do not assign the Pod to a node by explicitly not specifying the desired label.
-
Admission Controllers or Webhook
- A more complex method is to configure a webhook that will reject the creation of Pods on certain nodes.
The most common and simple method is using taints and tolerations, as it explicitly forbids Pod placement without the proper configuration.