Sub topic 3
The three QoS classes
This chapter assumes you can read Pod manifests and apply them with kubectl. You should also know the difference between a resource request and a limit. A request is the amount the scheduler reserves for a container. A limit is the maximum the container may use at runtime.
What a QoS class is
Kubernetes sorts every Pod into one of three Quality of Service (QoS) classes. The class is derived from the Pod's resource requests and limits. You never set it directly. The kubelet uses the class when a node runs short of memory, to decide which Pods to protect and which to sacrifice first.
| Class | Meaning | Protection under pressure |
|---|---|---|
| Guaranteed | Every container has CPU and memory requests equal to limits | Highest |
| Burstable | At least one request or limit is set, but the Pod is not Guaranteed | Medium |
| BestEffort | No container sets any request or limit | Lowest |
Guaranteed
Every container in the Pod must set both a CPU and a memory limit, and each request must equal its limit. If you set only limits, Kubernetes copies them into the requests, so that also qualifies.
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: 256MiThe Pod reserves exactly what it may use, so it is the most predictable.
Burstable
A Pod is Burstable when at least one container sets a request or limit, but the Pod does not meet the Guaranteed rules.
apiVersion: v1
kind: Pod
metadata:
name: qos-burstable
spec:
containers:
- name: app
image: nginx:1.27
resources:
requests:
cpu: "250m"
memory: 128Mi
limits:
memory: 256MiHere the memory request (128Mi) is lower than the limit (256Mi), and there is no CPU limit. The container can burst above its request when the node has spare capacity.
BestEffort
A Pod is BestEffort when no container sets any request or limit.
apiVersion: v1
kind: Pod
metadata:
name: qos-besteffort
spec:
containers:
- name: app
image: nginx:1.27The scheduler reserves nothing for this Pod. It runs on whatever is left over, and it is the first to be removed when the node is short of memory.
Check the assigned class
Kubernetes stores the class in the Pod's status. Read it with a JSONPath query:
kubectl get pod qos-guaranteed -o jsonpath='{.status.qosClass}{"\n"}'The command prints Guaranteed. Run it against the other two Pods to see Burstable and BestEffort.
Decision flow
Common mistakes
- Setting only a memory request and limit, then expecting Guaranteed. CPU must match as well.
- Setting requests equal to limits for the main container but forgetting a sidecar. The sidecar makes the Pod Burstable.
- Assuming the class can be edited on a running Pod. It is derived from the spec and does not change.
Exercise
A Pod has one container with requests of cpu 1 and memory 1Gi, and limits of cpu 2 and memory 1Gi. Which QoS class does it get, and why?
Show answer
Burstable. The memory request equals the limit, but the CPU request (1) differs from the CPU limit (2). Guaranteed needs requests equal to limits for both CPU and memory in every container. Some resources are set, so it is not BestEffort.
Exercise
A Pod has two containers. The first sets CPU and memory requests equal to limits. The second sets no resources at all. What is the QoS class?
Show answer
Burstable. The second container has no requests or limits, so the Pod fails the Guaranteed rule. The first container sets resources, so the Pod is not BestEffort.