https://drive.google.com/file/d/1o2eUiyAj-6naAc3IJXsSbSnRqvgzWz8H/view?usp=sharing
apiVersion: v1
kind: LimitRange
metadata:
name: cpu-limit-range
namespace: learning
spec:
limits:
- default: # โ CPU limit if not specified
cpu: 1 # = 1000m (1 full core)
defaultRequest: # โ CPU request if not specified
cpu: 0.4 # = 400m (0.4 cores)
type: Container
๐ Key Insight:
This LimitRange only manages CPU โ memory is not constrained (Pods can use any memory unless restricted elsewhere).
๐ก Why CPU-only?
- CPU is compressible: Throttled when exceeded (no crash)
- Memory is incompressible: OOMKilled when exceeded โ Teams often treat them differently
| Format | Meaning | Equivalent |
|---|---|---|
1 |
1 CPU core | 1000m |
0.4 |
0.4 CPU cores | 400m |
500m |
500 milliCPU | 0.5 |
โ Best Practice:
Use
m(millicores) for clarity:defaultRequest: cpu: "400m" default: cpu: "1000m"
โ ๏ธ Your YAML uses decimals (0.4, 1) โ valid, but m is more explicit.
# Create namespace
kubectl create namespace learning
# Apply LimitRange
kubectl apply -f namespace-cpu-limitrange.yaml
# Verify
kubectl describe limitrange cpu-limit-range -n learning
# Type Resource Min Max Default Request Default Limit
# Container cpu - - 400m 1
# pod-no-cpu.yaml
apiVersion: v1
kind: Pod
meta
name: no-cpu-pod
namespace: learning
spec:
containers:
- name: nginx
image: nginx
kubectl apply -f pod-no-cpu.yaml
# Check applied CPU resources
kubectl get pod no-cpu-pod -n learning -o jsonpath='{.spec.containers[0].resources}'
# โ
Output:
# {"limits":{"cpu":"1"},"requests":{"cpu":"0.4"}}
๐ Result:
LimitRange auto-applied CPU defaults โ Pod has 400m request, 1000m limit
# pod-custom-cpu.yaml
apiVersion: v1
kind: Pod
meta
name: custom-cpu-pod
namespace: learning
spec:
containers:
- name: nginx
image: nginx
resources:
requests:
cpu: "600m"
limits:
cpu: "1500m" # > default limit, but no max defined โ allowed!