Sub topic 4
How Kubernetes assigns a QoS class to a Pod
This chapter assumes you can read Pod manifests, know what CPU and memory requests and limits are, and can run kubectl. It covers the rules that map a manifest to a QoS class and the mistakes that most often give a different class than you expected.
The rules
Kubernetes computes the QoS class when it admits the Pod and stores it in status.qosClass. You cannot set it directly. The class depends only on the resource requests and limits of the containers in the Pod, including init containers.
| Class | Condition |
|---|---|
| Guaranteed | Every container has a CPU limit, a memory limit, a CPU request, and a memory request, and each request equals its limit. |
| BestEffort | No container has any CPU or memory request or limit. |
| Burstable | Everything else. |
The check is per Pod, not per container. One container that breaks the Guaranteed rule makes the whole Pod Burstable.
Three worked examples
This Pod is Guaranteed. Requests equal limits for both CPU and memory.
apiVersion: v1
kind: Pod
metadata:
name: qos-guaranteed
spec:
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: "500m"
memory: 256Mi
limits:
cpu: "500m"
memory: 256MiThis Pod is Burstable. Requests are set, but the CPU limit is missing and the memory request differs from the memory limit.
apiVersion: v1
kind: Pod
metadata:
name: qos-burstable
spec:
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: "250m"
memory: 128Mi
limits:
memory: 256MiThis Pod is BestEffort. It sets nothing.
apiVersion: v1
kind: Pod
metadata:
name: qos-besteffort
spec:
containers:
- name: app
image: nginx:1.27After you apply a manifest, read the assigned class from the Pod status:
kubectl get pod qos-guaranteed -o jsonpath='{.status.qosClass}{"\n"}'The output for the first Pod is Guaranteed.
Common errors
- Setting only limits. If you set a limit and omit the request, Kubernetes copies the limit into the request. A Pod with only equal-valued limits on every container for both resources is therefore Guaranteed. This surprises people who expect Burstable.
- Covering only one resource. Setting CPU request and limit but nothing for memory gives Burstable, not Guaranteed. Both resources must be set on every container.
- Forgetting a sidecar or init container. A Guaranteed app container next to a sidecar with no resources makes the whole Pod Burstable. Check every container in
spec.containersandspec.initContainers. - Mismatched units.
1CPU equals1000m, so they match. Butmemory: 1Giandmemory: 1000Mido not match, because 1Gi is 1024Mi. - Defaults from a LimitRange. A LimitRange in the namespace can inject default requests and limits at admission. A manifest that looks BestEffort may end up Burstable or Guaranteed. Always trust
status.qosClassover the manifest you wrote.
Why the rules matter
The class is not just a label. The kubelet uses it to set OOM scores and to rank Pods for eviction, which later chapters cover. Getting the manifest right is how you choose the treatment a Pod receives when a node runs short of memory.
Exercise
A Pod has two containers. The app container sets cpu and memory requests and limits, all equal. A logging sidecar sets only memory: 64Mi as both request and limit. What is the Pod's QoS class, and what is one change that would make it Guaranteed?
Show answer
Burstable. The sidecar has no CPU request or limit, so the Pod fails the Guaranteed rule, but some resources are set, so it is not BestEffort. Adding a CPU request and limit to the sidecar, with equal values, makes the Pod Guaranteed.