Description
CPU requests guide scheduling and CPU allocation under contention. A container with no effective CPU limit can use spare CPU above its request to handle bursts.
Potential impact
Contention can slow other workloads. A cap set too low can throttle the application and increase latency or timeouts.
Remediation
Set resources.limits.cpu when the workload needs a cap. Check namespace LimitRange defaults and the deployed Pod, then measure throttling and latency at normal and peak load. Size the CPU request and node capacity even when you leave CPU uncapped.
Examples
Use a maintained image for deployment.
Before
resource "kubernetes_pod" "pod" {
metadata {
name = "terraform-example"
}
spec {
container {
image = "nginx:1.7.9"
name = "example"
resources {
requests = {
memory = "50Mi"
}
}
}
}
}
After
resource "kubernetes_pod" "pod" {
metadata {
name = "terraform-example"
}
spec {
container {
image = "nginx:1.7.9"
name = "example"
resources {
limits = {
cpu = "0.5"
memory = "512Mi"
}
requests = {
cpu = "250m"
memory = "50Mi"
}
}
}
}
}
The first Pod requests only memory. The second requests 250m CPU and caps it at 0.5 CPU. Adjust both values using your performance tests.