Kubernetes Resource Limits: CPU, Memory, and QoS

Learn how Kubernetes CPU and memory requests, limits, and QoS affect scheduling and runtime behavior, with a practical load-test worksheet.

published: reading time: 36 min read author: Geek Workbench updated: November 22, 2026
Quick Summary

Kubernetes resource requests guide Pod placement; CPU and memory limits affect runtime enforcement through the node's kernel and container runtime. This guide separates throttling, OOM termination, and node-pressure eviction, explains what QoS does and does not promise, and gives a worksheet for choosing values from representative load measurements.

Kubernetes Resource Limits: CPU, Memory, and QoS

requests and limits look like a pair, but Kubernetes uses them differently. Requests drive Pod placement; on Linux, CPU requests also affect relative weight under contention. CPU limits add quota and throttling, while memory limits can lead the kernel to kill a process. Node pressure can evict a Pod altogether. This guide explains those outcomes, QoS classes, and namespace policies, then gives you a worksheet for choosing values from load-test measurements.

If you need Kubernetes fundamentals first, see the Kubernetes fundamentals post. For workload probes and rollouts, see Kubernetes workload resources; for scheduling constraints, see the advanced scheduling guide.

Introduction

This guide pins its examples to Kubernetes v1.37.1 on Linux with cgroups v2 and containerd v2.3.7, from the containerd 2.3 LTS line. The containerd support matrix lists v2.3.0+ and v2.4.0+ for Kubernetes 1.37; v2.3.7 includes security fixes. Managed clusters may ship a different supported runtime or patch, so check the version and cgroup mode on your nodes before applying runtime-specific diagnostics.

Nodes have finite CPU and memory. The scheduler uses resource requests when deciding whether a Pod fits on a node. At runtime, the kubelet passes resource settings to the container runtime, which configures the Linux cgroups. Requests do not promise a hard minimum of CPU time or memory to the process, and QoS does not by itself determine node-pressure eviction order.

Requests vs Limits Explained

Every container in a pod can specify resource requests and resource limits:

apiVersion: v1
kind: Pod
metadata:
  name: web-app
  namespace: production
spec:
  containers:
    - name: web-app
      image: nginx:1.25
      resources:
        requests:
          memory: "256Mi"
          cpu: "250m"
        limits:
          memory: "512Mi"
          cpu: "500m"

Requests are the resource values the scheduler accounts for when placing a Pod. A node needs enough allocatable capacity to satisfy the Pod’s requests. On Linux, a CPU request also typically affects a container’s relative CPU weight when cgroups compete for CPU. It does not reserve a dedicated core or guarantee that much CPU time at every moment. A memory request is mainly used for scheduling. On cgroups v2, kubelet can use requests for memory.min or memory.low protection when memoryReservationPolicy is configured, and for memory.high throttling when memoryThrottlingFactor is configured. Both behaviors are disabled by default, so a memory request is not a hard reservation.

Limits set runtime ceilings. On Linux, CPU limits are enforced by the kernel through cgroup quota and can throttle a container when it uses its allotted CPU time. A memory limit sets a cgroup memory boundary; when the cgroup runs out of memory, the kernel may kill a process in it. Kubernetes may restart that container according to the Pod’s restart policy. Node-wide memory pressure is handled separately and can lead to Pod eviction.

CPU representation

Kubernetes CPU is measured in CPU units, which correspond to cores or vCPUs according to the node platform. You can express a value as a whole number or millicores (1000m = 1 CPU). Common values:

  • 100m = 0.1 CPU (one-tenth of a core)
  • 250m = 0.25 CPU
  • 500m = 0.5 CPU
  • 1000m = 1 CPU

CPU is compressible. When a container’s CPU demand reaches its quota, the Linux kernel can throttle it until another scheduling period. CPU use alone does not cause the container to be killed.

Memory representation

Memory is measured in bytes. You can use suffixes: Ki (kibibytes), Mi (mebibytes), Gi (gibibytes).

  • 128Mi = 128 mebibytes (~134 MB)
  • 256Mi = 256 mebibytes (~268 MB)
  • 1Gi = 1 gibibyte (~1.07 GB)

Unlike CPU quota, a memory limit is not a rate that Kubernetes throttles around; it caps memory use in the container’s cgroup. With optional Memory QoS configured on cgroups v2, memory.high can throttle allocations before the hard limit. At the hard limit, the kernel may invoke the OOM killer for a process in that cgroup. Inspect the container’s last state and Pod events; an exit code of 137 alone only means the process received SIGKILL and does not prove the cause was a memory limit.

What happens when limits are exceeded

State: Terminated
Reason: OOMKilled
Exit Code: 137

