Hello, and welcome to this comprehensive lesson. In this guide, we will explore how to combine taints and tolerations with node affinity in Kubernetes to ensure that specific pods run exclusively on designated nodes. In our example, we consider a Kubernetes cluster with three nodes and three pods, each associated with one of three colors: blue, red, and green. The objective is to schedule the blue pod on the blue node, the red pod on the red node, and the green pod on the green node, even when the cluster is shared with other teams running different pods on various nodes.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Problem Overview
In a shared cluster environment, we want to ensure that:- Our dedicated nodes do not run pods from other teams.
- Our pods are not placed on nodes that are primarily serving other workloads.
First Approach: Taints and Tolerations
In this method, each node is tainted with its respective color (blue, red, or green). Correspondingly, each pod is given a toleration that matches the node’s taint. This ensures that:- Only pods with the appropriate toleration can be scheduled on the tainted node.
Second Approach: Node Affinity
Node affinity offers another strategy by allowing you to:- Label nodes with their respective colors (blue, red, and green).
- Define node affinity rules or selectors on pods to match these labels.
Combining Taints, Tolerations, and Node Affinity
To fully dedicate nodes exclusively for specific pods, you can harness the strengths of both approaches by combining them:
- First, apply taints on your nodes
First, apply taints on your nodes. This ensures that pods without the matching toleration are not scheduled on these nodes.
- Next, implement node affinity rules on your pods
Next, implement node affinity rules on your pods. This guarantees that the pods are scheduled only on the nodes with the corresponding color labels.