Kubernetes CPU and Memory Resources¶
Kubernetes manages computing resources by abstracting the underlying processor architecture and exposing them as basic units.^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md] To ensure resources are scheduled effectively and fairly across the cluster, Kubernetes relies on Request and Limit configurations^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
Resource Types¶
Kubernetes defines CPU and Memory resources using specific units of measurement.
CPU¶
CPU resources are measured in cores.^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md] One CPU unit is equivalent to: * 1 AWS vCPU * 1 GCP Core * 1 Azure vCore * 1 Hyperthread on a capable Intel processor^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]
Memory¶
Memory resources are measured in bytes and can be expressed as a plain integer or with a suffix (E, P, T, G, M, K).^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]
Requests and Limits¶
Requests and Limits are the mechanisms used to manage resource allocation and utilization.
Requests¶
A Request is the minimum amount of a resource required by a container.^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md] It serves as the primary criteria for the Kubernetes scheduler: a Pod will only be scheduled to a node if the node's allocatable resources are greater than or equal to the Pod's resource requests^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
The value for a request must adhere to the following rule:
0 <= request <= Node Allocatable
Limits¶
A Limit is the maximum amount of a resource a container is allowed to use.^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md] Setting a limit to 0 implies no constraint is placed on resource usage^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
The value for a limit must be greater than or equal to the request:
request <= limit <= Infinity
Quality of Service (QoS)¶
Based on the Request and Limit settings, Kubernetes classifies Pods into three Quality of Service (QoS) classes, which determine the priority and stability of Pods during resource contention^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
Guaranteed¶
A Pod is classified as Guaranteed when every container within it meets the following conditions^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]:
* request.memory equals limit.memory
* request.cpu equals limit.cpu
These Pods have the highest priority. They will not be killed or throttled unless their resource usage exceeds their limits and no lower-priority Pods can be evicted^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
Burstable¶
A Pod is classified as Burstable if^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]: * It is not a Guaranteed Pod. * At least one container in the Pod has a memory or CPU request set.
These Pods have a minimum resource guarantee but can utilize more resources when available^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]. If no BestEffort Pods exist and system capacity is insufficient, Burstable Pods are the first to be killed^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
BestEffort¶
A Pod is classified as BestEffort if none of its containers have any requests or limits set^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
These Pods have the lowest priority. In the event of memory shortage, they are the first candidates for eviction^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
Related Concepts¶
- Kubernetes
- Pod
- [[Quality of Service (QoS)]]
- [[Resource Management]]
Sources¶
400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md