Skip to main content

Workloads & Scheduling

How to Schedule Pods on a Tainted Node in Kubernetes

Your Kubernetes cluster contains nodes dedicated to critical workloads. The node01 node must be reserved for applications that explicitly tolerate its taint.

A new critical application needs to run on this dedicated node.

Your task is to configure the cluster so that the Deployment critical-app can run on node01.

The Deployment must:

  • Use the nginx image.
  • Run 3 replicas.
  • Include the appropriate toleration for the critical=true:NoSchedule taint.
  • Ensure its Pods can be scheduled onto node01.

First, apply the required taint to node01. Then create the Deployment with the necessary configuration.

Finally, verify that all 3 Pods are in the Running state and determine which node is hosting them.


Taints the Node

Apply a NoSchedule taint to node01:

$ kubectl taint node node01 critical=true:NoSchedule

node/node01 tainted

Verify the taint:

$  kubectl describe node node01 | grep Taints

Taints:             critical=true:NoSchedule

Create the Deployment

Generate the Deployment manifest with 3 replicas using the nginx image:

kubectl create deployment critical-app \
  --image=nginx \
  --replicas=3 \
  --dry-run=client -o yaml > deploy.yaml

Edit deploy.yaml and add the toleration under spec.template.spec:

deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: critical-app spec: replicas: 3 selector: matchLabels: app: critical-app template: metadata: labels: app: critical-app spec: containers: - name: nginx image: nginx tolerations: - key: critical operator: Equal value: "true" effect: NoSchedule

Why the Toleration Is Required

The node has the taint critical=true:NoSchedule. The Pod must have a matching toleration with the same key, value, and effect to be scheduled onto that node.

Important: A toleration allows a Pod to run on a tainted node; it does not force the Pod onto that node.

If the task specifically requires all 3 Pods to run on node01, add a nodeSelector as well:

nodeSelector:
  kubernetes.io/hostname: node01

The relevant section would be:

spec:
  nodeSelector:
    kubernetes.io/hostname: node01
  tolerations:
  - key: critical
    operator: Equal
    value: "true"
    effect: NoSchedule

Apply the Deployment

$ kubectl apply -f deploy.yaml

deployment.apps/critical-app created

Verify the Pods

Check the Pods and the nodes where they are running:

$ kubectl get pods -o wide

NAME                            READY   STATUS    RESTARTS   AGE   IP               NODE     NOMINATED NODE   READINESS GATES
critical-app-6d58b6f947-2sr6k   1/1     Running   0          8s    10.244.196.178   node01   <none>           <none>
critical-app-6d58b6f947-5mt4t   1/1     Running   0          8s    10.244.196.179   node01   <none>           <none>
critical-app-6d58b6f947-khxdk   1/1     Running   0          8s    10.244.196.177   node01   <none>           <none>

You should see 3 running Pods and, if nodeSelector was added, all three should show node01 in the NODE column.

CKA Exam Tips

1. Remember Taint Syntax

The general taint format is key=value:effect. For example:

kubectl taint node node01 critical=true:NoSchedule

2. Toleration Must Match the Taint

For the taint critical=true:NoSchedule, the Pod needs a matching toleration with the same key, value, and effect.

3. Toleration Does Not Mean "Schedule Here"

A toleration only allows a Pod to be scheduled on a tainted node; it does not force the Pod onto that node. To require a specific node, combine the toleration with a nodeSelector targeting that node.