Back to Checks
kubernetes

Pod containers have CPU limits set

core_cpu_limits_set
Service: coreSeverity: medium
OfficialBuilt-inVerified
Categories:resilience
Resource Type:KubernetesPod

Ensure CPU limits are set for containers to prevent noisy neighbors and resource exhaustion.

Risk

Missing CPU limits can allow containers to consume unbounded CPU leading to performance issues.

Run this check with Prowler

Run in Prowler Cloud
Run
prowler kubernetes --checks core_cpu_limits_set

Recommendation

Define CPU limits to bound a container's CPU usage and protect node stability.

Remediation

CLI

kubectl set resources deployment/<name> -n <namespace> --containers=<container> --limits=cpu=500m

NativeIaC

# Example: set cpu limits in container resources
resources:
  limits:
    cpu: "500m"

Other

1Edit the Pod/Deployment manifest and set `resources.limits.cpu` for each container.

Check Code

from prowler.lib.check.models import Check, Check_Report_Kubernetes
from prowler.providers.kubernetes.services.core.core_client import core_client


class core_cpu_limits_set(Check):
    """Check whether regular pod containers have CPU limits configured."""

    def execute(self) -> list[Check_Report_Kubernetes]:
        """Execute the Kubernetes pod CPU limits check.

        Returns:
            List of check reports for Kubernetes pods.
        """
        findings = []
        for pod in core_client.pods.values():
            report = Check_Report_Kubernetes(metadata=self.metadata(), resource=pod)
            report.status = "PASS"
            report.status_extended = (
                f"Pod {pod.name} regular containers have CPU limits configured."
            )

            for container in (pod.containers or {}).values():
                resources = container.resources or {}
                limits = (
                    resources.get("limits") if isinstance(resources, dict) else None
                )
                cpu = limits.get("cpu") if limits and isinstance(limits, dict) else None
                if not cpu:
                    report.status = "FAIL"
                    report.status_extended = f"Pod {pod.name} container {container.name} does not have a CPU limit configured."
                    break

            findings.append(report)

        return findings