Skip to main content
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—
kube-apiserverHot-loop ctrlbuggy operatorAdminsystem:masterskubeletssystem:nodesRequest filterauthn · then APFFlowSchemasfirst match winsexemptno limit, no queueworkload-lowqueues · shuffle shardnode-highown seatsHandlersseats in usePrometheusapiserver_flowcontrol_*kubectlLease renew
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​

ObservationMeaningNext step
A client gets 429 and its PriorityLevel UID header maps to workload-low or global-defaultIts flow is over its fair shareFix 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 fullFind the top flows in dump_requests, then the client
Same metric with reason="time-out"Requests waited in queue too longThe 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-electionCritical traffic is waitingCheck for something misclassified into that level
Requests from a custom controller land in catch-allNo FlowSchema matched itAdd a FlowSchema that sends it to a suitable level
An important request needs to bypass APFExempt levelUse 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

  1. A buggy operator floods the API server with LIST requests. Why do kubelet Lease renewals still get through?
  2. Two teams share workload-low. One team has a client in a hot loop. Why is the other team mostly unaffected?
  3. Your controller starts getting HTTP 429 with Retry-After. What is the right first move?

Further reading: API Priority and Fairness · Flow control debugging · How an API Request Gets Stored · CRDs and Operators