I moved a small URL shortener from three VMs onto a three-node k3s cluster and measured it with k6 before and after every change. One change looked harmless and wasn't: a CPU limit.

The setup

  • k3s, three nodes (one with 4 vCPUs, two with 2 vCPUs)
  • a Go service with two replicas, PostgreSQL via CloudNativePG
  • k6 with a constant arrival rate: 2,000 requests per second for 20 seconds, 90 % redirects, 10 % writes
  • the service gives up on a request after 2 seconds (a timeout it already had)

Then two runs that differ in exactly one line of the Deployment.

The result

Pod resources Requests/s served Failed requests
requests.cpu: 250m, limits.cpu: 500m 1,344–1,390 69–75 %
requests.cpu: 250m, no CPU limit 1,946–1,964 0 %

Two runs each, on different days. At 1,000 requests per second the limit caused no errors at all – only p95 latency went from 10 ms to 23 ms. That is the dangerous part: in normal traffic, nobody notices. At the next peak, three out of four requests fail.

Why: CFS throttling

A CPU limit of 500m does not mean "half a core". The kernel's CFS scheduler gives the container 50 ms of CPU time per 100 ms window, summed over all threads. A Go service spreads 1,000 requests per second across several threads and burns through that budget early in the window. For the rest of the window the container is not scheduled at all. Requests queue up, the queue grows, and once a request waits longer than the 2-second timeout it fails.

Timeline of three 100 ms CFS windows: four threads run for about 12.5 ms each, using the 50 ms quota, then all are throttled until the next window

How to see it in your own cluster

The kubelet counts the windows. You don't need to log in to the node:

# CFS periods and throttled periods of every container named "kurz" on node s2 kubectl get --raw /api/v1/nodes/s2/proxy/metrics/cadvisor \ | grep -E '^container_cpu_cfs_(periods|throttled_periods)_total' \ | grep 'container="kurz"' 

At 1,000 req/s, 44–67 % of all windows were throttled – with zero errors and a perfectly normal-looking CPU graph. In Prometheus, alert on the ratio:

rate(container_cpu_cfs_throttled_periods_total[5m]) / rate(container_cpu_cfs_periods_total[5m]) 

Note: these counters only exist for containers with a CPU limit. And kubectl top is the wrong tool for this – metrics-server averages over 15 seconds and hides the bursts.

What I do now

  • CPU: request yes, limit only with a reason. The request reserves capacity and gives weight when the node is busy. Without a limit, the pod may use idle CPU.
  • Memory: request and limit. Memory can't be throttled, only taken away. In the same lab an 8 Mi limit started fine and got both pods OOMKilled at the same moment under load.
  • If you need limits (multi-tenant clusters, Guaranteed QoS): size them from measured bursts, not averages. With cpu: 1 as request and limit the same service had zero throttled windows at 1,000 req/s.

Caveats

One service, one homelab, k6 running on one of the nodes. The exact numbers will differ in your cluster; the mechanism won't. Measure your own service under a constant arrival rate before you trust a limit.

This is day 2 of my free hands-on course System design on Kubernetes – every pattern on a real cluster, every decision measured with k6. Day 2 ("Measuring in the cluster") has all commands to reproduce it, no sign-up needed:
https://itdrills.com/books/system-design-kubernetes/course/tag02?utm_source=devto&utm_medium=social&utm_campaign=cpu-limits