Reason: OOMKilled identifies an out-of-memory termination reported for the container. Check the configured limit, the container’s peak working set, application logs, and whether the node also reported memory pressure before deciding to raise the limit. A higher limit can delay a repeat failure while allowing the workload to consume more node memory.

QoS Classes

Kubernetes assigns pods to Quality of Service classes based on their resource requests and limits:

QoS Class Resource criteria (CPU and memory) What the label tells you
Guaranteed Either every container has non-zero CPU and memory requests and limits with each request equal to its limit, or the Pod has equal CPU and memory requests and limits at Pod level Tightly specified resources; not immunity from failures or eviction
Burstable At least one CPU or memory request or limit is set at container or Pod level, without meeting Guaranteed criteria Some resource settings exist; values can differ by container and resource
BestEffort No container or Pod-level resource sets CPU or memory requests or limits No CPU or memory request is accounted for

Kubernetes v1.37 supports Pod-level CPU and memory resources as a beta feature, enabled by default. A Pod meets Guaranteed criteria through either the per-container rules or, when using Pod-level resources, equal Pod-level CPU and memory requests and limits. Cgroups v2 memory protection and throttling are separate beta behaviors and are not enabled by default in kubelet configuration.

When to Use Each QoS Class

QoS describes how Kubernetes classifies resource settings. It does not replace a capacity plan or application-level availability design.

Use Guaranteed only when equal CPU and memory requests and limits fit the workload’s capacity and isolation needs. Such Pods are usually among the last considered during node-pressure eviction because usage is normally at or below requests. The kubelet still orders candidates by usage versus requests, Pod priority, and usage relative to requests; Guaranteed does not prevent container OOM, node failure, direct deletion, or every eviction.

Use Burstable when resource requests should reflect expected scheduling needs while limits are set separately or omitted. A container may use more than its request when node resources are available, but it is not guaranteed that spare capacity will remain available.

Use BestEffort only when a workload can tolerate competition for unrequested CPU and memory. BestEffort Pods are often early eviction candidates during memory pressure because their usage is above a zero request, but the kubelet’s algorithm also considers Pod priority and usage relative to requests.

Do not choose a QoS class as a substitute for measuring the workload. Set requests and limits from observed behavior, scheduling needs, and the consequences of throttling or OOM termination.

QoS Decision Flow

flowchart TD
    A[Pod submitted] --> B{CPU and memory requests equal limits\nfor every container, or at Pod level?}
    B -->|Yes| G[Guaranteed QoS]
    B -->|No| C{Any requests\nor limits set?}
    C -->|Yes| Bu[Burstable QoS]
    C -->|No| BE[BestEffort QoS]
    Bu --> D{Node under\nresource pressure?}
    BE --> D
    G --> D
    D -->|Usage above requests| L1[Kubelet considers priority\nand usage relative to requests]
    D -->|Usage at or below requests| L2[Not an eviction candidate on this signal]
    D -->|Any QoS class| L3[QoS is a rough clue,\nnot the eviction algorithm]

Guaranteed pods

containers:
  - name: database
    image: postgres:15
    resources:
      limits:
        memory: "2Gi"
        cpu: "2000m"
      requests:
        memory: "2Gi"
        cpu: "2000m"

For container-level settings, every container needs non-zero CPU and memory requests and limits, with each request equal to its corresponding limit. If a Pod uses Pod-level resources, its CPU and memory requests must equal their limits for Guaranteed QoS. This classification does not make the database highly available or protect it from its own memory limit.

BestEffort pods

containers:
  - name: batch-job
    image: my-batch-job
    resources: {}

No CPU or memory requests or limits means BestEffort. During node memory pressure, such a Pod’s usage is above its zero request, so it is a likely eviction candidate. Pod priority and relative usage still matter.

Burstable pods

containers:
  - name: web-app
    image: nginx:1.25
    resources:
      requests:
        memory: "128Mi"
        cpu: "100m"
      limits:
        memory: "512Mi"
        cpu: "500m"

Most Pods with some CPU or memory settings that do not meet the Guaranteed criteria are Burstable. A request affects scheduling and relative CPU weight; it is not a runtime promise that the process will always receive that amount.

LimitRange for Namespace Quotas

A LimitRange sets default, minimum, and maximum resource limits for pods and containers in a namespace. Without it, pods without resource specs become BestEffort.

apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
  namespace: production
spec:
  limits:
    - max:
        memory: "4Gi"
        cpu: "2000m"
      min:
        memory: "64Mi"
        cpu: "50m"
      default:
        memory: "256Mi"
        cpu: "250m"
      defaultRequest:
        memory: "128Mi"
        cpu: "100m"
      type: Container

