Skip to main content
KBY Technologies Logo
Lexicon
Lexicon

API Priority and Fairness (APF)

Difficulty: Advanced
3 min read

In plain English

Plain definition

Kubernetes API Priority and Fairness protects the API server by classifying requests into priority levels and sharing limited concurrency among flows, so noisy clients cannot starve critical control-plane work.

APF sits inside the kube-apiserver request-handling chain, running after authentication (so the requesting user is known) as part of the filter chain before the request reaches its handler. Every incoming request is classified by a FlowSchema into a PriorityLevelConfiguration. The built-in levels include exempt, system, node-high, leader-election, workload-high, workload-low, global-default and catch-all. Each limited priority level owns a slice of the API server’s total concurrency budget, expressed in seats rather than raw request counts. A seat is one unit of concurrency, and list requests that the server estimates will return many objects occupy more seats than simple gets. Within a priority level, requests are further split into flows via a distinguisher (usually the requesting user or namespace), and a shuffle-sharded set of FIFO queues implements a fair-queuing algorithm so a single noisy tenant is far less able to monopolise the level’s seats even if it floods requests.

APF schedules with a variant of Fair Queuing with virtual finish times, borrowed conceptually from network packet scheduling. Each queue tracks a virtual start/finish time; when concurrency frees up, the scheduler dequeues from the queue with the earliest virtual finish time, approximating max-min fairness across flows without requiring per-flow rate limiting configuration. Requests are rejected with HTTP 429 and a Retry-After header when the queue is full or when they time out while waiting, rather than blocking indefinitely. Queuing applies only to Limited priority levels and is configured under spec.limited.limitResponse.queuing via queues, handSize and queueLengthLimit; Exempt levels such as exempt do not queue. That is what lets APF work as real admission control under overload, not just a scheduling nicety.

Before changing any FlowSchema or PriorityLevelConfiguration, export the current objects (for example with kubectl get flowschemas,prioritylevelconfigurations -o yaml) so you can restore them, make the change on a test cluster first, and watch the apiserver_flowcontrol_* metrics after applying it.

  • Seat estimates drift: list requests against large collections can be underestimated at admission time, so their actual memory/CPU cost exceeds the seats reserved. Bear in mind that the sum of --max-requests-inflight and --max-mutating-requests-inflight defines the server’s total concurrency limit that APF divides among priority levels.
  • A poorly written FlowSchema (one matching on a wildcard subject, for example) can misclassify a bursty controller and route it into the workload-high level, where it can consume that level’s seats and increase queueing latency for other flows in the same level, a form of priority inversion.
  • Rejections can cascade. During a control-plane incident, a client that retries 429s aggressively without honouring Retry-After and exponential backoff amplifies load precisely on the subsystem meant to shed it.
  • Without scraping apiserver_flowcontrol_* metrics, cluster admins often diagnose APF-induced 429s as generic API server unavailability rather than a fairness/queue-depth problem.

APF matters because it decouples the API server’s stability guarantees from the way any single client behaves, which is essential once a cluster hosts dozens of controllers, operators, and CI pipelines all calling the same control plane. Getting FlowSchema and PriorityLevelConfiguration tuning wrong is a common source of mysterious 429 storms in large multi-tenant clusters, so APF metrics belong on every control-plane SLO dashboard as a matter of course, not as an optional extra.

About this page

Credited to

Dates

Published

Corrections

  • : Corrected during a review of published articles. Details
  • : Corrected during a review of published articles. Details

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Found this useful? Follow KBY for more like it.

More from KBY that goes with this term.