π§ Concept 13: Resource Requests & Limits (Scheduling + Performance π―)




π 1. Core Idea (1-line)
π Requests = guaranteed resources, Limits = maximum allowed resources
π§ 2. Why This Concept Exists (VERY IMPORTANT β οΈ)
Without limits:
-
One pod can consume ALL CPU/RAM β
-
Other apps starve π΅
π Cluster becomes unstable
π‘ 3. Two Key Terms
π’ 1. Requests (Minimum guarantee)
π Scheduler uses this to decide:
- Where to place the pod
Example:
requests:
cpu: "500m"
memory: "256Mi"π Means:
-
Needs at least 0.5 CPU
-
Needs at least 256MB RAM
π΄ 2. Limits (Maximum cap)
limits:
cpu: "1"
memory: "512Mi"π Means:
-
Cannot exceed 1 CPU
-
Cannot exceed 512MB RAM
βοΈ 4. How Scheduling Works (VERY IMPORTANT π₯)
π Kubernetes scheduler checks:
- Node has enough requests capacity?
β Yes β Pod scheduled
β No β Pod pending
π₯ 5. Runtime Behavior
CPU:
-
Can burst above request (until limit)
-
If exceeds limit β throttled β οΈ
Memory:
- If exceeds limit β OOMKilled π
π¦ 6. Example YAML
resources:
requests:
cpu: "200m"
memory: "128Mi"
limits:
cpu: "500m"
memory: "256Mi"π§ 7. VERY IMPORTANT Concepts
π CPU Units:
-
1000m = 1 CPU
-
500m = 0.5 CPU
π Memory Units:
-
Mi = Mebibyte
-
Gi = Gibibyte
π₯ 8. Real-world DevOps Insight
For your ML workloads π:
-
Inference β moderate CPU + memory
-
Training β high CPU/GPU
π Set proper limits to avoid:
-
Node crash
-
Resource starvation
β οΈ 9. Common Mistakes (INTERVIEW TRAPS)
β Not setting requests β bad scheduling
β Setting limits too low β OOMKill
β Setting limits too high β waste resources
πΌ 10. Interview Answer
π βResource requests define the minimum resources required for scheduling, while limits define the maximum resources a container can consume, ensuring fair resource usage and cluster stability.β
β‘ 11. CKA Commands
kubectl describe pod <name>π Shows:
-
Requests
-
Limits
-
OOMKilled events
π§ 12. Memory Trick
π Request = reservation πͺ
π Limit = boundary π§
π₯ 13. Pro Insight (Real-world)
-
Always set requests + limits
-
Use:
-
HPA (autoscaling)
-
Metrics (Prometheus)
π Optimize based on usage
π Next Step
Bol:
π βnextβ
Then we go to:
π₯ Concept 14: HPA (Horizontal Pod Autoscaling π― β VERY IMPORTANT FOR REAL WORLD)