Sobes.tech
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:

  1. 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.
  2. Node Affinity (negative)

    • Specify nodeAffinity in the Pod manifest with requiredDuringSchedulingIgnoredDuringExecution, excluding the desired node by label.
    • Example:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: NotIn
                values:
                - <node-name>
      
  3. Node Selector

    • Do not assign the Pod to a node by explicitly not specifying the desired label.
  4. 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.

What methods can be used to prevent automatic pod… - sobes.tech