Step 1: Count the Nodes
Begin by verifying the total number of nodes (including the control plane) in your cluster. Run the following command:This output confirms that both the control plane and node01 are active and ready.
Step 2: Check Taints on node01
Next, examine node01 for any existing taints. Use thekubectl describe command:
Step 3: Apply a Taint on node01
Now, add a taint to node01 by specifying a key-value pair and an effect. The command below applies a taint with the key “spray”, a value of “mortein”, and an effect of “NoSchedule”:Step 4: Create the “mosquito” Pod Without a Toleration
Create a pod named “mosquito” using the nginx image without specifying any toleration:Ensure that you add the proper tolerations when you need a pod to be scheduled on a tainted node.
Step 5: Create the “bee” Pod With a Toleration
To schedule a pod on node01 despite the taint, create a new pod named “bee” with a toleration for “spray”. Follow these steps:-
Generate an initial YAML manifest using dry-run:
-
Open the generated
bee.yamlfile and add atolerationssection under the spec. The corrected YAML should resemble the following: -
Apply the manifest to create the pod:
-
Monitor the pod creation:
Step 6: Remove the Taint from the Control Plane
Finally, inspect the control plane node to confirm it has a taint restricting regular pod scheduling:Summary
This walkthrough demonstrates the use of taints and tolerations to control pod placement in a Kubernetes cluster:- Initially, node01 had a taint (
spray=mortein:NoSchedule) and the control plane had the default master taint, which prevented the “mosquito” pod from scheduling. - Creating the “bee” pod with the appropriate toleration allowed it to be scheduled on node01.
- Removing the taint from the control plane enabled the “mosquito” pod to be scheduled there.