Kubernetes resource constraints and relationships¶
Kubernetes resource constraints and relationships define how compute resources like CPU and memory are allocated, scheduled, and managed within a cluster^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]. Kubernetes manages these resources to ensure high utilization while guaranteeing that critical workloads have the necessary resources to run^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md].
This mechanism primarily relies on defining Requests and Limits for containers, which in turn determines the Pod's Quality of Service (QoS) class and priority during resource contention^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Request and Limit¶
Kubernetes uses two primary Metrics to manage resource allocation: request and limit^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Request¶
The request value specifies the minimum amount of resources required by a container^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- It acts as the dependency for scheduling decisions. A Pod will only be scheduled to a node if the node's available allocatable resources are greater than or equal to the Pod's total requests^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- The value must be greater than or equal to 0 and cannot exceed the node's allocatable capacity^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Limit¶
The limit value defines the maximum amount of resources a container is allowed to use^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- Setting this to 0 implies no restriction is placed on the resource, allowing it to consume up to the available capacity of the node^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- The value must be greater than or equal to the
request(the upper bound is effectively Infinity)^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Relationship¶
The relationship between a container's resource request, limit, and the node's capacity can be summarized by the following inequalities^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]:
0 <= request <= Node Allocatablerequest <= limit <= Infinity
When limit is set higher than request, the container can utilize additional resources (up to the limit) when the node has spare capacity^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Resource Types¶
Kubernetes abstracts underlying hardware into standardized units^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]:
- CPU: Represents computing power. The base unit is "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, or 1 Hyperthread on a supported Intel processor^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- Memory: Represents storage. The base unit is bytes^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- It can be expressed as a plain integer or with suffixes (E, P, T, G, M, K)^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Quality of Service (QoS) Classes¶
Based on the requests and limits defined in the Pod specification, Kubernetes classifies Pods into one of three QoS classes^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。This classification determines the Pod's priority when the node is under resource pressure (e.g., memory shortage)^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Guaranteed¶
A Pod is classified as Guaranteed if every container within it meets the following condition^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]:
request.cpu == limit.cpurequest.memory == limit.memory
These Pods have the highest priority. They are generally not killed or throttled unless they exceed 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 it meets both of the following conditions^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]:
- It is not a Guaranteed Pod.
- At least one container in the Pod has a
requestset for CPU or memory.
These Pods have a minimum resource guarantee but can use more if available. If there are no BestEffort Pods to kill and the system is out of capacity, Burstable Pods may be killed^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
BestEffort¶
A Pod is classified as BestEffort if all containers within it have no requests or limits set^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
- These Pods have the lowest priority.
- In the event of system memory shortage, they are the first candidates for eviction^[400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md]。
Related Concepts¶
- [[Pods]]
- [[Scheduling]]
- [[Eviction]]
Sources¶
400-devops__06-Kubernetes__k8s-ithelp__Day21__README.md