This LimitRange:

  • Sets maximum memory and CPU per container
  • Sets minimum memory and CPU per container
  • Applies default limits when containers specify no limits
  • Applies default requests when containers specify no requests

Without defaults or an admission policy, a container can be created without CPU or memory requests and limits. The scheduler then accounts for zero requested CPU and memory, which can make placement less predictable under load.

Applying LimitRange

kubectl apply -f limitrange.yaml
kubectl describe limitrange default-limits -n production

The output shows the actual limits applied:

Type        Resource  Min   Max   Default Request  Default Limit
Container    cpu       50m   2     100m             250m
Container    memory    64Mi  4Gi   128Mi            256Mi

ResourceQuota for Cluster-Wide Limits

A ResourceQuota limits total resource consumption in a namespace. Use it to prevent any single namespace from consuming all cluster resources.

apiVersion: v1
kind: ResourceQuota
metadata:
  name: production-quota
  namespace: production
spec:
  hard:
    requests.cpu: "10"
    requests.memory: "20Gi"
    limits.cpu: "20"
    limits.memory: "40Gi"
    pods: "50"
    persistentvolumeclaims: "10"

This quota limits the entire production namespace to 10 CPU requests, 20Gi memory requests, 20 CPU limits, 40Gi memory limits, 50 pods, and 10 persistent volume claims.

Viewing quota usage

kubectl describe resourcequota production-quota -n production

The output shows current usage against the hard limits. When a quota is exhausted, Kubernetes rejects new resource creation in that namespace.

The kubectl describe output breaks down usage by resource type, so you can see how much of your 20Gi memory request limit is currently consumed across all pods in the namespace. It also shows pods count, persistentvolumeclaims, and any other objects the quota tracks.

If usage is approaching a hard limit, you have a few options: scale down pods, increase the quota (if cluster headroom exists), or clean up unused resources. Unlike LimitRange (which enforces per-container constraints at pod creation), ResourceQuota enforces aggregate limits across the entire namespace. Both constraints work together — a pod that passes the LimitRange checks can still get rejected by ResourceQuota if the namespace has already consumed its total allocation.

For programmatic monitoring, query the quota status directly:

kubectl get resourcequota production-quota -n production -o jsonpath='{.status}' | jq

This returns the current usage and hard limits as JSON, which you can feed into alerting tools. Set an alert early enough to leave room for expected deployments and the time needed to adjust quota before new resources are rejected.

Pod Resource Testing and Tuning

Choose resource values from representative workload measurements, then validate them on the same Kubernetes, operating system, runtime, and cgroup setup used in production. kubectl top is a useful spot check, but a single sample does not show peak usage, throttling periods, or application latency.

Load-test worksheet

Run steady-state and peak or burst scenarios that reflect the service’s traffic shape. Resource values vary by workload and platform, so record measurements rather than choosing one fixed percentage for every application:

Scenario p95/p99 latency against SLO, or job time CPU usage and throttling Peak memory / OOM restarts Node pressure or evictions Candidate requests and limits Reason for the values
Steady traffic
Peak or burst traffic

Choose CPU requests with scheduling headroom in mind. If the service is CPU-bound, compare CPU usage and throttling with its latency target. Choose a CPU limit only after weighing the risk of throttling against the need to contain one workload’s CPU use. Set memory requests from the application’s normal working set and placement needs; set a memory limit only after measuring peak use and understanding the effect of an OOM termination. Repeat the measurement after major application, runtime, or workload changes.

To see which runtime Kubernetes reports for each node, use:

kubectl get nodes -o custom-columns=NODE:.metadata.name,KUBELET:.status.nodeInfo.kubeletVersion,RUNTIME:.status.nodeInfo.containerRuntimeVersion,KERNEL:.status.nodeInfo.kernelVersion

Managed providers may expose cgroup details through their node image or support documentation rather than this command. Confirm those details before interpreting CPU or memory metrics.

Vertical Pod Autoscaler

The Vertical Pod Autoscaler (VPA) analyzes historical resource usage and recommends or automatically applies better resource requests:

apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: web-app-vpa
  namespace: production
spec:
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web-app
  updatePolicy:
    updateMode: "Auto"

In Auto mode, VPA evicts and reschedules pods with updated resource specs. In Off mode, it only provides recommendations.

VPA can suggest request values from historical use, but a representative load test is still needed to capture peaks and check the service’s latency target.

Horizontal Pod Autoscaler

The Horizontal Pod Autoscaler (HPA) scales replica count based on CPU, memory, or custom metrics. For a resource utilization target, the percentage is calculated against the container’s request. For example, averageUtilization: 70 means average CPU use at 70% of the requested CPU, not 70% of the CPU limit. Resource requests must be set for the HPA to calculate that utilization target.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web-app-hpa
  namespace: production
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web-app
  minReplicas: 3
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

