Bin Packer: Requests & Limits
Pods book CPU and memory; the scheduler places them by what they booked. Then real usage decides who gets slowed, killed or evicted.
New to Kubernetes? Read this first
Think of booking seats on a train. The ticket office (the scheduler) only counts seats booked, not who actually turns up or how much luggage they bring. Here, a pod books CPU and memory; what it really uses can be smaller or bigger.
- Node
- A machine with a fixed amount of CPU and memory. Each node here has 2000m CPU (two cores) and 2048Mi memory.
- Pod
- A running app. The scheduler places each pod on one node.
- Request
- What a pod books. The scheduler adds up bookings and only places a pod where its booking still fits. Nothing is set aside on the machine: a pod can use less than it booked, or more.
- Limit
- A hard cap on what the pod may use. Over its CPU cap it is slowed down. Over its memory cap it is killed and restarted.
- Usage
- What the pod actually uses right now.
- Load
- Multiplies every pod’s usage. Requests and limits stay the same.
Units: CPU is in millicores, 1000m is one core. Memory is in mebibytes, 1024Mi is 1Gi. The requests and limits post walks through this lab step by step.
Start here: move Load to 1.25x and watch node-b. Every pod fit by its requests, but actual usage didn’t, so node-b evicts cache-2. Then try 1.75x (CPU throttling) and 2x (memory OOM kills).
Load multiplies what every pod actually uses. Requests and limits stay the same.
- Booked (requests): What the scheduler counts when it places pods.
- Actually using: What the pods really use at this load.
- Memory-pressure line: If memory in use goes past it, the node evicts pods until it is back under.
Memory-pressure line at 1792Mi
Memory-pressure line at 1792Mi
Memory-pressure line at 1792Mi
Not scheduled (0)
Every pod fits somewhere. Queue a pod with a big request to see Pending.
Pod states
Placed on a node and using no more than its limits allow.
It wants more CPU than its CPU limit. The kernel caps its CPU time, so it runs slower. Nothing is killed.
It used more memory than its memory limit. The kernel kills the container and the kubelet restarts it inside the same pod, on the same node.
Its node ran short of memory, so the kubelet removed the whole pod. Its controller (a Deployment here) creates a new pod to replace it. A pod with no controller would not come back.
No node has enough unbooked CPU or memory left for its requests, so the scheduler cannot place it yet. It waits.
Its request is bigger than its limit. Kubernetes refuses a spec like that, so it never reaches the scheduler.
QoS class (eviction order)
Requests equal limits for both CPU and memory. It cannot use more memory than it booked, so it is usually the last to be evicted. It is not immune.
Some requests or limits are set, but not all equal. It can use more than it booked, and the more it uses beyond its request, the earlier it is evicted.
No requests or limits at all. It books nothing, so any memory it uses counts as over its request when the node runs short.
QoS changes the eviction order. It does not make any pod immune.
Custom pod
BurstableDemand at 1x load (what the app actually wants, independent of requests)
Effective requests: 250m, 256Mi
What this hides
One container per pod, restartPolicy: Always, owned by a Deployment, all at equal priority. This is a snapshot, not a timeline.
OOM is instant here. The real kernel kills the container after memory goes over its limit, and the kubelet restarts it.
Eviction follows the kubelet's order: pods using more than their memory request first, then the largest overage above request. It is not sorted by QoS class directly.
Here a replacement only shows up once the load drops back. In a real cluster the Deployment creates it straight away, and the scheduler places it like any new pod, maybe on another node.
Not modelled: allocatable vs capacity, CPU shares under contention, priority and preemption, taints and affinity.