Kubernetes employs Quality of Service (QoS) classes to manage and prioritize pod resources, thereby mitigating Out of Memory (OOMKilled) errors.
Understanding OOMKilled Errors
OOMKilled errors occur when a container exceeds its allocated memory, prompting the Linux kernel’s OOM Killer to terminate the process to maintain node stability.
Kubernetes QoS Classes
Kubernetes assigns pods to one of three QoS classes based on their resource requests and limits:
Guaranteed QoS Class
To qualify for the Guaranteed class, all containers in the pod must specify equal memory and CPU requests and limits. These pods get the highest priority and are the last to be terminated under memory pressure.
Example YAML:
1 | apiVersion: v1 |
Burstable QoS Class
Pods are considered Burstable if at least one container has memory or CPU requests set, but not all containers match requests and limits. These pods have a medium priority and may be terminated if the node runs out of resources.
Example YAML:
1 | apiVersion: v1 |
BestEffort QoS Class
Pods that have no resource requests or limits defined fall under the BestEffort class. These pods receive the lowest priority and are the first to be terminated under memory pressure.
Example YAML:
1 | apiVersion: v1 |
Preventing OOMKilled Errors
By appropriately configuring resource requests and limits, Kubernetes ensures that critical applications remain operational even under memory constraints, effectively reducing the occurrence of OOMKilled errors.
Want to learn more? Check out this detailed guide on diagnosing and preventing OOMKilled errors.