{"id":158,"date":"2026-11-20T07:52:00","date_gmt":"2026-11-20T07:52:00","guid":{"rendered":"https:\/\/tothepowerof2.com\/blog\/?p=158"},"modified":"2026-11-15T08:33:42","modified_gmt":"2026-11-15T08:33:42","slug":"kubernetes-resource-units-as-powers-of-two","status":"publish","type":"post","link":"https:\/\/tothepowerof2.com\/blog\/kubernetes-resource-units-as-powers-of-two\/","title":{"rendered":"Kubernetes Resource Units as Powers of Two"},"content":{"rendered":"<p><strong>TL;DR \/ Summary:<\/strong> 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\u207f MiB steps for predictable bin-packing, then adjust with metrics \u2014 not folklore.<\/p>\n<h2>Why 256Mi, 512Mi, and 1Gi keep showing up<\/h2>\n<p>Cluster nodes advertise memory in binary-ish chunks. Humans compare those chunks faster when requests jump by doubling: 128 \u2192 256 \u2192 512 \u2192 1024. The pattern is not a law of Kubernetes; it is a readability contract that reduces off-by-one sizing debates in pull requests.<\/p>\n<p>CPU is different \u2014 millicores are decimal \u2014 so do not force fake powers of two onto <code>100m<\/code> just for symmetry. Apply the doubling habit where binary units already dominate: memory and ephemeral storage.<\/p>\n<h2>Bin-packing intuition with doubling steps<\/h2>\n<p>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.<\/p>\n<p>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 \u201cbecause it felt right.\u201d<\/p>\n<blockquote><p>Pick a ladder. Document the ladder. Climb it with metrics.<\/p><\/blockquote>\n<h2>A starter ladder for app teams<\/h2>\n<ul>\n<li>128Mi \u2014 tiny sidecars and CLI jobs<\/li>\n<li>256Mi \u2014 small APIs with modest caches<\/li>\n<li>512Mi \u2014 typical web workers<\/li>\n<li>1Gi \u2014 JVM-ish services after heap tuning<\/li>\n<li>2Gi \/ 4Gi \u2014 data-local caches, heavier workers<\/li>\n<\/ul>\n<p>Skip rungs only with a graph attached. \u201cWe need 700Mi\u201d should arrive with a week of RSS percentiles, not a vibe.<\/p>\n<h3>Requests vs limits<\/h3>\n<p>Keep requests on the ladder. Limits may sit one rung above during incident response, then return. Permanent limit sprawl recreates noisy-neighbor drama.<\/p>\n<h2>Page cache and the illusion of free RAM<\/h2>\n<p>Linux loves cache. A container that \u201cbarely fits\u201d 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.<\/p>\n<p>Watch working set estimates, not only averages. Averages lie during GC pauses and queue bursts.<\/p>\n<h2>Horizontal pods vs vertical doubling<\/h2>\n<p>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.<\/p>\n<p>Write the decision rule in the runbook: \u201cIf p95 latency rises with CPU saturation \u2192 scale out. If RSS climbs toward the limit with CPU calm \u2192 scale up one rung.\u201d<\/p>\n<h2>Ephemeral storage deserves the same honesty<\/h2>\n<p>Log spills and unpackaged assets blow disks in powers-of-two-shaped chunks more often than you think \u2014 image layers, tar extracts, and buffer files. Set ephemeral-storage requests on the same ladder when the workload writes temporary trees.<\/p>\n<p>Pods evicted for disk feel like mysterious disappearances. They are usually missing requests.<\/p>\n<h2>Teaching newcomers without shame<\/h2>\n<p>Show a spreadsheet of 2\u207f MiB values beside a node\u2019s allocatable memory. Ask which combinations fill a 8Gi allocatable slice with the least remainder. The exercise beats a abstract lecture on the scheduler.<\/p>\n<p>Then open production graphs and break the toy model on purpose. Reality always wins; the ladder is a starting language.<\/p>\n<h2>Calculator on the desk during reviews<\/h2>\n<p>During PR review, a quick glance at <a href=\"https:\/\/tothepowerof2.com\/\">2 to the power of n<\/a> keeps everyone honest about what \u201cthe next size up\u201d means. Then paste the actual metrics screenshot under the YAML change.<\/p>\n<p>No metrics, no rung climb.<\/p>\n<h2>Node pool SKUs and the same ladder<\/h2>\n<p>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.<\/p>\n<p>During capacity reviews, print allocatable memory beside your request ladder. The visual mismatch ends arguments faster than vibes.<\/p>\n<h2>JVM heaps inside power-of-two containers<\/h2>\n<p>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 \u2014 otherwise the pod dies \u201cfor no reason\u201d at traffic you already tested at a lower heap.<\/p>\n<p>Document heap = f(limit) in the Dockerfile comments so the next engineer does not \u201coptimize\u201d by deleting headroom.<\/p>\n<h2>HPA interactions with vertical rungs<\/h2>\n<p>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.<\/p>\n<p>Record the date you last changed requests beside the HPA config so future readers know which lever moved last.<\/p>\n<h2>Burstable versus Guaranteed classes<\/h2>\n<p>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 \u2014 do not stumble into it.<\/p>\n<h2>Retiring cargo-cult sizes<\/h2>\n<p>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.<\/p>\n<p>Powers of two will not autopilot capacity planning. They will keep your YAML readable and your leftover node memory less embarrassing \u2014 which is a quietly expensive problem when the cluster bill arrives.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u207f MiB steps for predictable bin-packing, then adjust with metrics \u2014 not folklore. Why 256Mi, 512Mi, and 1Gi keep showing up Cluster nodes advertise memory in &#8230; <a title=\"Kubernetes Resource Units as Powers of Two\" class=\"read-more\" href=\"https:\/\/tothepowerof2.com\/blog\/kubernetes-resource-units-as-powers-of-two\/\" aria-label=\"Read more about Kubernetes Resource Units as Powers of Two\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":63,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-binary-exponents-computing"],"_links":{"self":[{"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/comments?post=158"}],"version-history":[{"count":1,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/posts\/158\/revisions\/159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/media\/63"}],"wp:attachment":[{"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/media?parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/categories?post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tothepowerof2.com\/blog\/wp-json\/wp\/v2\/tags?post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}