Set requests and limits, and understand QoS classes
In this task you'll set requests and limits so the right pods survive when a node runs short.
A request is what the scheduler reserves for a container; a limit is the most it may use. Use more CPU than the limit and the container is slowed down (throttled); use more memory than the limit and it's killed (OOMKilled).
From these, each pod gets a QoS class. Guaranteed: every container has CPU and memory requests equal to its limits. Burstable: at least one request or limit is set, but not Guaranteed. BestEffort: nothing set. When a node runs short of memory, BestEffort pods are evicted first, then Burstable pods using more than they requested, and Guaranteed pods last.
Example. Quayhurst Health's patient portal was evicted during a busy clinic morning, while a reporting job with no requests kept running on another node. They gave the portal Guaranteed resources and put the reporting job in its own namespace with a quota.
Before you start
You need: Docker Desktop and kind on your computer (both free). Time: 30 minutes.
Where to look
- Terminal
- kubectl
Steps
- Create three pods: one with requests equal to limits, one with only requests, and one with neither.
- Check each class:
kubectl get pod <pod> -o jsonpath='{.status.qosClass}'. - Read the node's allocation:
kubectl describe node lab-workerand find Allocated resources. - Decide which pod should survive memory pressure, and give it Guaranteed resources.
Commands
kubectl get pods -o custom-columns=NAME:.metadata.name,QOS:.status.qosClass
kubectl top pods
kubectl describe node <node> | sed -n '/Allocated resources:/,/Events:/p'
Watch out for
- Cost
- Free on kind. On AKS, requests decide how many nodes you pay for: oversized requests waste money.
- Security
- Limits stop one container starving its neighbours; quotas stop one team doing it.
- Common mistakes
- Setting CPU limits far too low (the app slows to a crawl) and setting no memory requests (the scheduler packs nodes too tightly).
Clean up
Delete the three test pods.
Words to know
- Request
- The CPU and memory the scheduler reserves for a container.
- Limit
- The most CPU or memory a container may use; above the memory limit it's killed.
- QoS class
- Guaranteed, Burstable or BestEffort: decides which pods are evicted first under pressure.
- CPU throttling
- Slowing a container down when it tries to use more CPU than its limit.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands OnKeep going
- Kubernetes errors, decodedExplained
- How Kubernetes decides where pods runExplained
- Kubernetes autoscaling: HPA, VPA, KEDA and nodesExplained
- Fix NotReady nodes and disk pressurePrevious in Kubernetes in depth
- Keep apps up during maintenance with disruption budgetsNext in Kubernetes in depth
- Containers and KubernetesAll pages in this topic