Room 40
LIMITRANGES
The Default Enforcer
- LimitRanges set default, min, and max resource limits for containers in a namespace.
- Pods without resource specs get the defaults automatically.
📜 Mission Briefing
- Apply
limitrange.yamlto namespaceenforced. - Deploy a pod WITHOUT resource requests/limits.
- Describe the pod - it should have default limits applied.
- Verify the defaults match the LimitRange.
- The LimitRange annotation contains the password:
limitrng.
Key Commands
| Command | Purpose |
|---|---|
kubectl get limitrange -n NS |
List LimitRanges |
kubectl describe limitrange NAME -n NS |
LimitRange details |
How LimitRanges Work
apiVersion: v1
kind: LimitRange
metadata:
name: container-limits
namespace: enforced
annotations:
escape-password: "limitrng"
spec:
limits:
- type: Container
default: # Default limits (if not specified)
cpu: "500m"
memory: "256Mi"
defaultRequest: # Default requests (if not specified)
cpu: "100m"
memory: "128Mi"
max: # Maximum allowed
cpu: "2"
memory: "1Gi"
min: # Minimum allowed
cpu: "50m"
memory: "64Mi"
- type: Pod
max:
cpu: "4"
memory: "2Gi"
- type: PersistentVolumeClaim
max:
storage: "10Gi"
min:
storage: "1Gi"
# LimitRange vs ResourceQuota:
# LimitRange: Per-container/pod defaults and limits
# ResourceQuota: Total namespace resource budget
# If LimitRange sets defaults:
# Pods without requests/limits get defaults injected
# Pods exceeding max are REJECTED
# Pods below min are REJECTED
kubectl create ns enforced
kubectl apply -f limitrange.yaml -n enforced
# Deploy pod without limits
kubectl run no-limits --image=nginx -n enforced
# Check that defaults were applied
kubectl describe pod no-limits -n enforced | grep -A 5 "Limits\|Requests"
Hints
Hint 1
Hint 2
Hint 3
The password is limitrng.