Review Kubernetes container CPU limits

Assess CPU caps and throttling against workload requirements.

Description

Without an effective CPU limit, a container can use spare CPU on its node. A CPU request guides scheduling and sets its share when workloads compete for CPU.

Potential impact

CPU contention can slow neighboring workloads. A low limit can also throttle legitimate work and cause timeouts.

Remediation

  • Check the CPU request, observed usage and any LimitRange default. Set resources.limits.cpu if the workload or namespace policy requires a cap.
  • Measure throttling and latency under normal and peak load. If bursts are allowed without a cap, size the request and node capacity for that load.

Examples

Use an available, verified image and adjust the example resource values for your workload.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
    - name: app
      image: images.my-company.example/app:v4
      resources:
        limits:
          memory: "64Mi"

Only memory has an explicit limit. The container can use spare CPU unless a default cap applies.

After

yaml
apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
    - name: app
      image: images.my-company.example/app:v4
      resources:
        requests:
          cpu: "250m"
          memory: "64Mi"
        limits:
          cpu: "500m"
          memory: "128Mi"

The container requests 250m of CPU and can be throttled at its 500m limit.

References