Kubernetes Resource Requests and Limits Explained

Resource requests and limits are foundational to Kubernetes scheduling and stability — misconfigured or absent settings are a very common cause of cluster instability. This guide covers understanding and configuring them correctly.

Requests vs Limits: The Key Distinction

SettingPurpose
RequestsGuaranteed minimum, used by the scheduler to decide pod placement
LimitsMaximum a container can use before being throttled (CPU) or killed (memory)

Basic Resource Configuration

resources:
  requests:
    memory: "256Mi"
    cpu: "250m"
  limits:
    memory: "512Mi"
    cpu: "500m"

250m means 250 millicores, or a quarter of one CPU core — Kubernetes CPU units are fractional, unlike memory which uses standard byte-based units (Mi, Gi).

Why Requests Matter for Scheduling

The scheduler places pods on nodes with sufficient available capacity based on requested (not actual current) resource usage — a pod requesting more than any node can provide will remain unschedulable (Pending status) indefinitely.

Why Missing Requests/Limits Is a Genuine Problem

Without explicit resource specifications, a pod could theoretically consume unbounded resources, potentially starving other pods on the same node — production clusters should generally require explicit resource specifications for every workload.

What Happens When a Container Exceeds Its Memory Limit

The container is OOMKilled (Out Of Memory killed) — visible in kubectl describe pod output, a common cause of the crash-debugging scenario in How to Debug a Crashing Pod in Kubernetes.

What Happens When a Container Exceeds Its CPU Limit

Unlike memory, CPU is throttled (not killed) when exceeding the limit — the container continues running but is artificially slowed, a different (often less immediately obvious) symptom than memory limit violations.

Setting Requests Based on Actual Observed Usage

kubectl top pod POD_NAME

Rather than guessing, observe actual resource consumption under realistic load (see How to Right-Size Your VPS Based on Actual Usage Data for the general principle, applied here at the pod level) before finalizing request/limit values.

Setting Namespace-Level Resource Quotas

See Kubernetes Namespaces and Resource Quotas Explained — beyond individual pod-level settings, namespace-level quotas prevent any single namespace/team from consuming disproportionate cluster resources.

Using LimitRanges for Default Values

apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
spec:
  limits:
    - default:
        memory: 512Mi
        cpu: 500m
      defaultRequest:
        memory: 256Mi
        cpu: 250m
      type: Container

Ensures every container in a namespace gets sensible default resource settings even if the pod definition itself omits them, providing a safety net against unspecified resource configuration.

Balancing Requests and Limits Appropriately

Setting requests too low risks OOM/throttling under real load; setting them too high wastes cluster capacity (the scheduler reserves the requested amount even if actual usage is lower) — find genuine balance based on observed usage patterns, not arbitrary guessing.

Common Errors

Pods stuck Pending with "Insufficient cpu/memory" in events — either your cluster genuinely lacks capacity for the requested resources, or requests are set unreasonably high relative to actual node capacity; verify against actual node resources with kubectl describe nodes.

Continue Reading

Browse more articles in Kubernetes & Container Orchestration.

  • kubernetes resource requests limits, kubernetes oomkilled, kubernetes cpu throttling, kubectl top pod
  • 0 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

What Is Kubernetes and When Do You Need It on a VPS?

Kubernetes is a container orchestration platform — it automates deploying, scaling, and...

How to Install a Single-Node Kubernetes Cluster with k3s

k3s is a lightweight, certified Kubernetes distribution designed to run efficiently on modest...

How to Install kubeadm and Set Up a Multi-Node Kubernetes Cluster

kubeadm is the official tool for bootstrapping a standard, full-featured Kubernetes cluster. This...

Kubernetes Pods, Deployments & Services Explained

Understanding these three core Kubernetes objects — Pods, Deployments, and Services —...

How to Expose Applications with a Kubernetes Ingress Controller (Nginx Ingress)

An Ingress lets you route external HTTP/HTTPS traffic to multiple services within your cluster...