Kubernetes internalsLesson 2 of 12
API Priority and Fairness
A buggy controller starts sending thousands of requests a second. Without limits it would crowd out kubelets and leader election and take the cluster down with it. API Priority and Fairness (APF) sorts each request into a priority level and a flow, so the noisy client waits or gets 429 while everyone else carries on.
Priority level—
Flow—
Result—
RequestResponse / reportAppears in a later step
What you will learn
- Why a fixed in-flight limit alone lets one client starve the rest
- FlowSchemas map requests to PriorityLevelConfigurations
- nominalConcurrencyShares split the total seats
- Flows and shuffle sharding keep a noisy flow in its own queues
- 429 with Retry-After, metrics, debug endpoints and headers
What a reading tells you
| Observation | Meaning | Next step |
|---|---|---|
A client gets 429 and its PriorityLevel UID header maps to workload-low or global-default | Its flow is over its fair share | Fix the client (backoff, watch instead of repeated LIST, smaller pages) |
apiserver_flowcontrol_rejected_requests_total rising with reason="queue-full" | Queues of that level are full | Find the top flows in dump_requests, then the client |
Same metric with reason="time-out" | Requests waited in queue too long | The level is too small for real demand, or one flow is hogging it |
apiserver_flowcontrol_request_wait_duration_seconds high for node-high or leader-election | Critical traffic is waiting | Check for something misclassified into that level |
Requests from a custom controller land in catch-all | No FlowSchema matched it | Add a FlowSchema that sends it to a suitable level |
| An important request needs to bypass APF | Exempt level | Use sparingly; exempt traffic is unlimited |
Try it yourself
kubectl get flowschemas # PRIORITYLEVEL, MATCHINGPRECEDENCE, DISTINGUISHERMETHOD
kubectl get prioritylevelconfigurations # TYPE, NOMINALCONCURRENCYSHARES, QUEUES, HANDSIZE
kubectl get pods -v=8 2>&1 | grep -i x-kubernetes-pf # UIDs of the FlowSchema and level for your request
kubectl get flowschemas -o custom-columns="uid:{metadata.uid},name:{metadata.name}" # Map UID to name
kubectl get --raw /debug/api_priority_and_fairness/dump_priority_levels # Seats and queued requests per level
kubectl get --raw /debug/api_priority_and_fairness/dump_requests # Who is waiting right now
kubectl get --raw /metrics | grep apiserver_flowcontrol_rejected_requests_total # Rejections by level and reason
Check yourself
Further reading: API Priority and Fairness · Flow control debugging · How an API Request Gets Stored · CRDs and Operators