Kubernetes
tainting
node management
container orchestration
cluster management

Tainting in k8s

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Tainting is a powerful feature in Kubernetes (k8s) that allows you to control the scheduling of pods on nodes to ensure optimal resource management and to satisfy specific requirements. Understanding how taints work is crucial for implementing node affinity and anti-affinity scenarios and ensuring that your workloads run on the appropriate nodes.

Taint and Toleration

Concepts

Taints are applied to nodes, allowing you to repel a set of pods from being scheduled on them. Nodes can have multiple taints, which consist of three components: `key`, `value`, and `effect`. The `effect` can take one of three values:

  • `NoSchedule`: New pods will not be scheduled onto the node unless the pod has a matching toleration.
  • `PreferNoSchedule`: The system will try to avoid placing a new pod onto the node.
  • `NoExecute`: New pods will not be scheduled onto the node, and existing pods will be evicted if they do not have the matching toleration.

Tolerations, on the other hand, are applied to pods and allow a pod to be scheduled on nodes with matching taints. A toleration consists of `key`, `operator`, `value`, and `effect`.

Example

Consider a scenario where you have a specific set of nodes designated for GPU workloads. You can taint these GPU nodes with a key `dedicated`, a value of `gpu`, and an effect of `NoSchedule`:

  • name: gpu-container
  • key: "dedicated"
  • Automating Taints: Consider using Kubernetes Node Feature Discovery (NFD) to automate the tainting of nodes based on their hardware or software characteristics.
  • Combining Techniques: Combine taints with other scheduling features like resource requests/limits and priorities for fine-tuned control over pod scheduling.
  • Dynamic Tainting: Use Kubernetes events and monitoring tools to trigger dynamic tainting for maintenance or scaling purposes.
  • Overuse: Excessive use of taints can lead to underutilization of cluster resources. Utilize monitoring tools to ensure nodes are not left unscheduled without necessity.
  • Coordination: Ensure that both developers and operations teams are coordinated on taint and toleration strategies to avoid conflicts between workload needs and node usage policies.
  • Security Implications: Be cautious with the use of tolerations as they might allow unauthorized workloads onto dedicated nodes.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.