Kubernetes Resource Units as Powers of Two

TL;DR / Summary: Kubernetes memory requests often look friendlier when sized near powers of two because node capacity, page sizes, and human mental math all share that language. Use 2ⁿ MiB steps for predictable bin-packing, then adjust with metrics — not folklore.

Why 256Mi, 512Mi, and 1Gi keep showing up

Cluster nodes advertise memory in binary-ish chunks. Humans compare those chunks faster when requests jump by doubling: 128 → 256 → 512 → 1024. The pattern is not a law of Kubernetes; it is a readability contract that reduces off-by-one sizing debates in pull requests.

CPU is different — millicores are decimal — so do not force fake powers of two onto 100m just for symmetry. Apply the doubling habit where binary units already dominate: memory and ephemeral storage.

Bin-packing intuition with doubling steps

Imagine a 16Gi node after the OS and system pods take roughly 2Gi. You have about 14Gi of schedulable RAM. Pods requesting 3Gi leave awkward remainders. Pods requesting 2Gi or 4Gi tile the node with less leftover sand.

Leftover sand becomes unschedulable capacity that still costs money. Doubling steps will not eliminate waste, but they shrink the weird gaps that appear when every team invents 768Mi “because it felt right.”

Pick a ladder. Document the ladder. Climb it with metrics.

A starter ladder for app teams

  • 128Mi — tiny sidecars and CLI jobs
  • 256Mi — small APIs with modest caches
  • 512Mi — typical web workers
  • 1Gi — JVM-ish services after heap tuning
  • 2Gi / 4Gi — data-local caches, heavier workers

Skip rungs only with a graph attached. “We need 700Mi” should arrive with a week of RSS percentiles, not a vibe.

Requests vs limits

Keep requests on the ladder. Limits may sit one rung above during incident response, then return. Permanent limit sprawl recreates noisy-neighbor drama.

Page cache and the illusion of free RAM

Linux loves cache. A container that “barely fits” at 900Mi may look fine until a noisy neighbor flushes cache and latency spikes. Sizing near 1Gi with headroom is often calmer than clinging to 900Mi to win a density contest.

Watch working set estimates, not only averages. Averages lie during GC pauses and queue bursts.

Horizontal pods vs vertical doubling

When load grows, teams double memory out of habit. Sometimes you should double replicas instead. Memory doubling helps when a single process holds a large in-memory map. Replica doubling helps when work is embarrassingly parallel and stateful sticky sessions are absent.

Write the decision rule in the runbook: “If p95 latency rises with CPU saturation → scale out. If RSS climbs toward the limit with CPU calm → scale up one rung.”

Ephemeral storage deserves the same honesty

Log spills and unpackaged assets blow disks in powers-of-two-shaped chunks more often than you think — image layers, tar extracts, and buffer files. Set ephemeral-storage requests on the same ladder when the workload writes temporary trees.

Pods evicted for disk feel like mysterious disappearances. They are usually missing requests.

Teaching newcomers without shame

Show a spreadsheet of 2ⁿ MiB values beside a node’s allocatable memory. Ask which combinations fill a 8Gi allocatable slice with the least remainder. The exercise beats a abstract lecture on the scheduler.

Then open production graphs and break the toy model on purpose. Reality always wins; the ladder is a starting language.

Calculator on the desk during reviews

During PR review, a quick glance at 2 to the power of n keeps everyone honest about what “the next size up” means. Then paste the actual metrics screenshot under the YAML change.

No metrics, no rung climb.

Node pool SKUs and the same ladder

Cloud node sizes themselves often jump in doubling-ish RAM steps. Aligning pod requests to those steps makes it obvious when a workload belongs on a different pool. A 3Gi request on a pool of 4Gi nodes is a packing puzzle you chose for yourself.

During capacity reviews, print allocatable memory beside your request ladder. The visual mismatch ends arguments faster than vibes.

JVM heaps inside power-of-two containers

Java services frequently set heap as a fraction of the container limit. If the limit is 1Gi and the heap is 75%, leave room for metaspace and direct buffers — otherwise the pod dies “for no reason” at traffic you already tested at a lower heap.

Document heap = f(limit) in the Dockerfile comments so the next engineer does not “optimize” by deleting headroom.

HPA interactions with vertical rungs

Horizontal Pod Autoscaler multiplies whatever request you chose. A too-large rung multiplied by ten replicas wastes a node pool; a too-small rung multiplied by ten still OOMs. Tune the rung before you tune maxReplicas.

Record the date you last changed requests beside the HPA config so future readers know which lever moved last.

Burstable versus Guaranteed classes

When requests equal limits on a power-of-two rung, you enter Guaranteed territory (simplified). That can be correct for latency-critical pods and wrong for batch. Choose the QoS class deliberately after picking the rung — do not stumble into it.

Retiring cargo-cult sizes

Quarterly, list pods whose requests never changed while traffic doubled. Those services are either overprovisioned or about to page someone. Re-fit them to the ladder with fresh data.

Powers of two will not autopilot capacity planning. They will keep your YAML readable and your leftover node memory less embarrassing — which is a quietly expensive problem when the cluster bill arrives.