The BestEffort pod has the lowest priority in the Resource QoS classes. Therefore, in the case of a resource shortage, this BestEffort pod will be terminated by the Kubernetes scheduler, then will yield CPU and memory resources to other, higher priority pods.
In order to configure a pod as a BestEffort, you need to set the resource limit as 0 (explicit), or specify no resource limit (implicit).
- Prepare a pod configuration that explicitly sets the spec.containers.resources.limits as 0:
$ cat besteffort-explicit.yml
apiVersion: v1
kind: Pod
metadata:
name: besteffort
spec:
containers:
- name: nginx
image: nginx
resources:
limits:
cpu: 0
memory: 0
- Create the pod on both the chap8-qos and chap8-no-qos namespaces:
$ kubectl create -f besteffort-explicit.yml --namespace=chap8-qos
pod "besteffort" created
$ kubectl create -f besteffort-explicit.yml --namespace=chap8-no-qos
pod "besteffort" created
- Check the QoS class; both pods have the BestEffort class:
$ kubectl describe pods besteffort --namespace=chap8-qos | grep QoS
QoS Class: BestEffort
$ kubectl describe pods besteffort --namespace=chap8-no-qos | grep QoS
QoS Class: BestEffort
There is a pitfall : if you don't set any resource settings in the pod configuration, the pod takes a value from the namespace's default settings. Therefore, if you create a pod with no resource settings, the result will be different between chap8-qos and chap8-no-qos. The following example demonstrates how the namespace settings affect the result:
- Delete the preceding pods from the chap8-qos and chap8-no-qos namespaces:
$ kubectl delete pod --all --namespace=chap8-qos
pod "besteffort" deleted
$ kubectl delete pod --all --namespace=chap8-no-qos
pod "besteffort" deleted
- Prepare a pod configuration that doesn't have resource settings:
$ cat besteffort-implicit.yml
apiVersion: v1
kind: Pod
metadata:
name: besteffort
spec:
containers:
- name: nginx
image: nginx
- Create the pod on both namespaces:
$ kubectl create -f besteffort-implicit.yml --namespace=chap8-qos
pod "besteffort" created
$ kubectl create -f besteffort-implicit.yml --namespace=chap8-no-qos
pod "besteffort" created
- The result of the QoS class is different:
$ kubectl describe pods besteffort --namespace=chap8-no-qos |grep QoS
QoS Class: BestEffort
$ kubectl describe pods besteffort --namespace=chap8-qos |grep QoS
QoS Class: Burstable
Because the chap8-qos namespace has the default setting request.cpu: 0.1, it causes the pod to configure with the Burstable class. Therefore, we will use the chap8-no-qos namespace, which avoids this unexpected result.