Configuring Resource Management
1. Setting CPU Requests
resources:
requests: { cpu: 250m } # 0.25 core guaranteed
| Unit | Meaning |
| 1 | 1 vCPU/core |
| 500m | 500 millicores = 0.5 core |
| 100m | 0.1 core (typical minimum) |
2. Setting Memory Requests
| Suffix | Value |
| Ki | 1024 bytes |
| Mi | 1024² bytes (binary, preferred) |
| Gi | 1024³ bytes |
| M | 10⁶ bytes (decimal) |
| G | 10⁹ bytes (decimal) |
3. Setting CPU Limits
resources:
limits: { cpu: 1 } # throttled above 1 core
| Behavior | Mechanism |
| Enforcement | CFS quota (cgroup v2) |
| Effect | Throttling, not eviction |
| Latency | Can cause spikes — consider not setting limit for latency-sensitive workloads |
4. Setting Memory Limits
Warning: Exceeding memory limit triggers OOMKill — container restarts.
| Rule | Detail |
| Hard limit | Enforced by kernel cgroup |
| JVM | Use -XX:MaxRAMPercentage=75 for container-aware sizing |
| No throttle | Memory is always hard (unlike CPU) |
5. Understanding Resource Units
| Resource | Units |
| cpu | 1, 500m, 0.5 |
| memory | 128Mi, 1Gi, 500M |
| ephemeral-storage | Same as memory |
| Extended (e.g., GPU) | nvidia.com/gpu: 1 |
6. Configuring LimitRange
apiVersion: v1
kind: LimitRange
metadata: { name: defaults }
spec:
limits:
- type: Container
default: { cpu: 500m, memory: 256Mi }
defaultRequest: { cpu: 100m, memory: 128Mi }
max: { cpu: "2", memory: 2Gi }
min: { cpu: 50m, memory: 64Mi }
7. Setting ResourceQuota
| Resource | Examples |
| Compute | requests.cpu, limits.memory |
| Storage | requests.storage, persistentvolumeclaims |
| Object count | pods, services, secrets, configmaps |
| Class-based | count/deployments.apps |
8. Viewing Resource Usage
kubectl top nodes
kubectl top pods -A --sort-by=memory
kubectl top pods --containers
| Requirement | Detail |
| Metrics Server | Must be installed |
| Window | ~1 minute average |
9. Understanding QoS Classes
| Class | Condition | Eviction Order |
| Guaranteed | limits = requests for ALL resources | Last |
| Burstable | Requests set, limits ≥ requests | Middle |
| BestEffort | No requests or limits | First |
10. Setting Priority Classes
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata: { name: high }
value: 1000000
preemptionPolicy: PreemptLowerPriority
globalDefault: false
description: "Critical workloads"
| Built-in | Value |
| system-cluster-critical | 2000000000 |
| system-node-critical | 2000001000 |
11. Configuring Pod Disruption Budgets
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: { name: web }
spec:
minAvailable: 2 # or maxUnavailable
selector: { matchLabels: { app: web } }
| Field | Use |
| minAvailable | Min healthy pods required |
| maxUnavailable | Max disruption allowed |
| unhealthyPodEvictionPolicy | IfHealthyBudget / AlwaysAllow |
Note: PDB only protects against voluntary disruptions (drain, eviction) — not node failures.
12. Using Extended Resources
resources:
limits:
nvidia.com/gpu: 1
smarter-devices/fuse: 1
| Source | Detail |
| Device plugins | Advertise via kubelet |
| Node patch | kubectl patch node N --subresource=status -p ... |
| Common | GPUs, FPGAs, RDMA NICs, smart NICs |