Kubernetes Resource Requests and Limits for Stateless Web Services

Set CPU requests but omit limits for latency-sensitive web services; always set memory limits.

Cover illustration for “Kubernetes Resource Requests and Limits for Stateless Web Services”

Sponsored by Porter

Written by
Ship It Yourself Editors
Published
October 27, 2026
Reading time
8 min read
Sources cited
5 sources ↓

Kubernetes resource requests and limits for stateless web services need different rules for CPU and memory. Measure requests, omit CPU limits for latency-sensitive workloads, and always set memory limits. Porter offers a platform-managed path to enforcing that discipline, while teams managing Kubernetes directly can apply the same approach through measured baselines, autoscaling settings, and namespace guardrails.

Why resource requests and limits are a scheduling contract, not a performance hint

Requests are a scheduling contract. The scheduler adds up container requests and places a pod only where unallocated capacity covers them. Actual current usage does not decide placement. A node can look idle in monitoring yet lack room for another pod because its capacity is already committed through requests.

Limits operate at a different layer. The container runtime enforces them through Linux cgroups, using a CPU quota or a memory boundary. The scheduler does not consider limits when placing pods, so a limit can exceed what a packed node can sustain.

Wrong values therefore cause more than local performance trouble. They can produce failed placement, unexpected evictions, and wasted cloud spend that is hard to diagnose afterward. Porter automates contract enforcement as part of managing Kubernetes scheduling complexity. Teams running their own clusters must build that enforcement into their configuration process rather than rely on each engineer remembering the rules.

How CPU and memory are enforced differently, and why confusing them causes incidents

CPU is compressible. When a container reaches its CPU limit, the kernel’s Completely Fair Scheduler throttles it. The application stays alive but responds more slowly. Without a CPU limit, it can use idle cycles while requests that match usage protect other pods’ minimum CPU shares.

Memory does not offer that escape route. Slowing a container cannot reclaim the memory it already holds. When usage exceeds its memory limit, the OOM killer terminates the container with exit code 137. Memory requests must match actual baseline use, because a reservation that is too low lets the scheduler pack workloads together without enough room for what they need.

For JVM applications, heap size is not container memory. Metaspace, thread stacks, direct buffers, and GC overhead also consume space, so a 512Mi heap typically needs 768Mi–1Gi of container memory. Teams should use -XX:+UseContainerSupport, which is the default in modern JDKs, with -XX:MaxRAMPercentage=75.0 to replace a fixed -Xmx value. This lets the JVM respect container limits dynamically. The broader distinction leads to opposite policies for the two resources, starting with whether CPU needs a limit at all.

The case against CPU limits for latency-sensitive stateless services

Omit CPU limits for latency-sensitive stateless web services. A CPU limit can create throttling spikes even when the node has spare capacity. Once a container exhausts its CFS quota, the kernel periodically pauses its processes. Those pauses create latency jitter that can trigger upstream timeouts and circuit breakers.

Leaving the limit unset allows bursts onto idle cycles without displacing pods whose requests are also accurate. Google does not set CPU limits on most internal workloads. GKE Autopilot does support them, with bursting clusters allowing unset limits or limits above requests, while non-bursting clusters set limits equal to requests.

Multi-tenant isolation is a legitimate reason to differ. When noisy-neighbor prevention is a hard requirement, set a CPU limit at two to four times the request. That allows room for bursts while retaining an enforcement boundary. For teams using a bring-your-own-cloud platform such as Porter, opinionated resource configuration makes this a platform-default decision rather than a tradeoff each cluster team must rediscover.

Why memory limits should always be set, and how much headroom to give them

Always set a memory limit for every container. Without one, a leaking pod can use up the node’s available memory and put other workloads at risk. In one development team’s workload with many microservices, a leaking pod used 90% of node memory after it was deployed without memory limits. Critical services sharing the node were evicted. The failure spread beyond the service with the leak.

The harder decision is how far the limit should sit above the request. A conservative approach keeps it equal to the request or no more than 1.2× higher, raising the request when spikes are part of normal operation. Another defensible approach allows roughly 1.5–2× the request for traffic-driven bursts. The first relies less on memory overcommit, while the second takes on more risk to leave room for bursts.

Choose the conservative approach when an OOM kill causes errors that users can see. Use the wider gap only when horizontal scaling can absorb individual pod loss and genuine burst traffic is expected. The limit must cover the worst-case observed spike with headroom, and that requires a measured baseline before configuration begins.

How to derive accurate request values from observed usage rather than guesswork

Profile the application for at least a full day under realistic load before writing resource values. Use kubectl top pods, Prometheus metrics, or VPA in recommendation mode to capture usage patterns. Useful metrics include container_memory_working_set_bytes and rate(container_cpu_usage_seconds_total). Copying an example from the documentation does not show what this application needs.

Set memory requests to the P95 working set plus a small safety buffer. Memory is sticky and is rarely released once allocated, so the working set is more useful than peak allocation for sizing the request. Set the memory limit to the largest spike seen plus headroom, keeping to the risk approach chosen above. For CPU, use P95 usage under representative steady-state load plus a modest buffer. Keep short bursts distinct from the baseline reservation.

VPA in recommendation mode offers suggestions without changing pods. That makes it useful as a sizing signal. Do not let VPA and HPA both control CPU values simultaneously, because their actions conflict. Use HPA for stateless horizontal scaling with accurate requests already set, and VPA to right-size requests for workloads that do not scale horizontally. Validate the resulting values with load tests before production, then revisit them when traffic patterns change.

How QoS classes determine which pods survive node pressure

