This guide walks you through diagnosing and resolving Kubernetes API server throttling and request saturation. You’ll learn how to identify the root cause—whether it’s client-side rate limiting, server-side overload, or resource exhaustion—and apply targeted fixes to restore responsiveness. You’ll need kubectl access to your cluster and the ability to view logs and metrics.
What You’ll Need
- Cluster administrator access (to view kube-apiserver logs and modify flags)
- kubectl configured with sufficient permissions
- Access to cluster metrics (e.g., Prometheus, Cloud Provider metrics, or `kubectl top`)—optional but helpful
- Basic understanding of Kubernetes control plane components
Step-by-Step
- Confirm the symptom. Users or controllers report errors like
429 Too Many Requests,Timeout, oretcdserver: request timed out. Check if the API server is slow to respond or if requests are being rejected. Usekubectl get --raw /healthzto check basic health. - Check API server metrics. Access the API server metrics endpoint (usually
/metrics). Look forapiserver_request_total,apiserver_request_duration_seconds, and especiallyapiserver_current_inflight_requests. The inflight requests metric shows how many requests are currently being processed. If it’s near the configured limit (default--max-requests-inflightis 400 for read requests and--max-mutating-requests-inflightis 200 for write requests), you’re hitting saturation. - Look for client-side throttling. If you see
Throttling request took 1.234sin your client logs (kubectl, controller-manager, scheduler), that indicates client-side rate limiting. Check the kubeconfig’sqpsandburstsettings. The default for kubectl isqps=5, burst=10, which is very low. For controllers, the default is oftenqps=20, burst=30. Increase these values if appropriate. - Identify the source of high request volume. Use the
apiserver_request_totalmetric, broken down byverb,resource, andclient. A common culprit is a misconfigured controller or a custom controller with a tight watch loop. Also check if there are manyLISTcalls with large resource versions—these are expensive. - Check etcd health and performance. Since the API server stores all data in etcd, etcd latency directly affects API server performance. Check etcd metrics (if exposed) or run
etcdctl endpoint healthfrom the etcd pod. Look for high disk I/O, network latency, or slow fsync. If etcd is slow, the API server will time out even if it has capacity. - Review API server flags. Check the API server’s startup flags. Look at
--max-requests-inflightand--max-mutating-requests-inflight. If they’re set too low for your workload, you’ll see throttling. Also check--request-timeout(default 60s). If requests are timing out, consider increasing it, but first understand why they’re slow. - Inspect API server logs. Look for patterns like
Too many requests,APIServiceerrors, oretcdserver: request timed out. Also look forWATCHevents that are being dropped or taking too long. Usekubectl logs -n kube-system kube-apiserver-. - Check for watch leaks. A common cause of saturation is too many open watch connections. Each watcher consumes resources. Use the
apiserver_watch_events_sizesorapiserver_watch_events_totalmetrics to see watch activity. If a client is not closing watches properly, it can exhaust the server. - Scale the API server. If you’re running a single API server, consider running multiple replicas (typically 2-3). This spreads the load. Ensure your load balancer distributes traffic evenly. Also consider increasing the node size if CPU/memory are saturated.
- Optimize client behavior. For controllers, use informers with proper resync periods instead of polling. For kubectl, use
--server-sidefor large apply operations. For custom scripts, batch requests and use watch instead of frequent GETs. - Implement priority and fairness. If you’re on Kubernetes 1.20+, enable the
APIPriorityAndFairnessfeature gate (it’s beta by default). This allows you to configureFlowSchemaandPriorityLevelConfigurationto prevent a single client from starving others. Create a flow schema that limits aggressive clients. - Consider API caching. For read-heavy workloads, use a cache like the
kube-aggregatoror a sidecar cache. This reduces direct load on the API server.
Common Mistakes
- Ignoring client-side throttling. Many users see 429 errors and assume the server is overloaded, but the client is actually rate-limiting itself. Always check client logs first.
- Setting max-requests-inflight too high. Increasing this blindly can cause memory exhaustion and crash the API server. It should be tuned based on available memory and typical request size.
- Not monitoring etcd. The API server is only as fast as etcd. If etcd is slow, no amount of API server tuning will fix it.
- Forgetting about watch requests. Watches are long-lived and can consume significant memory. A single client opening thousands of watches can be worse than thousands of GETs.
Tips
- Use
kubectl get --raw /metrics | grep apiserver_current_inflightto quickly check current saturation. - Enable audit logging temporarily to see which clients are making the most requests.
- For production, set up Prometheus alerts on
apiserver_current_inflight_requestsexceeding 80% of the limit. - When increasing client QPS, also increase burst to allow for short spikes.
- Use the
--v=4flag on the API server to get more detailed request logs, but be cautious as this increases log volume.
Troubleshooting
If the above steps don’t resolve the issue, try the following:
- Check if the issue is intermittent. If it happens only during certain times, it may be related to a cron job or a specific workload. Use metrics to correlate.
- Verify network connectivity. High latency between clients and the API server can cause timeouts. Use
kubectl get --raw /readyzand check response times. - Review recent changes. If the problem started after a change, roll back or adjust the change. Check for new controllers or updated versions.
- Check for resource leaks. If memory usage of the API server keeps increasing, there may be a leak (often due to watches). Restart the API server as a temporary measure, but investigate the root cause.
- If all else fails, restart the API server. This clears all transient state. It’s safe to do one at a time if you have multiple replicas.
Frequently Asked Questions
What is the difference between throttling and saturation?
Throttling is when the API server deliberately rejects or delays requests to protect itself (either via client-side rate limiting or server-side max-inflight limits). Saturation is when the API server is processing so many requests that it can’t respond in time, often due to CPU or etcd bottlenecks.
How do I increase the API server’s request limits?
You can increase the --max-requests-inflight and --max-mutating-requests-inflight flags on the kube-apiserver. However, be cautious—these limits exist to prevent memory exhaustion. Monitor memory usage after increasing.
Why do I see ‘Throttling request took 1.234s’ in my logs?
This is a client-side message, meaning your client (kubectl, controller) is rate-limiting itself. Check the qps and burst settings in your kubeconfig or client configuration.
Can a single namespace cause API server saturation?
Yes, if a namespace has many resources and many controllers watching them, it can generate a high volume of requests. Use priority and fairness to limit the impact of such namespaces.
Is it safe to restart the API server?
Yes, the API server is stateless (it stores data in etcd). Restarting it will briefly interrupt API access, but it will recover. If you have multiple replicas, restart them one by one to avoid downtime.
What is APIPriorityAndFairness?
It’s a feature that allows you to configure how requests are prioritized and limited. It prevents a single client from consuming all API server resources, ensuring fair access for all.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Campus Tech Innovation Hubs: What They Are
- Poco C51 Airtel Prepaid Locked Variant India?
- Jenkins vs GitHub Actions: Which CI/CD Fits Your Team?
- Turn Off Backup Encryption in iTunes?
- Shared VPS Hosting: Is It Better?
- Disk Defrag Pro: What It Does and Whether You Need It