Aller au contenu

Lab 01: Managing Taints and Tolerations in Kubernetes

  • Manage workloads using specialized Node Pools (e.g., GPU vs CPU nodes, or test vs production workloads).
  • Configure affinity and anti-affinity rules for pods.
  • Use labels and taints to control pod scheduling onto nodes.
  • Test deployments to validate pod behavior based on configured rules.
  1. A running Kubernetes cluster provided by OKS.
  2. Access to the kubectl CLI.
  3. Administrator privileges on the cluster.
Terminal window
oks-cli cluster kubeconfig --cluster-name my-cluster --project-name my-project > kubeconfig.yaml
export KUBECONFIG=./kubeconfig.yaml

Make sure you have the required permissions to access the target cluster. You must have a user or role that allows you to export or retrieve the cluster configuration.

Terminal window
kubectl get nodes
kubectl describe node <node-name>

This command provides detailed information about the specified Kubernetes node, including labels, taints, capacities, current conditions, and the pods running on it.

Terminal window
kubectl get nodes -o custom-columns=":metadata.name" | xargs -I {} kubectl taint node {} dedicated=workload:NoSchedule

To confirm that taints are applied to each node, use:

Terminal window
kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints
NAME TAINTS
ip-10-91-35-253 dedicated=workload:NoSchedule
ip-10-91-39-104 dedicated=workload:NoSchedule
Terminal window
kubectl run pod-without-toleration --image=nginx --port=80 --dry-run=client -o yaml | kubectl apply -f -

Use the following command to check the pod status:

Terminal window
kubectl get pods

The pod will be in a Pending state because no available node accepts pods without toleration due to the applied taints.

Remove the taint from one of the nodes to allow the pod to be scheduled on it.

Command to remove a taint:

Terminal window
kubectl taint nodes <node-name> dedicated:NoSchedule-

Confirm that the taint has been removed:

Terminal window
kubectl describe node ip-10-91-35-253 | grep Taints

Check the pod status again to confirm it is now running on the node where the taint was removed.

Command:

Terminal window
kubectl get pods -o wide

This lab demonstrated how Kubernetes uses taints and tolerations to control pod placement on specific nodes. When a node is tainted, only pods with matching tolerations can be scheduled onto it.