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

Setting CPU Limits

Define CPU limits to cap maximum CPU usage and prevent containers from consuming excessive resources.

Setting CPU Limits

What you'll learn: How to define CPU limits to prevent containers from monopolizing cluster CPU resources.

The Core Idea

While CPU requests guarantee a baseline amount of processing power for your container (what you've already learned), CPU limits set a ceiling on how much CPU a container can actually use. Think of it like a speed governor on a car engine—even if the road is clear, the engine won't exceed the maximum speed you've configured.

When you set a CPU limit, Kubernetes uses the underlying container runtime to enforce this cap. If your container tries to use more CPU than its limit, it gets throttled—the kernel restricts its processing time rather than giving it unlimited access to available CPU cycles.

Why CPU Limits Matter

Without limits, a single misbehaving container could consume all available CPU on a node, starving other workloads. CPU limits provide:

  • Predictable performance for other containers on the same node
  • Protection against runaway processes that could monopolize resources
  • Fair resource allocation in multi-tenant environments

Setting the Limit

You define CPU limits in your Pod specification using the same units as requests (millicores or cores). Here's the syntax:

resources:
  requests:
    cpu: "250m"
  limits:
    cpu: "500m"

In this example, the container is guaranteed 250 millicores (its request) but can burst up to 500 millicores maximum. If it tries to use more, the kernel throttles it back down.

Key Takeaway: CPU limits cap the maximum CPU a container can use, preventing resource monopolization through kernel-level throttling when the limit is exceeded.