Course contentsShow
← Cloud and Infrastructure
Lesson 1332 of 2,98927. Kubernetes Scheduling and ResourcesFree lesson

Setting CPU Requests

Define CPU requests in pod specifications to guarantee minimum CPU allocation for containers.

Setting CPU Requests

What You'll Learn

You'll learn how to define CPU requests in your pod specifications to guarantee that Kubernetes reserves a minimum amount of CPU power for your containers.

Why CPU Requests Matter

Think of a CPU request like reserving a table at a restaurant. When you make a reservation for four people, the restaurant guarantees those seats will be available when you arrive. Similarly, a CPU request tells Kubernetes: "This container needs at least this much CPU to function properly—please reserve it."

Without requests, Kubernetes treats all containers equally when scheduling, which can lead to critical applications being placed on overloaded nodes.

How CPU Requests Work

When you set a CPU request:

  1. Kubernetes reserves that CPU capacity on the node where your pod lands
  2. The scheduler only places your pod on nodes with enough unreserved CPU
  3. Your container is guaranteed access to that minimum CPU amount, even when the node is busy

The request doesn't limit your container—if extra CPU is available, your container can use more. It simply ensures a baseline.

Defining CPU Requests in Pod Specs

You specify CPU requests in the resources section of your container definition:

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: app-container
    image: nginx
    resources:
      requests:
        cpu: "250m"

Here, "250m" means 250 millicores (0.25 CPU cores). This guarantees the container gets at least one-quarter of a CPU core.

Choosing the Right Value

Start with realistic estimates based on your application's needs. A web server handling moderate traffic might need "500m", while a background worker could run fine with "100m".

Key Takeaway: CPU requests guarantee minimum CPU allocation by telling Kubernetes how much CPU capacity to reserve when scheduling your pods, ensuring your containers have the processing power they need to run reliably.