Sobes.tech
Junior — Middle

How to ensure Pod binding to a specific node in Kubernetes?

sobes.tech AI

Answer from AI

There are several approaches to bind a Pod to a specific node in Kubernetes:

  • nodeName — you can explicitly specify the name of the node in the Pod specification where the Pod should run.

  • nodeSelector — sets labels on the node where the Pod should be placed. For example:

spec:
  nodeSelector:
    disktype: ssd
  • affinity (nodeAffinity) — a more flexible method that allows setting preference rules or mandatory conditions for node selection.

  • taints and tolerations — allow marking nodes and permitting or forbidding the Pod to run on them.

Example with nodeSelector:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mycontainer
    image: nginx
  nodeSelector:
    kubernetes.io/hostname: node-1

This Pod will only run on a node with the label kubernetes.io/hostname=node-1.

How to ensure Pod binding to a specific node in… - sobes.tech