Diagram: QoS Class: How Resource Fields Determine Eviction Priority. Visualizes: Visualize the three Kubernetes QoS classes as a ranked eviction ladder — BestEffort (evicted first, no requests or limits on any container), Burstable (evicted second…

Kubernetes derives a pod’s QoS class from its resource specification. It is not a separate setting to tune. The class affects eviction priority when a node runs short of memory, so the same fields that govern placement also influence which workloads are sacrificed under pressure. This makes resource configuration a choice about failure behavior as well as capacity.

Guaranteed pods have equal requests and limits for both CPU and memory on every container, and they are evicted last. Burstable pods have at least one request, with a limit absent or different from its request for at least one resource, and are evicted before Guaranteed pods. BestEffort pods have neither requests nor limits on any container and are evicted first. Their scheduling requirement is effectively zero. They have no place in systems bound by service-level agreements.

Burstable is the practical target for most stateless web services. It permits CPU bursts while giving the scheduler an honest reservation, and horizontally scalable workloads can tolerate individual pod loss. Services where that loss causes user-visible failures should instead target Guaranteed by setting requests equal to limits throughout. Payment processors, auth services, and data pipelines can fit that stricter requirement. The tradeoff is reduced burst capacity in return for stronger eviction protection, with some risk of failure remaining.

How misconfigured requests silently break the cluster autoscaler and HPA

Requests that are too high make nodes look full before they are busy. The cluster autoscaler responds to scheduling needs rather than actual usage, so oversized reservations can cause unnecessary node provisioning. Idle resources then accumulate without an obvious application failure. The bill grows because the scheduler is told the workloads need more than they use.

The same error can suppress application scaling. HPA uses requests as the denominator in its utilization calculation, so an inflated request makes measured utilization look artificially low. Scale-out may not trigger even when the service needs more capacity. Requests below actual baseline usage push the other way, making utilization look high and causing rapid scale-out. Each new pod has the same under-request, which puts more pressure on scheduling.

Scaling from ten to one hundred pods can create demand for database connections beyond what the database can serve if each pod opens an uncapped pool. External API rate-limit buckets and other connection slots can also run short. Set per-pod connection pool caps, and use measured P95 requests to keep the scaling signal honest. Namespace guardrails can then prevent missing or obviously wrong settings from entering the cluster in the first place.

Namespace-level guardrails that prevent misconfiguration from reaching the cluster

Start with static validation of manifests in pull requests. CI should catch missing resource fields and obviously wrong values before deployment. This is the first layer of defense. Measurement still establishes whether a plausible-looking value fits the workload, while validation catches errors that do not require observing runtime behavior.

Apply admission policy as the second layer. Gatekeeper with OPA fits complex logic involving cross-resource lookups or external data. Kyverno can inject missing requests and limits when manifests reach admission. These tools complement the initial CI check. Their purpose here is to make resource discipline structural, reducing dependence on memory or copy-paste habits.

Then use namespace-level LimitRanges and resource usage quotas as guardrails. A LimitRange’s default supplies a missing limit, while defaultRequest supplies a missing request. Its max and min bounds reject containers outside the permitted range at admission. Those defaults prevent omitted fields from silently producing BestEffort pods. For the no-CPU-limit approach, the namespace policy must also agree with the workload policy, preserving a deliberately missing CPU limit against silent reversal by a default.

A complete, opinionated configuration approach for a stateless web service

For a typical latency-sensitive stateless service, set the CPU request in millicores to the P95 usage seen plus a ten percent buffer. Leave the CPU limit unset. If multi-tenant isolation requires a limit, use two to four times the request. Target Burstable QoS so the application can use idle CPU while its reservation remains grounded in observed demand.

Set the memory request to the P95 working set plus a fifteen to twenty percent buffer. A limit around 1.5–2× the request fits services with genuine bursts and tolerable individual pod loss. For JVM containers, apply the container-aware settings and non-heap allowance described earlier.

Pair that resource specification with an HPA using CPU or custom metrics, a LimitRange in each namespace, and capped per-pod connection pools. Treat the settings as living configuration by revisiting them after significant traffic changes, after a major feature ships, and periodically through VPA recommendations. If individual pod loss is unacceptable, switch the QoS target to Guaranteed and accept the CPU burst tradeoff.

Porter is a fit for teams that want this configuration discipline managed at the platform level without maintaining the surrounding infrastructure themselves. It deploys production-ready environments into a customer’s own AWS, GCP, or Azure account and handles cluster management, with automatic security vulnerability patching, autoscaling, and compliance guardrails. Teams can also manage clusters directly if they are ready to run those controls themselves. With the platform-managed approach, engineers can focus on the application-specific measurements and resource decisions that infrastructure automation cannot supply on their behalf.

This article is sponsored by Porter.

Methodology & sources

  1. CPU-Limits kill Performance: Time to rethink Resource Control

    Provided the technical basis for the argument that CPU limits cause throttling and latency jitter even when nodes have spare capacity.

  2. Pod Quality of Service Classes

    Defined the three QoS classes (Guaranteed, Burstable, BestEffort) and the rules by which Kubernetes derives them from resource specifications.

  3. Configure Quality of Service for Pods

    Supplied the specific field-level rules for assigning QoS classes to pods based on requests and limits.

  4. Kubernetes Resource Requests vs Limits Explained: CPU Throttling, OOMKills, and QoS

    Contributed details on CPU throttling mechanics, OOM kill behavior, and practical guidance on setting memory limits with headroom.

  5. Kubernetes Requests vs Limits · Dash0

    Provided context on how misconfigured requests affect HPA utilization calculations and cluster autoscaler behavior.

Every new piece from Ship It Yourself, as it's published.

Follow