This HPA targets an average CPU use of 70% of the Pods’ CPU requests and scales between 3 and 10 replicas. A memory target uses the same request-based percentage calculation:

metrics:
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

Trade-off Analysis

Requests vs Limits Trade-offs

Aspect Requests only Requests and limits
Scheduling The scheduler accounts for requests when placing the Pod Limits do not replace requests for scheduler placement
CPU runtime No CPU quota from a CPU limit; relative weight still applies under contention The container can be throttled at its quota
Memory runtime The request guides placement and may be used as a cgroups v2 hint; actual use can contribute to node memory pressure The cgroup limit can cause an OOM kill; node pressure can still affect other Pods
QoS class Usually Burstable if any CPU or memory request is set Guaranteed only when the full criteria are met; otherwise typically Burstable
Trade-off More room to use spare capacity, with less runtime containment More containment, with possible throttling or OOM termination

QoS Class Trade-offs

QoS class Scheduling effect Node-pressure eviction context Use when
Guaranteed Requests still determine placement; equal limits do not reserve a dedicated CPU core Usage is normally at or below requests; kubelet orders eviction candidates by usage versus requests, priority, then usage relative to requests Equal CPU and memory requests/limits fit the workload’s measured profile
Burstable Requests determine placement; extra use depends on available capacity Usage above requests makes the Pod a candidate; priority and relative usage also matter Requests and limits need different values, or a resource limit is omitted
BestEffort No CPU or memory request is accounted for Usage is above a zero request, so these Pods are common candidates under memory pressure Work can tolerate resource competition and eviction

QoS is not a reservation system. Requests affect scheduler accounting, while runtime behavior depends on the resource, kernel, cgroup mode, and container runtime.

LimitRange vs ResourceQuota

Aspect LimitRange ResourceQuota
Scope Per namespace, per container Per namespace, total namespace
What it controls Min/max/default requests/limits Total CPU, memory, pod count
Enforcement Applied when pod is created Checked when resources are created
Use case Prevent BestEffort pods, set defaults Prevent namespace from monopolizing cluster

Vertical Pod Autoscaler vs Manual Resource Tuning

Aspect VPA (Automated) Manual Tuning
Effort Low High (profiling required)
Precision Based on historical data Based on engineered judgment
Disruption Pod evictions in Auto mode None (no changes unless you apply)
Best for Initial baseline discovery Production fine-tuning

CPU Throttling Trade-offs

Aspect With a CPU limit Without a CPU limit
Runtime behavior Can throttle at the configured quota Can use spare CPU, while still competing according to its request and node policy
Latency Quota may add throttling during bursts Removing the quota may reduce throttling, but does not guarantee latency
Containment Caps a container’s CPU time A workload may use more spare CPU than expected
QoS Depends on CPU and memory settings for every container Cannot be Guaranteed solely by setting CPU requests; equal CPU and memory requests/limits are required

For latency-sensitive services, compare both choices under representative load. CPU limit behavior depends on quota enforcement and the kernel/runtime configuration; removing the limit can reduce throttling but allows more use of spare CPU. A CPU request alone does not dedicate CPU cores. Check the cluster’s CPU manager policy if exclusive CPU assignment is required.

Memory Limit Trade-offs

Aspect Lower limit Higher limit
Container OOM risk An application peak can reach the limit sooner More memory growth may fit before the container is OOM-killed
Node risk A constrained container can still be OOM-killed More containers may compete for node memory; a high limit is not reserved capacity
Sizing Compare measured working set and bursts with the service’s failure behavior Do not use a high limit to hide a leak or assume the node has that memory available

There is no universal headroom percentage. Include enough room for measured peaks and known transient allocations, then check node capacity and the cost of an OOM termination.

Production Failure Scenarios

BestEffort Pods Evicted Under Memory Pressure

BestEffort Pods are common candidates for eviction when a node runs low on memory because their memory use is above a zero request. That does not mean the kubelet orders every eviction by QoS class alone.

When node pressure crosses an eviction threshold, the kubelet first considers whether each Pod’s usage exceeds its requests, then Pod priority, then usage relative to requests. QoS is a useful rough guide for memory pressure, not the algorithm. A BestEffort Pod has a zero CPU and memory request, so its usage is above its requests; a lower-priority Burstable Pod whose usage is also above requests may still be evicted first.

Node-pressure eviction is different from a container hitting its memory limit. The former evicts a Pod to reclaim node resources; the latter can cause the kernel to kill a process inside a container’s cgroup.

