Sub topic 6
QoS classes and how they are assigned
This chapter assumes you can write pod manifests and apply them with kubectl. It also assumes you know what requests and limits are, how CPU is throttled at its limit, and how memory over the limit causes an OOM kill.
What a QoS class is
Kubernetes puts every pod into one of three Quality of Service (QoS) classes. The class is not something you set. The API server computes it from the requests and limits in the pod spec and stores it in status.qosClass. The kubelet uses the class later to decide which pods to evict first when a node runs short of resources.
The three classes are Guaranteed, Burstable, and BestEffort.
The assignment rules
Kubernetes checks the rules in this order:
| Class | Rule |
|---|---|
| Guaranteed | Every container, including init containers, has a CPU request, a CPU limit, a memory request, and a memory limit. Request equals limit for each. |
| BestEffort | No container has any CPU or memory request or limit. |
| Burstable | Everything else. At least one container has a request or limit, but the pod does not meet the Guaranteed rules. |
Two details cause most mistakes:
- The rules apply to the whole pod, not to one container. If one container in a two-container pod has no limits, the pod cannot be Guaranteed.
- If you set only limits, Kubernetes copies each limit into the matching request. A container with
limits.cpu: 500mandlimits.memory: 256Miand no requests therefore becomes Guaranteed.
Guaranteed example
Setting requests equal to limits for both resources gives the pod the Guaranteed class.
apiVersion: v1
kind: Pod
metadata:
name: guaranteed-web
spec:
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: 500m
memory: 256Mi
limits:
cpu: 500m
memory: 256MiCheck the result with:
kubectl get pod guaranteed-web -o jsonpath='{.status.qosClass}'The output is Guaranteed.
Burstable example
The web pod from the first chapter has requests lower than its limits (250m CPU against 500m, 128Mi memory against 256Mi). It is Burstable. The pod may use more than it requested, up to its limits, when the node has spare capacity.
A pod is also Burstable if it sets only a memory request, or if it sets CPU requests and limits but only a memory request. Any gap breaks the Guaranteed rules.
BestEffort example
A pod with no resources section is BestEffort, unless a LimitRange in the namespace injects defaults. That interaction is covered in the LimitRange chapter. After defaults are injected, the pod usually becomes Burstable.
apiVersion: v1
kind: Pod
metadata:
name: besteffort-web
spec:
containers:
- name: app
image: nginx:1.27How the class shapes behavior
The class affects two things at runtime.
- Eviction order. When a node is under memory pressure, the kubelet evicts BestEffort pods first, then Burstable pods that use more than their requests, and Guaranteed pods last. The next chapter covers the full order.
- OOM score. The kubelet sets the Linux
oom_score_adjvalue for each container based on its class. Guaranteed containers get a strongly negative adjustment, so the kernel kills them last. BestEffort containers get the highest value, so they are killed first. Burstable containers fall in between, scaled by how much memory they requested relative to the node.
Common errors
- Expecting Guaranteed with only CPU set. Memory must also have matching request and limit values.
- Forgetting a sidecar. A logging sidecar with no resources turns the pod into Burstable.
- Changing the class by editing the pod. The class is fixed at creation, and resource fields of a running pod generally cannot be changed. Create a new pod, or change the Deployment template to roll out replacements.
- Assuming Guaranteed means immune. A Guaranteed pod is still OOM-killed if it exceeds its memory limit. It is only evicted last under node pressure.
Exercise
A pod has two containers. The first sets CPU and memory requests and limits, all equal. The second sets only limits.memory: 128Mi and limits.cpu: 100m. What QoS class does the pod get, and why?
Show answer
Guaranteed. When only limits are set, Kubernetes copies them into the requests, so the second container has request equal to limit for both resources. The first container already meets the rule, so every container qualifies.
Exercise
A pod has one container with requests.memory: 256Mi and limits.memory: 256Mi, and no CPU settings. What is its QoS class?
Show answer
Burstable. The pod sets a request and limit, so it is not BestEffort. It lacks CPU requests and limits, so it does not meet the Guaranteed rules.