Kubernetes Resource Units
CPU and Memory notation demystified
What are Resource Units?
When you set cpu: "500m"
or memory: "128Mi"
in Kubernetes, you're using resource units to tell the cluster how much CPU and memory your containers need. Understanding these units is critical for proper resource allocation and avoiding pod scheduling issues.
CPU Units
Whole Cores
Use integers to specify full CPU cores.
cpu: "2" # 2 full CPU cores
cpu: "4" # 4 full CPU cores
Decimal Notation
Use decimals for fractional CPU cores.
cpu: "0.1" # One-tenth of a core (10%)
cpu: "1.5" # 1.5 CPU cores
Millicores (m)
Use millicores for precise CPU allocation. 1000m = 1 core
cpu: "250m" # 0.25 cores (25%)
cpu: "500m" # 0.5 cores (50%)
cpu: "1500m" # 1.5 cores
Note: 500m
= 0.5
(they are equivalent). Minimum precision is 1m
(1 millicore).
Memory Units
Plain Bytes
Specify memory as raw bytes (rarely used).
Decimal (SI) Suffixes
Use metric units based on powers of 1000.
memory: "1G" # 1 gigabyte (1 × 10⁹)
memory: "2T" # 2 terabytes (2 × 10¹²)
Available suffixes: k
(kilo), M
(mega), G
(giga), T
(tera), P
(peta), E
(exa)
Binary (IEC) Suffixes
Use binary units based on powers of 1024. Most commonly used!
memory: "1Gi" # 1 gibibyte (1 × 2³⁰) ≈ 1.07 GB
memory: "512Mi" # 512 mebibytes ≈ 537 MB
Available suffixes: Ki
(kibi), Mi
(mebi), Gi
(gibi), Ti
(tebi), Pi
(pebi), Ei
(exbi)
Common Gotcha
Never use m
suffix for memory!
memory: "400m"
means 0.4 bytes (not 400 megabytes). You want memory: "400Mi"
for 400 mebibytes.
The m
suffix is for millicores (CPU only), not memory.
Mi vs M: What's the Difference?
128Mi (Binary)
128 × 1024² bytes
= 134,217,728 bytes
≈ 134 MB
Use this: Matches what monitoring tools (kubectl, Prometheus) display.
128M (Decimal)
128 × 1000² bytes
= 128,000,000 bytes
= 128 MB
Note: Less common in K8s. Use Mi for consistency.
That's a 6 MB difference! For larger allocations (like 10Gi vs 10G), the gap widens significantly.