Symptoms to watch for:

  • Frequent evictions in kubectl get events --all-namespaces | grep Evicted
  • Containers with OOMKilled as the last termination reason (inspect the container state and node events to identify container-limit or node-wide pressure)
  • One namespace with constant churn while the rest of the cluster looks fine

Mitigation:

  1. Set measured CPU and memory requests for workloads that need predictable scheduling. Any CPU or memory request moves a Pod with no other settings from BestEffort to Burstable.
  2. Use LimitRange to enforce minimum resource requests per namespace so new containers cannot become BestEffort.
  3. Monitor kube_pod_info grouped by QoS class to track how many BestEffort pods exist in each namespace.
  4. For batch workloads that genuinely have no resource requirements, isolate them in a dedicated namespace with their own ResourceQuota.
kubectl get events --namespace production --field-selector reason=Evicted

kubectl get pods -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.qosClass}{"\n"}{end}' | sort | uniq -c

OOMKilled Pods from Memory Limit Too Low

When the kernel cannot satisfy a container’s memory allocation within its cgroup limit, it may kill a process in that cgroup. The container can then show OOMKilled, depending on the runtime and restart policy. Raising the limit is one possible fix, but first check whether the application leaks, whether a transient allocation is expected, and whether the node has capacity for the higher value.

Check actual memory usage first:

kubectl describe pod <pod-name>  # Look for OOMKilled in state
kubectl top pod <pod-name>  # Check actual memory usage

Compare the observed peak with the test’s traffic, application logs, and node pressure. Staging results are useful only when the workload shape resembles production; there is no fixed percentage that fits every service.

CPU Throttling Impacting Latency

CPU limits can throttle containers even when the node has free CPU. That may affect latency for a service with tight response-time targets.

On this Linux/cgroups v2 baseline, a CPU limit is enforced as a quota. Once the cgroup uses its allotted CPU time in a period, the kernel throttles it until a later period. This can happen while a node has spare CPU capacity, because the container has reached its own quota. CPU requests affect relative weight under contention; they do not set this quota.

Compare throttling metrics with latency and node CPU availability. Average CPU can hide short throttling bursts, but low average CPU and high latency do not prove throttling by themselves; application queues, locks, and downstream dependencies can cause the same pattern.

Diagnosing CPU throttling:

kubectl exec <pod-name> -c <container-name> -- cat /sys/fs/cgroup/cpu.stat

If the container exposes the cgroup file, compare nr_throttled and throttled_usec across samples rather than judging one cumulative value. Metric names and cgroup visibility depend on the runtime, container cgroup namespace, and monitoring configuration.

If your monitoring setup exports cAdvisor metrics, compare these series for the same container over the load-test window: container_cpu_cfs_periods_total, container_cpu_cfs_throttled_periods_total, and container_cpu_cfs_throttled_seconds_total.

If p99 latency rises while throttled periods increase, the CPU limit may be contributing. Confirm the relationship during a repeatable load test before changing the limit.

Workloads where this matters most:

  • API servers with strict SLA latency targets (p99 < 50ms)
  • Real-time data pipelines processing events with deadlines
  • gRPC services where a single slow response blocks a client thread
  • Any service where request queuing is not an option

Remediation:

  1. Compare the service under a CPU limit and without one; removing the limit can reduce quota throttling but increases the amount of spare CPU the container may use.
  2. Revisit the CPU request using scheduler headroom and measured contention. A request is not a dedicated CPU core.
  3. If you keep a CPU limit, choose it from measured behavior and test the effect on latency. Equal CPU and memory requests and limits across all containers would be needed for Guaranteed QoS; matching the CPU values alone is not enough.

For batch workloads where latency is irrelevant, CPU limits are useful to prevent one job from monopolizing available CPU. For latency-sensitive services, treat CPU limits as a knob to use carefully or not at all.

Anti-Patterns

Copying Identical Requests and Limits Across Workloads

Copying one resource profile across every Pod can mis-size workloads. A web server handling 1000 req/s may need a different CPU and memory profile from a batch job processing queues.

Profile each application type separately and set appropriate resource specs.

Workload profiles fall into a few distinct categories:

Workload type CPU profile Memory profile Example
Request-driven web servers Moderate, stable Moderate, bounded API gateways, frontend services
Background workers Low or bursty Variable or higher Queue processors, batch transformers
Data-intensive services High High, possible growth ML inference, image processing
Cached services Low Grows to configured cache size Redis, in-memory aggregators

The worksheet above is a better starting point than example values copied from another service. Compare representative traffic, latency, CPU usage and throttling, memory working set, restarts, and node pressure. Do not set identical requests and limits for every workload just to obtain one QoS class; choose values that match each service and document the trade-off.

