Repository navigation
Description
Description:
Today the only way to influence Envoy's locality priority from Envoy Gateway's API is Backend.spec.fallback, which is a bool. It lands as ds.Priority = 1 during route translation and reaches Envoy as LocalityLbEndpoints.priority.
That gives us exactly two priority levels, and it is scoped to the Backend resource rather than to the backendRef that references it. Three things fall out of that:
- No multi-tier failover. There is no way to express primary -> secondary -> tertiary.
- No per-route priority. The same
Backendcannot be primary for one route rule and a fallback for another. This is a natural shape for LLM/provider routing (route model A to provider 1 with provider 2 as fallback, and model B the other way around), but it applies to any multi-region or multi-provider setup that reuses backends across routes. - Priority failover cannot be combined with
MergeBackends. Cluster deduplication is worth having — smaller xDS, less active health-check traffic — but priority failover only works while a rule's backends share a single cluster. EG gets this right for its ownfallback, disqualifying such a rule from deduplication. A priority the translator cannot see gets no such protection: the rule's backends are deduplicated into separate weighted clusters, and the failover silently degrades into weight-based distribution.
Because of (2), downstream projects reach past the API. Envoy AI Gateway exposes AIGatewayRoute.spec.rules[].backendRefs[].priority and applies it from its extension server, after EG's translation has finished, by rewriting LocalityLbEndpoints.priority on the generated clusters in PostTranslateModify.
Describe the solution you'd like
Add a backendPriority filter to HTTPRouteFilter, referenced from HTTPBackendRef.filters via ExtensionRef. EG already supports backendRef-level extension filters, This is the only per-backendRef extension point Gateway API gives us, and it is the granularity the use case needs.
API
type HTTPRouteFilterSpec struct {
// ... existing fields ...
// BackendPriority sets the Envoy locality priority of the endpoints belonging to the
// backendRef this filter is attached to, enabling priority-based failover between the
// backendRefs of a single HTTPRouteRule.
//
// This filter is only valid when referenced from HTTPBackendRef.filters. Referencing it
// from HTTPRouteRule.filters is rejected: a rule-level filter applies uniformly to every
// backendRef of the rule, and a uniform priority carries no failover meaning.
//
// +optional
BackendPriority *HTTPBackendPriorityFilter `json:"backendPriority,omitempty"`
}
// HTTPBackendPriorityFilter configures Envoy's priority-based locality failover for a single
// backendRef. Envoy sends traffic to the lowest priority value that has enough healthy
// endpoints, and only spills over to the next value as that health degrades.
//
// This overrides the priority derived from the referenced Backend's `fallback` field.
// For additional details, see
// https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/priority
type HTTPBackendPriorityFilter struct {
// Value is the locality priority assigned to this backendRef's endpoints.
// 0 is the highest priority.
//
// Within one HTTPRouteRule, the values used across backendRefs must start at 0 and be
// contiguous. A rule that skips a value is rejected with a ResolvedRefs=False condition
// on the route.
//
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=127
Value uint32 `json:"value"`
}Usage
One HTTPRouteFilter per distinct priority value; it is reusable across backendRefs and routes.
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: HTTPRouteFilter
metadata:
name: priority-1
spec:
backendPriority:
value: 1
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: llm
spec:
rules:
- matches:
- headers: [{name: x-model, value: gpt-4}]
backendRefs:
- name: primary-provider # priority 0 (default, no filter)
group: gateway.envoyproxy.io
kind: Backend
- name: secondary-provider
group: gateway.envoyproxy.io
kind: Backend
filters:
- type: ExtensionRef
extensionRef:
group: gateway.envoyproxy.io
kind: HTTPRouteFilter
name: priority-1[optional Relevant Links:]
- https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/priority
- https://github.com/theagentrouter/agent-router/blob/main/api/v1beta1/ai_gateway_route.go#L397
Activity
zhaohuabing commentedon Sep 11, 2026
This seems reasonable to me. One thing worth calling out: because the priority lands on the
backendRefrather than on thebackendobject, this also gives Service backendRefs priority failover, whichBackend.spec.fallbackcan't reach today.cc @arkodg @guydc
zhaohuabing commentedon Sep 11, 2026
One more thought: this needs an
HTTPRouteFilterobject per priority value, and the lookup is same-namespace, so it's per namespace rather than per cluster. That's a lot of ceremony for one integer.I don't see a lighter shape at backendRef granularity though —
ExtensionRefhas no inline params, so an object seems unavoidable. ABackendTrafficPolicyon the rule would cost no new objects since health checking or outlier detection has to be configured anyway, but that means that policy can only target routes, which doesn't feel right either. Is there an option here I'm missing?kkk777-7 commentedon Sep 11, 2026
I agree. I initially expected this to be a field in Gateway API side.
I found some previous discussions on this, and it seems Arko had the same opinion, but upstream doesn't seem to be moving forward on this.
Ref: #3055
I considered several options, including using a policy, but for now I personally feel that putting it in
ExtensionRefofbackendRefis the most appropriate approach. That said, I can definitely see the point that BTP would ultimately be needed for health checking.Hi @arkodg , do you have some opinion on this?
kkk777-7 commentedon Sep 11, 2026
I also found that kgateway has
PriorityGroupconcept within Backend in some cases.https://github.com/kgateway-dev/kgateway/blob/main/api/v1alpha1/kgateway/backend_types.go#L83
kgateway-dev/kgateway#13643
And upstream discussions:
kubernetes-sigs/gateway-api#2304
kubernetes-sigs/gateway-api#1802
arkodg commentedon Sep 14, 2026
yeah fine with
backendPriority: int(versus struct) in BackendRef Filter or anotherpriorityfield inBackendgithub-actions commentedon Oct 14, 2026
This issue has been automatically marked as stale because it has not had activity in the last 30 days.