Course contentsShow
← Cloud and Infrastructure
Lesson 1358 of 2,98927. Kubernetes Scheduling and ResourcesFree lesson

Node Affinity and Taints Together

Learn how node affinity works with taints/tolerations for advanced placement control.

Node Affinity and Taints Together

What you'll learn: How to combine node affinity rules with taints and tolerations for sophisticated pod placement control.

Understanding the Combination

While node affinity attracts pods to specific nodes and taints repel pods from nodes, using them together creates powerful, multi-layered scheduling logic. Think of it like a bouncer at an exclusive club: taints act as the velvet rope (keeping most people out), while node affinity is the guest list (inviting specific VIPs to specific sections).

When both mechanisms are present, both conditions must be satisfied for a pod to schedule:

  1. The pod must tolerate any taints on the node
  2. The pod must satisfy any node affinity rules it declares

This combination is especially valuable when you want to:

  • Reserve specialized hardware (GPU nodes) for specific workloads while allowing fine-grained placement within that pool
  • Create dedicated node pools with additional placement preferences
  • Implement defense-in-depth scheduling policies

How They Work Together

A tainted node rejects all pods except those with matching tolerations. Among the tolerated pods, node affinity then determines which pods go where based on preferences or requirements.

Example scenario: GPU nodes are tainted to prevent general workloads. ML training pods tolerate the GPU taint, but use node affinity to prefer nodes in specific availability zones or with certain GPU models.

The scheduler evaluates taints first (hard filter), then applies affinity rules (scoring and filtering). If either check fails, the pod won't schedule on that node.

Key Takeaway: Node affinity and taints work as complementary filters—taints create exclusive node pools, while affinity provides nuanced placement logic within those pools for advanced scheduling control.