Not Setting Memory Limits

Memory limits can cap one container’s cgroup use, but they do not prevent every node-level OOM event. They can also cause the container’s own process to be killed when its working set reaches the limit. Set them only after considering both failure modes and the node’s total memory budget.

Without a memory limit, a container may use more than its request when memory is available. If the node then runs out of memory, kubelet eviction and the kernel’s node OOM handling can affect multiple workloads. A container-level memory limit narrows that container’s cgroup, but it does not guarantee that the rest of the node is protected from memory pressure.

Keep the failure cases separate:

Event Possible effect What to inspect
Container reaches its memory cgroup limit Kernel may kill a process in that cgroup; the container may restart Container last state, configured limit, application logs
Node crosses an eviction threshold Kubelet may evict selected Pods to reclaim memory Node conditions, Pod events, requests, priorities, and node-level usage
Node-wide OOM Kernel may kill one or more processes on the node Kernel/node logs and events; do not assume only one Pod was affected

Memory leaks can consume memory over time. A growing Java heap, retained Python objects, or a Go process with expanding goroutine stacks can all increase a container’s working set. Without a memory limit, node pressure and kubelet eviction are the remaining safeguards, and they can affect other Pods.

An application with a working set that rises from 128Mi during quiet hours to 1Gi at peak may use memory above its request when the node has capacity. The kernel can reclaim some memory, such as cache, but memory the process keeps can contribute to pressure on other Pods.

Use measured peak memory plus the known transient allocations of the application as inputs, then verify that the selected limit fits node capacity. A fixed 20–30% margin is not a general rule, and a limit does not stop an application leak before it reaches that value.

Setting CPU Limits Without Measuring the Workload

An arbitrary CPU limit, whether very high or low, may not fit the workload. The scheduler uses requests for placement, not limits.

Choose CPU limits from measured behavior and the consequences of throttling. A high limit can provide a large burst ceiling, but it can also allow several containers to compete for more CPU than the node has.

The scheduler accounts for requests, not CPU limits, when placing a Pod. If a container requests 100m and has a 4000m limit, the request is used for placement and the limit is a runtime ceiling. The request is not a hard runtime guarantee, and the limit does not reserve 4000m on a node.

For example, ten containers with 100m CPU requests and 4000m limits can fit on a four-core node by request accounting if other constraints allow it. If they all use CPU at once, their combined demand exceeds the node’s capacity; each may compete or hit its own quota. Requests guide placement but do not promise that the node can satisfy every container’s limit simultaneously.

Under simultaneous bursts, measure CPU contention and throttling alongside latency. The effect depends on each container’s quota, cgroup configuration, node load, and application behavior; do not infer a latency failure from oversubscription alone.

Base CPU requests and limits on the service’s workload profile and latency target. There is no universal CPU value for a request rate; measure the application under representative concurrency.

For latency-sensitive services, test CPU limits against the service’s SLO and throttling metrics. Removing a limit may give the container more access to spare CPU, but the request still does not reserve a core. For batch workloads, decide whether a CPU cap is needed to control contention, then validate it under concurrent load.

Interview Questions

1. What is the difference between a resource request and a resource limit in Kubernetes?

Expected answer points:

  • Requests define what a container needs — the scheduler uses requests to decide node placement
  • Requests guide scheduling and can affect relative CPU weight under contention; they do not guarantee a hard runtime minimum.
  • CPU limits can throttle a container; a memory limit can cause the kernel to kill a process in that container's cgroup.
  • A node must have enough allocatable resources to satisfy a pod's requests
  • The kubelet and container runtime enforce runtime settings through the operating system; node pressure can affect multiple Pods.
2. What happens when a container exceeds its memory limit versus its CPU limit?

Expected answer points:

  • CPU: Linux cgroup quota can throttle a container after it uses its allotted CPU time.
  • Memory: the kernel may kill a process in the container's memory cgroup; the container may restart according to its restart policy.
  • Node-pressure eviction is a separate kubelet action that can remove a Pod to reclaim node resources.
  • Correlate throttling counters with latency; high p99 alone does not prove CPU throttling.
3. What are the three Kubernetes QoS classes and how are they assigned?

Expected answer points:

  • Guaranteed — either every container has non-zero CPU and memory requests and limits with each request equal to its limit, or Pod-level CPU and memory requests equal their limits when Pod-level resources are used.
  • Burstable — at least one CPU or memory request/limit is set at container or Pod level, but the Pod does not meet Guaranteed criteria.
  • BestEffort — no container or Pod-level resource sets CPU or memory requests or limits.
  • QoS is not the eviction algorithm; node-pressure eviction considers usage versus requests, Pod priority, then usage relative to requests.
