0
0
Kubernetesdevops~5 mins

Quality of Service classes (Guaranteed, Burstable, BestEffort) in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
Kubernetes uses Quality of Service (QoS) classes to decide how to allocate resources like CPU and memory to containers. This helps keep important apps running smoothly even when the system is busy.
When you want to make sure a critical app always gets the resources it needs.
When you have apps that can use extra resources if available but can work with less.
When you run apps that do not need guaranteed resources and can be slowed down or stopped if needed.
When you want to control how Kubernetes handles resource shortages for different apps.
When you want to optimize resource use on a shared cluster with many apps.
Config File - pod-qos.yaml
pod-qos.yaml
apiVersion: v1
kind: Pod
metadata:
  name: qos-demo
spec:
  containers:
  - name: guaranteed-container
    image: nginx
    resources:
      requests:
        memory: "200Mi"
        cpu: "500m"
      limits:
        memory: "200Mi"
        cpu: "500m"
  - name: burstable-container
    image: nginx
    resources:
      requests:
        memory: "100Mi"
        cpu: "200m"
      limits:
        memory: "300Mi"
        cpu: "1"
  - name: besteffort-container
    image: nginx
    resources: {}

This file defines a Pod with three containers demonstrating each QoS class:

  • Guaranteed: Requests and limits are equal for CPU and memory, so Kubernetes guarantees these resources.
  • Burstable: Requests are less than limits, so the container can use extra resources if available but is not guaranteed.
  • BestEffort: No requests or limits set, so this container gets resources only if nothing else needs them.
Commands
This command creates the Pod with three containers, each having different QoS classes to show how Kubernetes treats their resource needs.
Terminal
kubectl apply -f pod-qos.yaml
Expected OutputExpected
pod/qos-demo created
This command shows the overall QoS class of the Pod based on its containers' resource settings.
Terminal
kubectl get pods qos-demo -o jsonpath='{.status.qosClass}'
Expected OutputExpected
Burstable
-o jsonpath='{.status.qosClass}' - Extracts only the QoS class value from the Pod status
This command gives detailed information about the Pod, including resource requests, limits, and QoS classes for each container.
Terminal
kubectl describe pod qos-demo
Expected OutputExpected
Name: qos-demo Namespace: default Priority: 0 Node: <node-name>/<node-ip> Start Time: <start-time> Labels: <none> Annotations: <none> Status: Running QoS Class: Burstable Containers: guaranteed-container: Container ID: docker://<id> Image: nginx Limits: cpu: 500m memory: 200Mi Requests: cpu: 500m memory: 200Mi State: Running burstable-container: Container ID: docker://<id> Image: nginx Limits: cpu: 1 memory: 300Mi Requests: cpu: 200m memory: 100Mi State: Running besteffort-container: Container ID: docker://<id> Image: nginx Limits: <none> Requests: <none> State: Running Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True
Key Concept

If you remember nothing else from this pattern, remember: Kubernetes uses resource requests and limits to assign QoS classes that control how it prioritizes containers during resource shortages.

Common Mistakes
Setting resource limits but not requests for a container.
This causes the container to be classified as BestEffort, which means it gets the lowest priority and no guaranteed resources.
Always set both requests and limits to get Burstable or Guaranteed QoS classes.
Setting requests and limits to different values but expecting Guaranteed QoS.
Guaranteed QoS requires requests and limits to be exactly equal for all resources.
Set requests and limits to the same values for CPU and memory to get Guaranteed QoS.
Not setting any resource requests or limits.
This results in BestEffort QoS, which can cause the container to be killed first under resource pressure.
Set at least resource requests to avoid BestEffort QoS.
Summary
Create a Pod with containers having different resource requests and limits to see QoS classes in action.
Use 'kubectl get pods' with jsonpath to check the Pod's QoS class.
Use 'kubectl describe pod' to see detailed resource and QoS info for each container.