Kubernetes uses Quality of Service classes (QoS) to make decisions about scheduling and evicting pods.
QoS classes:
When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:
- Guaranteed
- Burstable
- BestEffort
Guaranteed:
A pod gets assigned a QoS class of Guaranteed when it satisfies the following,
- Every Container in the Pod must have a memory limit and a memory request.
- For every Container in the Pod, the memory limit must equal the memory request.
- Every Container in the Pod must have a CPU limit and a CPU request.
- For every Container in the Pod, the CPU limit must equal the CPU request.
These restrictions apply to init containers and app containers equally.
apiVersion: v1
kind: Pod
metadata:
name: qos-demo
namespace: qos-example
spec:
containers:
- name: qos-demo-ctr
image: nginx
resources:
limits:
memory: "200Mi"
cpu: "700m"
requests:
memory: "200Mi"
cpu: "700m"
Above is the configuration file for a Pod that has one Container. The Container has a memory limit and a memory request, both equal to 200 MiB. The Container has a CPU limit and a CPU request, both equal to 700 milliCPU.
Now create the pod.
kubectl apply -f qos-pod.yaml
Check the QoS class assigned to Pod,
Burstable:
A Pod is given a QoS class of Burstable if:
- The Pod does not meet the criteria for QoS class Guaranteed.
- At least one Container in the Pod has a memory or CPU request or limit.
apiVersion: v1
kind: Pod
metadata:
name: qos-demo-2
namespace: qos-example
spec:
containers:
- name: qos-demo-2-ctr
image: nginx
resources:
limits:
memory: "200Mi"
requests:
memory: "100Mi"
Above is the configuration file for a Pod that has one Container. The Container has a memory limit of 200 MiB and a memory request of 100 MiB.
Create the Pod:
kubectl apply -f qos-pod-2.yaml
Check the QoS class assigned to Pod:
kubectl get pod qos-demo-2 --namespace=qos-example --output=yaml | grep "qosClass:"
BestEffort:
For a Pod to be given a QoS class of BestEffort, the Containers in the Pod must not have any memory or CPU limits or requests.
apiVersion: v1
kind: Pod
metadata:
name: qos-demo-3
namespace: qos-example
spec:
containers:
- name: qos-demo-3-ctr
image: nginx
Above is the configuration file for a Pod that has one Container. The Container has no memory or CPU limits or requests.
Create the Pod:
kubectl apply -f qos-pod-3.yaml
Check the QoS class assigned to Pod:
kubectl describe -n qos-example pod qos-demo-3 | grep "QoS Class"