4. When should you use Guaranteed QoS versus Burstable QoS?

Expected answer points:

  • Use Guaranteed only when equal CPU and memory requests/limits fit the workload and its capacity plan.
  • Burstable allows requests and limits to differ, or one value to be omitted; spare capacity may not always be available.
  • Guaranteed does not prevent OOM termination, node failure, direct deletion, or every node-pressure eviction.
  • Decide whether BestEffort is acceptable from the workload's tolerance for resource competition and eviction.
5. What is a LimitRange and what does it enforce?

Expected answer points:

  • A LimitRange can set defaults and min/max requests and limits for selected resources in a namespace.
  • Without defaults, an omitted request may be accounted as zero; if a limit is set alone, Kubernetes may copy it to the request when no admission default applies.
  • It applies defaults when containers do not specify requests or limits
  • It validates configured ranges; it does not guarantee that an admitted value matches the workload's measured needs.
6. What is a ResourceQuota and how does it differ from a LimitRange?

Expected answer points:

  • ResourceQuota limits total resource consumption across an entire namespace
  • LimitRange sets per-container defaults, minimums, and maximums
  • ResourceQuota limits only the resource totals and object counts specified in its quota for that namespace.
  • Both are namespace-scoped and enforced at pod creation time
7. How does the Vertical Pod Autoscaler help with resource configuration?

Expected answer points:

  • VPA analyzes historical resource usage and recommends or automatically applies better resource requests
  • Auto mode evicts and reschedules pods with updated specs
  • Off mode only provides recommendations without making changes
  • Historical recommendations can help establish an initial request, then load-test the result against peak use and the service's SLO.
8. How does OOMKilled happen and how do you diagnose it?

Expected answer points:

  • `OOMKilled` indicates an out-of-memory termination reported for the container; an exit code of 137 alone is not enough to identify the cause.
  • Diagnose with `kubectl describe pod ` — look for OOMKilled in container state
  • Check Pod and node events, application logs, the configured cgroup limit, and memory samples; `kubectl top` is only a point-in-time view.
  • Mitigation depends on the cause: adjust measured sizing, reduce memory use, or address node pressure.
9. What is CPU throttling and how does it affect application performance?

Expected answer points:

  • On Linux, a CPU limit is enforced through cgroup quota; a container can be throttled after using its period's allotment.
  • The container runs but may get less CPU time than it wants; compare throttling with latency before attributing a slowdown to quota.
  • Compare throttled periods and latency; high latency with low average CPU is not conclusive by itself.
  • Test with and without limits against the SLO; CPU requests alone do not provide dedicated cores.
10. What is the relationship between resource requests and the Kubernetes scheduler?

Expected answer points:

  • The scheduler uses requests (not limits) to decide which node a pod goes on
  • A node must have at least as much allocatable resources as the pod's requests
  • Limits do not affect scheduling decisions — only requests do
  • Requests guide scheduler placement; on Linux, CPU requests also typically affect relative weight under contention.
  • A request is not a hard runtime guarantee that a process will always receive that amount.
11. How do memory limits differ from CPU limits?

Expected answer points:

  • Memory limits can lead the kernel to kill a process in the container's cgroup; they do not eliminate node memory pressure.
  • CPU limits can throttle a cgroup; a CPU request affects scheduling and relative weight, not a dedicated core.
  • Without a limit, a container may use spare node memory above its request and contribute to pressure.
  • Node-pressure eviction and node-wide OOM handling are separate from a container's memory-limit OOM.
12. How does the Horizontal Pod Autoscaler work with resource metrics?

Expected answer points:

  • HPA scales replicas based on observed CPU or memory utilization against a target
  • For a Resource metric, `averageUtilization: 70` is average CPU use at 70% of the Pods' CPU requests, not their limits.
  • HPA can also use custom metrics or external metrics for scaling decisions
  • HPA works alongside resource requests — it scales replica count, not the per-pod resource size
13. What happens when a namespace exceeds its ResourceQuota?

Expected answer points:

  • Kubernetes rejects new resource creation in that namespace
  • Pod creation fails with "exceeded quota" error
  • The quota applies to both requests and limits depending on the quota spec
  • Use `kubectl describe resourcequota -n ` to see current usage against hard limits
14. What anti-patterns exist around Kubernetes resource configuration?

Expected answer points:

  • Copying identical requests and limits to every workload instead of measuring each service.
  • Treating a memory limit as a guarantee against node pressure or as a fix for a memory leak.
  • Setting CPU quotas without checking their effect on throttling and latency.
  • Assuming a request guarantees runtime resources or that QoS alone determines eviction order.
