Day 15/40 - Kubernetes Node Affinity Explained | How Node Affinity Works

About this video

### Summary of the Video Content: 1. **Introduction**: - The video is part of the DK 2024 series, specifically video number 15. - The main topic is **Node Affinity**, a scheduling concept in Kubernetes. 2. **Objective**: - To explain and demonstrate **Node Affinity** in depth. - To differentiate between **Affinity** and **Taints & Tolerations** (covered in the previous video). - To provide practical tasks on GitHub for viewers to practice. 3. **Key Concepts**: - **Taints & Tolerations**: - These allow nodes to repel or accept certain pods but do not guarantee pod placement on specific nodes. - Limitations include the inability to add multiple conditions or expressions. - **Node Affinity**: - Ensures pods are scheduled on nodes with specific labels. - Uses **labels and selectors** to match pods to nodes. - Provides more control over pod scheduling compared to taints and tolerations. 4. **Node Affinity in Detail**: - **Labels and Selectors**: - Nodes are labeled (e.g., `disk=HDD` or `disk=SSD`). - Pods specify affinity rules to match these labels. - **Operators**: - Supports operators like `In`, `NotIn`, `Exists`, etc., allowing complex conditions. - **Properties**: - **Required During Scheduling, Ignored During Execution**: - Ensures pods are only scheduled on nodes with matching labels. - If no match is found, the pod remains in a pending state. - **Preferred During Scheduling, Ignored During Execution**: - Prefers matching labels but schedules the pod even if no match is found. - Useful when scheduling is prioritized over node-specific placement. 5. **Demo Highlights**: - Demonstrated how to define **Node Affinity** in YAML files. - Showed the impact of label changes on pod scheduling: - Changes to node labels do not affect already running pods. - Only new pods are impacted by updated labels. - Explained the use of operators like `In`, `Exists`, and `NotIn`. 6. **Combining Node Affinity with Taints & Tolerations**: - Node Affinity alone cannot prevent pods from being scheduled on non-matching nodes. - Combining **Node Affinity** with **Taints & Tolerations** ensures precise pod placement. - Example: A pod with `toleration: color=green` and `affinity: GPU=true` will only be scheduled on a node with matching labels and tolerations. 7. **Use Cases**: - Dedicated nodes for specific workloads (e.g., GPU-intensive or AI/ML tasks). - High-performance nodes for data warehousing or I/O-intensive tasks. 8. **Conclusion**: - Node Affinity simplifies precise pod scheduling using labels and operators. - Encourages viewers to practice the concepts and complete the GitHub tasks. - Requests likes and comments to unlock the next video on **Resource Requests and Limits**. 9. **Call to Action**: - Engage with the community via Discord or YouTube comments for support. - Rewatch the video for clarity if needed. - Complete the like and comment target to expedite the release of the next video. This summary captures the key points and structure of the video content effectively.


Course: Certified Kubernetes Administrator Full Course For beginners | CKA 2025

This playlist contains the complete CKA series for beginners, based on the latest 2025 curriculum. It includes 40+ videos with hands-on demos, assignments, and exam-based scenarios. We will cover everything from the basics to the Advanced, including fundamental concepts such as Docker, containers, Docker storage and networking, DNS, etc.

View Full Course