0
0
Kubernetesdevops~10 mins

CPU requests and limits in Kubernetes - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - CPU requests and limits
Pod Spec Created
CPU Requests Set?
NoDefault Scheduler Behavior
Yes
Scheduler Checks Node Capacity
Pod Scheduled on Node
Container Starts Running
CPU Usage Monitored
CPU < Limit
Runs Normally
The pod spec sets CPU requests and limits. Scheduler uses requests to place pods. Runtime enforces limits by throttling CPU if usage exceeds limit.
Execution Sample
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: cpu-demo
spec:
  containers:
  - name: app
    resources:
      requests:
        cpu: "500m"
      limits:
        cpu: "1"
Defines a pod with CPU request of 0.5 CPU and limit of 1 CPU.
Process Table
StepActionCPU RequestCPU LimitScheduler DecisionRuntime Behavior
1Pod spec created with CPU request 500m and limit 1500m1Pending schedulingNot started
2Scheduler checks nodes for available CPU >= 500m500m1Pod scheduled on node with enough CPUNot started
3Container starts running500m1ScheduledContainer can use up to 1 CPU
4Container CPU usage at 300m500m1ScheduledRuns normally, no throttling
5Container CPU usage at 800m500m1ScheduledRuns normally, no throttling
6Container CPU usage at 1200m500m1ScheduledCPU throttled to 1 CPU limit
7Container CPU usage drops to 400m500m1ScheduledRuns normally, no throttling
8Pod deleted or stopped00No schedulingContainer stopped
💡 Pod stops running or is deleted, ending CPU usage monitoring.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 6After Step 8
CPU RequestNone500m500m500m0
CPU LimitNone1110
CPU Usage0001200m0
Pod StatePendingPendingRunningRunningStopped
CPU ThrottledNoNoNoYesNo
Key Moments - 3 Insights
Why does the scheduler use CPU requests and not limits to place pods?
The scheduler uses CPU requests as guaranteed minimum resources to ensure the node can handle the pod. Limits are enforced at runtime and do not affect scheduling decisions. See execution_table step 2.
What happens if the container tries to use more CPU than its limit?
The container is throttled by the runtime to not exceed the CPU limit, which means it cannot use more CPU than allowed. See execution_table step 6 where usage exceeds limit and throttling occurs.
Can a container use less CPU than its request?
Yes, the request is a minimum reserved amount, but the container can use less CPU if workload is low. See execution_table step 4 and 7 where usage is below request and runs normally.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does the container start getting CPU throttled?
AStep 6
BStep 4
CStep 2
DStep 8
💡 Hint
Check the 'Runtime Behavior' column for when throttling starts.
According to the variable tracker, what is the CPU request value after step 3?
A0
B500m
CNone
D1
💡 Hint
Look at the 'CPU Request' row under 'After Step 3' column.
If the CPU limit was removed from the pod spec, how would the runtime behavior change at high CPU usage?
AContainer would be throttled at 500m CPU
BScheduler would fail to schedule the pod
CContainer would never be throttled
DPod would be deleted automatically
💡 Hint
Consider what happens when no CPU limit is set in the execution_table runtime behavior.
Concept Snapshot
CPU requests reserve minimum CPU for scheduling.
CPU limits cap max CPU usage at runtime.
Scheduler uses requests to place pods on nodes.
Runtime throttles CPU if usage exceeds limits.
Requests ensure guaranteed CPU, limits control max usage.
Full Transcript
In Kubernetes, CPU requests and limits control how pods use CPU resources. The CPU request is the minimum CPU the pod needs and is used by the scheduler to decide which node can run the pod. The CPU limit is the maximum CPU the pod can use at runtime. If the pod tries to use more CPU than its limit, the system throttles it to prevent overuse. The execution table shows a pod with 500m CPU request and 1 CPU limit. The scheduler places the pod on a node with enough CPU. The container runs normally when CPU usage is below the limit. When usage exceeds 1 CPU, throttling happens. Variables like CPU request, limit, usage, pod state, and throttling status change step by step. Key moments clarify why requests affect scheduling and limits affect runtime behavior. The quiz tests understanding of when throttling starts, CPU request values, and effects of removing limits.