WHAT is the core idea? You describe the end state in YAML. K8s runs a reconciliation loop: continuously compare desired state vs actual state, and take actions to close the gap.
action=reconcile(desired,observed)
This is exactly a control system — like a thermostat. That analogy is the whole design.
Derivation from a conservation idea. Suppose current replicas Rcur collectively show metric value Mcur (e.g. average CPU% or requests/sec), and you want each replica to sit at target Mtar. Assume load is shared evenly and scales linearly with replicas. Total load L=Rcur⋅Mcur. To make per-replica load equal Mtar:
Rcur⋅Mcur=Rdes⋅Mtar⇒Rdes=Rcur⋅MtarMcur
Kubernetes rounds up (ceil) so you never under-provision:
What are the two states K8s reconciles? → desired vs actual/observed.
Which field drives scheduling, request or limit? → request.
Formula for desired replicas? → ⌈RcurMcur/Mtar⌉.
What happens on exceeding a memory limit? → Pod is OOM-killed.
Which object runs batch training to completion? → Job.
Why does a Service use labels not IPs? → Pod IPs change constantly.
Recall Feynman: explain to a 12-year-old
Imagine you run a pizza shop with many identical chefs (Pods). You tell the manager (Kubernetes): "always keep 3 chefs working, each needs one oven." If a chef quits, the manager hires a new one instantly. If a huge rush comes, the manager adds chefs (autoscaling). Customers phone one number (Service) and the manager routes them to whichever chef is free — they never need to know which chef. You never manage chefs by hand; you just tell the manager the goal, and it keeps things true.
Socho Kubernetes ek "cluster ka operating system" hai. Tum usse sirf desired state batate ho — jaise "mere model server ki 3 copies chalao, har ek ko 1 GPU aur 8 GB RAM chahiye". Uske baad Kubernetes ek loop chalata hai jise reconciliation loop kehte hain: baar-baar check karta hai ki actual state desired ke barabar hai ya nahi, aur difference ko theek karta rehta hai. Koi Pod crash ho gaya? Turant naya bana dega. Yehi thermostat wali feeling hai — tum temperature set karte ho, machine khud manage karti hai.
ML ke liye ye isliye zaroori hai kyunki inference traffic bursty hota hai aur training bade resources maangti hai. Yahan do cheezein yaad rakho: request (guaranteed minimum jo scheduler reserve karta hai — Pod ko kaunse Node pe rakhna hai ye isse decide hota hai) aur limit (maximum ceiling — memory limit cross hui to Pod OOM-killed, CPU limit cross hui to throttle). GPU/memory ke liye aksar request=limit rakhte hain kyunki GPU share nahi ho sakti.
Autoscaling ka funda simple hai. Agar 4 replicas pe CPU 90% chal raha hai aur tumhe 50% chahiye, to formula Rdes=⌈Rcur⋅Mcur/Mtar⌉=⌈4×90/50⌉=8 replicas. Logic: load replicas ke saath linearly bat-ta hai, to zyada replicas add karke per-replica load neeche laate hain. Chhote fluctuations pe ye scale nahi karta (10% tolerance band), taaki oscillation na ho.
Ek aur important baat — Service kabhi bhi specific Pod IP pe route nahi karta, wo labels ke through Pods dhoondta hai, kyunki Pods marte-bante rehte hain aur unke IP badalte rehte hain. Batch training ke liye Job, scheduled retraining ke liye CronJob, aur distributed training ke stable ranks ke liye StatefulSet use karo. Bas yeh mental model pakad lo: tum goal likhte ho, Kubernetes usse sach banaye rakhta hai.