15. How do you tune resource limits for a latency-sensitive service?

Expected answer points:

  • Monitor actual p99 latency in production to determine if CPU throttling is occurring
  • Compare CPU throttling counters and latency under representative load; test a higher or absent CPU limit before changing production settings.
  • Choose memory limits from measured peak behavior and node capacity; no fixed margin fits every workload.
  • Use VPA in Off mode first to understand actual resource consumption before setting production values
16. How does Kubernetes handle resource overcommitment in a cluster?

Expected answer points:

  • Requests can be lower than configured limits, so Pods may use more CPU or memory than their requests when resources are available.
  • The scheduler accounts for requests when placing Pods; CPU and memory limits are enforced at runtime.
  • Under node pressure, the kubelet considers whether usage exceeds requests, Pod priority, then usage relative to requests; QoS is only a rough clue.
  • Memory use above requests can increase utilization but may cause memory pressure or OOM termination if too many workloads grow at once.
17. How do LimitRange and ResourceQuota work together to enforce resource constraints?

Expected answer points:

  • LimitRange operates at the container level within a namespace — it sets defaults, minimums, and maximums for individual pods
  • ResourceQuota operates at the namespace level — it caps total requests and limits across all pods in the namespace
  • A LimitRange can set a default request to avoid zero-accounted CPU/memory; a ResourceQuota only caps the totals configured in its spec.
  • Both are enforced at pod creation time — pods that exceed either constraint are rejected
18. When multiple pods share the same QoS class, how does Kubernetes determine eviction order?

Expected answer points:

  • For node-pressure eviction, the kubelet first considers whether usage exceeds requests, then Pod priority, then usage relative to requests.
  • Node-pressure eviction does not evict Pods whose usage does not exceed their requests.
  • QoS can help estimate likely behavior for memory pressure, but the kubelet does not use QoS class as its eviction algorithm.
  • PriorityClass changes one factor in that ordering; it does not prevent eviction or replace a capacity plan.
19. How do Vertical Pod Autoscaler and Horizontal Pod Autoscaler work together?

Expected answer points:

  • VPA adjusts the resource requests (CPU/memory) of individual pod containers — it changes what each pod needs
  • HPA adjusts the replica count of a Deployment or StatefulSet — it changes how many pods run
  • VPA handles vertical scaling (bigger/smaller pods); HPA handles horizontal scaling (more/fewer pods)
  • If both are used, check their interaction: HPA utilization targets use requests as their denominator, so VPA changing requests can change the scaling signal.
20. What does the Kubernetes notation for CPU and memory values mean in practice?

Expected answer points:

  • CPU: `100m` = 0.1 CPU, `1` = one CPU unit (a core or vCPU according to the platform), and `1000m` = 1 CPU.
  • Memory: `Ki`, `Mi`, and `Gi` are binary units based on powers of 1024; `K`, `M`, and `G` are decimal units based on powers of 1000.
  • Kubernetes resource quantities have supported precision limits, but the smallest valid quantity is not a useful sizing recommendation; use values that reflect workload demand and scheduler needs.

Further Reading

Conclusion

Use this checklist when configuring Kubernetes resource limits:

  • Set requests from measured workload needs; they guide placement, and CPU requests can affect relative weight under contention.
  • Set CPU limits only after measuring throttling and its effect on the service’s latency target.
  • Set memory limits from measured peaks and node capacity; account for container OOM termination and node-pressure eviction separately.
  • Use LimitRange for namespace defaults and per-container bounds, and ResourceQuota for namespace totals.
  • Use VPA recommendations or monitoring as inputs, then validate values under representative load.
  • Monitor OOM restarts, CPU throttling, node pressure, and evictions together with application latency.
  • Treat QoS as context. Kubelet eviction order considers usage above requests, Pod priority, then usage relative to requests.
  • Choose Guaranteed only when its per-container or Pod-level criteria fit the workload; do not set identical values across services just to get the class.
  • Use BestEffort only for workloads that can tolerate unrequested resource competition and possible eviction.

Category

Related Posts

Container Security: Image Scanning and Vulnerability Risks

Implement comprehensive container security: from scanning images for vulnerabilities to runtime security monitoring and secrets protection.

#container-security #docker #kubernetes

Deployment Strategies: Rolling, Blue-Green, Canary

Compare and implement deployment strategies—rolling updates, blue-green deployments, and canary releases—to reduce risk and enable safe production releases.

#deployment #devops #kubernetes

Developing Helm Charts: Templates, Values, and Testing

Create production-ready Helm charts with Go templates, custom value schemas, and testing using Helm unittest and ct.

#helm #kubernetes #devops