CPU and memory requests and limits
Requests and limits solve different problems
A resource request describes capacity used for placement decisions. A limit constrains how much a container may consume at runtime. A bookstore service might reserve scheduling capacity of a quarter CPU and 128 MiB of memory, but be allowed to use more under load. A request is not a measurement of current usage or a promise of dedicated CPU cores. The scheduler evaluates requested resources against node allocatable capacity and already scheduled requests, along with other constraints.
Read a container resource manifest
This offline Pod contains two ordinary app containers, without init containers, Pod-level resources or runtime overhead. Both image names are non-deployable placeholders. Resource values here are small teaching examples, not recommendations for production.
apiVersion: v1kind: Podmetadata: name: catalog-resources namespace: book-labspec: containers: - name: catalog image: registry.invalid/bytemind/catalog:demo resources: requests: cpu: 250m memory: 128Mi limits: cpu: 500m memory: 256Mi - name: helper image: registry.invalid/bytemind/helper:demo resources: requests: cpu: 100m memory: 64Mi limits: cpu: 200m memory: 128MiAdd requests across these two containers: 250m + 100m = 350m CPU, and 128Mi + 64Mi = 192Mi memory. Their configured limits total 700m CPU and 384Mi memory, but each limit is enforced at its own container boundary in this example. The helper cannot automatically borrow the catalog container’s unused memory limit.
CPU and memory quantity syntax
One CPU unit represents one physical core or virtual CPU unit depending on the node. 250m is 0.25 CPU; 1000m is one CPU. CPU quantities cannot request precision finer than 1m. For memory, 128Mi means 128 × 1,048,576 = 134,217,728 bytes; 128M means 128,000,000 bytes. 1Gi is 1,073,741,824 bytes. The lowercase m suffix means milli, so a memory value of 400m means 0.4 bytes rather than 400 MiB. Use explicit Mi or Gi for binary memory units, and keep quantity strings in YAML when units are attached.
Placement versus enforcement
In our simplified exercise a node has 400m CPU and 200Mi memory left for requested capacity. The 350m/192Mi Pod fits these two checks, leaving 50m and 8Mi. A node with only 300m CPU left does not fit even when its instantaneous CPU usage is low. This does not guarantee scheduling: other rules, overhead, admission and storage can also matter. Effective requests for init containers and Pod-level settings require additional rules, covered later.
What happens at runtime
CPU limits commonly constrain CPU execution time; a busy container may be throttled rather than killed for exceeding its CPU allowance. Memory enforcement is different: under memory pressure the kernel can kill a process, and container status may show OOMKilled. Memory limits are not a guarantee of application stability. A restart can follow under the applicable restart policy. When a resource limit is specified without its request and no admission default supplies a request, Kubernetes uses the limit as the request. Namespace LimitRanges and quotas may modify or reject a configuration; inspect them in an authorized environment rather than assuming defaults.
Diagnose before raising limits
A Pending Pod with an insufficient-cpu scheduling event is different from a running container with slow responses or a previous OOMKilled state. Check requested capacity and placement events first for Pending; investigate metrics and application behavior for latency; review memory usage, previous state and logs for OOM. A CPU metric showing high utilization is not by itself proof of throttling. kubectl top requires the resource metrics API and cannot on its own establish a memory leak or CPU throttling. Size requests and limits using measured representative load, headroom and failure tests rather than removing all limits or copying a fixed number.
Practice and recap
Use catalog-resources.yaml, resource-fit.json and quantities.json. Calculate the Pod’s total ordinary container requests, convert the example memory values into bytes, and determine which nodes pass the simplified capacity test. Explain how CPU throttling and OOM differ. Next, learn how a workload finishes safely when Kubernetes stops it.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CPU and memory requests and limits — knowledge check
Apply the lesson concepts to original offline scenarios.
What is 250m CPU?
What are the combined requests of the two containers in catalog-resources.yaml?
A node has 300m requested-capacity headroom and 500Mi memory. Does the example Pod fit?
What can happen when a container reaches its CPU limit?
Which memory quantity is exactly 134217728 bytes?