Configuring Resource Management

1. Setting CPU Requests

resources:
  requests: { cpu: 250m }   # 0.25 core guaranteed
UnitMeaning
11 vCPU/core
500m500 millicores = 0.5 core
100m0.1 core (typical minimum)

2. Setting Memory Requests

SuffixValue
Ki1024 bytes
Mi1024² bytes (binary, preferred)
Gi1024³ bytes
M10⁶ bytes (decimal)
G10⁹ bytes (decimal)

3. Setting CPU Limits

resources:
  limits: { cpu: 1 }   # throttled above 1 core
BehaviorMechanism
EnforcementCFS quota (cgroup v2)
EffectThrottling, not eviction
LatencyCan cause spikes — consider not setting limit for latency-sensitive workloads

4. Setting Memory Limits

Warning: Exceeding memory limit triggers OOMKill — container restarts.
RuleDetail
Hard limitEnforced by kernel cgroup
JVMUse -XX:MaxRAMPercentage=75 for container-aware sizing
No throttleMemory is always hard (unlike CPU)

5. Understanding Resource Units

ResourceUnits
cpu1, 500m, 0.5
memory128Mi, 1Gi, 500M
ephemeral-storageSame 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

ResourceExamples
Computerequests.cpu, limits.memory
Storagerequests.storage, persistentvolumeclaims
Object countpods, services, secrets, configmaps
Class-basedcount/deployments.apps

8. Viewing Resource Usage

kubectl top nodes
kubectl top pods -A --sort-by=memory
kubectl top pods --containers
RequirementDetail
Metrics ServerMust be installed
Window~1 minute average

9. Understanding QoS Classes

ClassConditionEviction Order
Guaranteedlimits = requests for ALL resourcesLast
BurstableRequests set, limits ≥ requestsMiddle
BestEffortNo requests or limitsFirst

10. Setting Priority Classes

apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata: { name: high }
value: 1000000
preemptionPolicy: PreemptLowerPriority
globalDefault: false
description: "Critical workloads"
Built-inValue
system-cluster-critical2000000000
system-node-critical2000001000

11. Configuring Pod Disruption Budgets

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: { name: web }
spec:
  minAvailable: 2          # or maxUnavailable
  selector: { matchLabels: { app: web } }
FieldUse
minAvailableMin healthy pods required
maxUnavailableMax disruption allowed
unhealthyPodEvictionPolicyIfHealthyBudget / 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
SourceDetail
Device pluginsAdvertise via kubelet
Node patchkubectl patch node N --subresource=status -p ...
CommonGPUs, FPGAs, RDMA NICs, smart NICs