Skip to content

Compressible vs incompressible resources in Kubernetes

In Kubernetes, resources are categorized based on how the system handles resource contention. The primary distinction is made between compressible resources (like CPU) and incompressible resources (like Memory), which directly determines how Pods are treated when resources become scarce^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

Definition

Compressible Resources are resources for which supply can be throttled or restricted without causing a fatal process failure. In Kubernetes, CPU is the standard compressible resource^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]. When CPU resources are exhausted, a Pod enters a state of "starvation" (throttling) where it receives less processing time, but it does not terminate^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

Incompressible Resources are resources that cannot be throttled; once the limit is reached, the application cannot function. Memory is the standard incompressible resource^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]. When Memory resources are exhausted, the Pod is terminated by the kernel via an OOM (Out-Of-Memory) kill^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

Impact on Scheduling and Eviction

This classification influences the Quality of Service (QoS) and the Kubernetes scheduling mechanism.

When a node experiences resource pressure, the kubelet performs Eviction (resource reclamation) to free up space^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md]. The order in which Pods are selected for eviction depends heavily on their resource usage and QoS class.

  1. BestEffort Pods: These are the first to be evicted.
  2. Burstable Pods: These are evicted if BestEffort Pods are not consuming enough resources to resolve the pressure.
  3. Guaranteed Pods: These are the most protected^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

A Pod with a Guaranteed QoS class (where requests equal limits for all containers) is only evicted if its usage exceeds its limits or if the node is in a critical Memory Pressure state^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

Resource Configuration

In a Pod specification, requests and limits define resource consumption^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

  • Requests: Used by the kube-scheduler to determine where to place the Pod^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].
  • Limits: Used by the kubelet to set the constraints (e.g., via Cgroups)^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

Setting a lower request and a higher limit (Borg model) allows for resource overcommitment, relying on the compressible nature of CPU and the OOM behavior of Memory to manage contention^[400-devops__06-Kubernetes__k8s-paas__原理及源码解析__Kubernetes调度机制.md].

Sources