Module 10: Kubernetes Resource Management & Scheduling

Managing workloads in Kubernetes is not just about deploying applications β itβs about making sure your cluster resources (CPU, memory, nodes) are used efficiently and fairly. In this module, weβll explore how Kubernetes schedules pods and how you can control resource usage using powerful features like Requests, Limits, QoS, Taints, Tolerations, and more.
πΉ 1. Why Resource Management Matters
Without proper resource management:
One pod can consume all CPU/memory and starve others.
Critical workloads may get evicted when nodes run out of memory.
Apps may get scheduled on the wrong nodes.
Kubernetes provides fine-grained controls to handle this.
πΉ 2. Resource Requests & Limits
Every container can specify:
Requests β minimum CPU/memory it needs.
Limits β maximum CPU/memory it can use.
π YAML Example:
apiVersion: v1
kind: Pod
metadata:
name: resource-demo
spec:
containers:
- name: nginx
image: nginx
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
β Kubernetes scheduler uses requests to decide where to place the pod. β Limits protect nodes by capping resource consumption.
πΉ 3. Quality of Service (QoS) Classes
Kubernetes assigns each pod a QoS class automatically:
Guaranteed β Requests == Limits for all containers.
Burstable β Requests < Limits.
BestEffort β No requests/limits set.
π‘ Eviction priority β Guaranteed > Burstable > BestEffort.
πΉ 4. Taints & Tolerations
Taints let you repel pods from specific nodes, unless they tolerate it.
π Example: Taint a node
kubectl taint nodes node1 dedicated=database:NoSchedule
π Pod with toleration
tolerations:
- key: "dedicated"
operator: "Equal"
value: "database"
effect: "NoSchedule"
β Ensures only database pods run on that node.
πΉ 5. Node Affinity & Anti-Affinity
Control where pods get scheduled:
Affinity β attract pods to nodes with certain labels.
Anti-Affinity β spread pods across nodes.
π Example: Schedule pod only on nodes labeled zone=us-east1
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: zone
operator: In
values:
- us-east1
πΉ 6. Pod Priority & Preemption
When resources are scarce:
- Higher priority pods can evict lower priority ones.
π PriorityClass Example
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: high-priority
value: 1000
globalDefault: false
description: "High priority for critical workloads"
π Pod with priority
spec:
priorityClassName: high-priority
β Critical apps always win scheduling battles.
πΉ 7. Hands-On Checklist
Run these in your cluster:
Deploy a pod with requests & limits.
Check QoS class β
kubectl describe pod resource-demo
.Add a taint to a node & deploy a pod with toleration.
Test node affinity by labeling nodes.
Create a high-priority pod & watch it preempt others.
πΉ 8. Kubernetes Resource Scheduling β Visual Diagram
Hereβs a simple architecture to visualize resource scheduling:
Hereβs the colorful diagram showing Nodes (with taints/labels), Pods (with affinity/tolerations), and Scheduler decisions. π
β Conclusion
Resource management ensures that your apps:
Run reliably without resource starvation.
Get placed on the right nodes.
Scale efficiently in shared clusters.
With Requests, Limits, QoS, Taints, Affinity, and Priority, you gain full control over scheduling and prevent cluster chaos. π
Subscribe to my newsletter
Read articles from DevOpsLaunchpad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
