To use this feature, you (or a cluster administrator) will need to enable the RequestCostAggregation feature gate for all relevant components in your cluster.
See Enable Or Disable Feature Gates for more information.
In high-availability Kubernetes clusters with multiple
API server replicas behind
a load balancer, traffic and CPU consumption across replicas are often asymmetric.
Leader-elected controllers and clients using long-lived HTTP/2 connections or watch
streams can saturate one kube-apiserver instance while other replicas have spare
capacity.
Weighted load balancing enables the kube-apiserver to report its real-time load
metrics to an upstream Layer 7 load balancer using the Open Request Cost Aggregation
(ORCA) standard. Compatible load balancers use these reports to run weighted routing
policies (such as Weighted Round Robin or Weighted Least Request) and steer traffic
toward less loaded API server replicas.
Endpoint load metrics reporting is disabled by default. To enable it, set both the
RequestCostAggregation
feature gate
and the --enable-endpoint-load-metrics flag on every kube-apiserver replica:
kube-apiserver \
--feature-gates=RequestCostAggregation=true \
--enable-endpoint-load-metrics=true
Both settings are required:
RequestCostAggregation without --enable-endpoint-load-metrics=true
makes the capability available but never attaches load reports to responses.--enable-endpoint-load-metrics=true while RequestCostAggregation is
disabled has no effect.kube-apiserver with RequestCostAggregation=true and
--enable-endpoint-load-metrics=true on non-Linux platforms fails at startup.To disable endpoint load metrics reporting, remove --enable-endpoint-load-metrics
(or set it to false) or disable RequestCostAggregation and restart
kube-apiserver. When reporting stops, the load balancer falls back to unweighted
routing.
When enabled, kube-apiserver runs a background sampler that records cumulative
process CPU time and incoming HTTP request counts every 250 milliseconds over a
5-second sliding window. On each tick after a full window is collected, it computes
and caches an updated load report:
cpu_utilizationGOMAXPROCS, which accounts for host logical CPUs, process CPU
affinity, and Linux cgroup CPU quotas). Per the CNCF xDS ORCA specification,
cpu_utilization is non-negative and can exceed 1.0 when OS thread CPU usage
exceeds GOMAXPROCS.rps_fractionalDuring the first 5 seconds after kube-apiserver starts (or after a sampling error
resets the sample window), no report is ready yet, so kube-apiserver omits the
load metrics response header until a full window is available. Because the latest
report is pre-computed in the background and read lock-free on the HTTP request path,
attaching the header adds minimal per-request overhead.
ORCA does not define a standard request negotiation header, so kube-apiserver uses
an explicit opt-in request header to avoid exposing load reports to arbitrary clients.
Requests that do not carry the expected negotiation header receive no load metrics.
| Header | Direction | Supported value and format | Description |
|---|---|---|---|
endpoint-load-metrics-request | Request | TEXT | Requests an ORCA load report on the response. kube-apiserver strips this header before forwarding requests downstream. |
endpoint-load-metrics | Response | TEXT cpu_utilization=<float>, rps_fractional=<float> | Carries the latest ORCA load report, formatted to four decimal places, when negotiated. |
endpoint-load-metrics-bin | Response | Binary protobuf (not emitted) | Stripped by kube-apiserver from proxied backend responses so backends cannot inject spoofed reports. |
An example response header emitted by kube-apiserver looks like:
endpoint-load-metrics: TEXT cpu_utilization=0.3125, rps_fractional=42.8000
API server utilization reveals operational load and tenant activity and could help
a malicious caller target saturated instances. Because the endpoint load metrics
handler runs before request authentication and authorization, any caller that can
send endpoint-load-metrics-request: TEXT directly to kube-apiserver (including
to unauthenticated endpoints such as /livez or /version) would receive load
metrics if the feature is enabled.
To reduce exposure and prevent spoofing, kube-apiserver enforces these rules:
RequestCostAggregation and --enable-endpoint-load-metrics=true are enabled and
the request carries endpoint-load-metrics-request: TEXT.kube-apiserver removes
endpoint-load-metrics-request before delegating the request so it is not leaked
to aggregated API servers, admission webhooks, or proxied Pods, Nodes, or
Services.kube-apiserver removes
endpoint-load-metrics-bin and replaces or removes endpoint-load-metrics on
responses so proxied backends cannot override the API server's own load report.endpoint-load-metrics-request header signals opt-in intent and does not
authenticate the load balancer. Enable --enable-endpoint-load-metrics only when
kube-apiserver is reachable exclusively through trusted Layer 7 load balancers that
strip endpoint-load-metrics and endpoint-load-metrics-bin from responses before
returning them to clients.Any Layer 7 load balancer consuming ORCA load reports from kube-apiserver must:
endpoint-load-metrics-request: TEXT on requests forwarded to
kube-apiserver.endpoint-load-metrics and endpoint-load-metrics-bin from every response
after reading the load report, before returning the response to clients.For example, in an Envoy Proxy route configuration:
routes:
- match:
prefix: "/"
route:
cluster: kube-apiserver
request_headers_to_add:
- header:
key: endpoint-load-metrics-request
value: TEXT
append_action: OVERWRITE_IF_EXISTS_OR_ADD
response_headers_to_remove:
- endpoint-load-metrics
- endpoint-load-metrics-bin
If you use Envoy Gateway, its BackendUtilization
load balancer strips both endpoint-load-metrics and endpoint-load-metrics-bin by
default unless keepResponseHeaders is set to true.
In Kubernetes v1.38 (Alpha):
TEXT format
(endpoint-load-metrics-request: TEXT) is supported. Requests specifying other
ORCA formats (such as JSON or BIN) receive no load report, and out-of-band
gRPC ORCA reporting is not supported.cpu_utilization and rps_fractional.kube-apiserver hosts.RequestCostAggregation feature gate.Items on this page refer to third party products or projects that provide functionality required by Kubernetes. The Kubernetes project authors aren't responsible for those third-party products or projects. See the CNCF website guidelines for more details.
You should read the content guide before proposing a change that adds an extra third-party link.