Skip to content

Kubernetes resource request and limit constraints

In Kubernetes, managing computational resources involves defining Requests and Limits for containers. Requests represent the guaranteed amount of resources (CPU or memory) reserved for a container, while Limits define the maximum amount a container can consume^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].

By default, containers in Kubernetes run without resource constraints. To optimize resource usage and prevent any single application from consuming all available node resources, administrators implement constraint policies^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].

Constraint Types

There are two primary mechanisms for enforcing these constraints within a Kubernetes cluster:

  • LimitRange: A policy object that lives within a specific [[Namespace]] to enforce min and max resource constraints on individual Pods or Containers^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].
  • ResourceQuota: A namespace-scoped object that restricts the total aggregate amount of compute resources (e.g., total CPU or memory) that can be requested or limited across all Pods in a Namespace^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].

LimitRange

A LimitRange allows administrators to control resource allocation for resources within a Namespace^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].

Functions

LimitRange ensures that: * Constraints are enforced: It enforces minimum and maximum usage limits for Pods or Containers^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. * Defaults are applied: If a Pod is created without specifying resource requests or limits, the LimitRange automatically injects default values^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. * Ratios are controlled: It manages the ratio between resource requests and limits^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. * Storage is bounded: It restricts the minimum and maximum storage space requested via PersistentVolumeClaim^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].

Behavior

When a LimitRange is active: * If a container does not declare a request or limit, the system assigns the defaultRequest and default values defined in the policy^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]. * Validation: Kubernetes rejects container creation if the declared request falls below the min constraint or if the declared limit exceeds the max constraint^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md].

Sources

^[400-devops-06-kubernetes-k8s-ithelp-day23-readme.md]