Scheduling Pods with Taints
Understanding the Scheduling Process
When a pod is created, the Kubernetes scheduler evaluates the pod's tolerations against the node's taints. If the pod's tolerations match the node's taints, the pod can be scheduled on that node.
Scheduling Pods with Tolerations
To schedule a pod on a tainted node, you need to add a toleration to the pod specification. Here's an example:
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
tolerations:
- key: "key"
operator: "Equal"
value: "value"
effect: "NoSchedule"
In this example, the pod will be scheduled on a node with the taint key=value:NoSchedule
.
Handling Multiple Taints
A node can have multiple taints, and a pod can have multiple tolerations. The pod will be scheduled on the node if at least one of the pod's tolerations matches one of the node's taints.
Overriding Taints with Node Selectors
You can also use node selectors to override taints and force a pod to be scheduled on a specific node, regardless of the node's taints. This can be useful for critical system pods that need to be scheduled on specific nodes.
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: nginx
nodeSelector:
node-role.kubernetes.io/master: "true"
This pod will be scheduled on a master node, even if the master node has taints.