For efficient resource scheduling, Kubernetes uses QoS classes to schedule and evict pods. The service quality of a pod is determined by its CPU usage and memory usage. If a pod does not have sufficient resources, Kubernetes takes actions according to the QoS class of the pod.
Kubernetes defines the following QoS classes, which are listed in descending order of priority:
Guaranteed—Every container on a pod has requests and limits set for both CPU and memory resources, and the request and limit for a resource type are set to the same value.
If a container has memory limits and does not have memory requests, Kubernetes automatically sets memory requests for the container based on the memory limits. Kubernetes performs the same action for CPU resources. |
Burstable—A pod does not meet the requirements of the Guaranteed class, or a pod has at least one container which has the memory or CPU requests configured.
Best-effort—No containers on a pod have limits or requests set for CPU or memory resources.
When resources are insufficient, the system preferentially assigns resources to the pods whose QoS classes have high priority. For example, if memory resources are not enough for all pods, the system kills low-priority pods according to the following rules:
First kill best-effort pods.
If no best-effort pods exist, kill burstable pods.
If no best-effort or burstable pods exist, kill guaranteed pods.
If resources are sufficient, assign the guaranteed class to all pods for high performance and stability.
For efficient resource scheduling, configure QoS classes as follows:
Set the requests and limits for a resource type to the same value on all containers of the pods that provide key services to ensure that the pods have the guaranteed QoS class.