⎈ k8s knowledge compiler

API Priority and Fairness [page]deterministic

concepts

Controlling the behavior of the Kubernetes API server in an overload situation is a key task for cluster administrators. The [kube-apiserver](#gloss:kube-apiserver) has some controls available (i.e. the `--max-requests-inflight` and `--max-mutating-requests-inflight` command-line flags) to limit the amount of outstanding work that will be accepted, preventing a flood of inbound requests from overloading and potentially crashing the API server, but these flags are not enough to ensure that the most important requests get through in a period of high traffic.

The API Priority and Fairness feature (APF) is an alternative that improves upon aforementioned max-inflight limitations. APF classifies and isolates requests in a more fine-grained way. It also introduces a limited amount of queuing, so that no requests are rejected in cases of very brief bursts. Requests are dispatched from queues using a fair queuing technique so that, for example, a poorly-behaved [controller](#gloss:controller) need not starve others (even at the same priority level).

This feature is designed to work well with standard controllers, which use informers and react to failures of API requests with exponential back-off, and other clients that also work this way.

> Caution: Some requests classified as "long-running"—such as remote command execution or log tailing—are not subject to the API Priority and Fairness filter. This is also true for the `--max-requests-inflight` flag without the API Priority and Fairness feature enabled. API Priority and Fairness _does_ apply to watch requests. When API Priority and Fairness is disabled, watch requests are not subject to the `--max-requests-inflight` limit.

## Enabling/Disabling API Priority and Fairness

The API Priority and Fairness feature is controlled by a command-line flag and is enabled by default. See [Options](/docs/reference/command-line-tools-reference/kube-apiserver/#options) for a general explanation of the available kube-apiserver command-line options and how to enable and disable them. The name of the command-line option for APF is "--enable-priority-and-fairness". This feature also involves an [API Group](#gloss:api-group) with: (a) a stable `v1` version, introduced in 1.29, and enabled by default (b) a `v1beta3` version, enabled by default, and deprecated in v1.29. You can disable the API group beta version `v1beta3` by adding the following command-line flags to your `kube-apiserver` invocation:

```shell kube-apiserver \ --runtime-config=flowcontrol.apiserver.k8s.io/v1beta3=false \ # …and other flags as usual ```

The command-line flag `--enable-priority-and-fairness=false` will disable the API Priority and Fairness feature.

## Recursive server scenarios

API Priority and Fairness must be used carefully in recursive server scenarios. These are scenarios in which some server A, while serving a request, issues a subsidiary request to some server B. Perhaps server B might even make a further subsidiary call back to server A. In situations where Priority and Fairness control is applied to both the original request and some subsidiary ones(s), no matter how deep in the recursion, there is a danger of priority inversions and/or deadlocks.

One example of recursion is when the `kube-apiserver` issues an admission webhook call to server B, and while serving that call, server B makes a further subsidiary request back to the `kube-apiserver`. Another example of recursion is when an `APIService` object directs the `kube-apiserver` to delegate requests about a certain API group to a custom external server B (this is one of the things called "aggregation").

When the original request is known to belong to a certain priority level, and the subsidiary controlled requests are classified to higher priority levels, this is one possible solution. When the original requests can belong to any priority level, the subsidiary controlled requests have to be exempt from Priority and …(trimmed)

Sources

concepts/cluster-administration/flow-control.md · docAPI Priority and Fairness

Related (25)

references API serverkube-apiserver conf=1
references Controllercontroller conf=1
references API GroupAPI Group conf=1
references Shuffle-shardingshuffle sharding conf=1
part_of Recursive server scenariosdescribes conf=1
part_of Conceptsdescribes conf=1
part_of Resourcesdescribes conf=1
part_of Defaultsdescribes conf=1
part_of Health check concurrency exemptiondescribes conf=1
part_of Observabilitydescribes conf=1
part_of {{% heading "whatsnext" %}}describes conf=1
part_of Priority Levelsdescribes conf=1
part_of Seats Occupied by a Requestdescribes conf=1
part_of Execution time tweaks for watch requestsdescribes conf=1
part_of Queuingdescribes conf=1
part_of Exempt requestsdescribes conf=1
part_of PriorityLevelConfigurationdescribes conf=1
part_of FlowSchemadescribes conf=1
part_of Mandatory Configuration Objectsdescribes conf=1
part_of Suggested Configuration Objectsdescribes conf=1
part_of Metricsdescribes conf=1

← all Docs