Skip to content

Disabling KServe HTTPRoute Generation to Route Models by a Single Host and Path

Interactive Diagram

새 탭 ↗

This post records how we moved KServe on Gateway API (implemented by Envoy Gateway) away from its default of one host per model, to a single llm.<domain> host with a path per model. Gateway API and Envoy Gateway themselves are covered in Why Gateway API, Envoy Gateway Setup and HTTPRoute Routing and Verification, so this post focuses only on the HTTPRoutes KServe creates and what happens after you turn them off.

The target version is KServe v0.19.0. Behavior described here was confirmed by reading pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/httproute_reconciler.go at that tag. Example values are generalized: the domain is example.com and the namespace is models.

In Gateway API mode (enableGatewayApi: true) with Standard (Raw) deployment, KServe creates HTTPRoutes itself every time it reconciles an InferenceService (ISVC). A predictor-only ISVC gets two.

HTTPRoute namehostSends to
<isvc> (top-level)Host built from domainTemplate, default <isvc>-<namespace>.<ingressDomain>Transformer Service if present, otherwise predictor Service
<isvc>-predictorSame template with the name <isvc>-predictorPredictor Service

With a transformer or explainer, <isvc>-transformer and <isvc>-explainer routes are added the same way. Details confirmed in the source:

  • Every route uses path match type RegularExpression. The default rule ^/.*$ accepts every path. With an explainer, the top-level route also gets a ^/v1/models/[\w-]+:explain$ rule.
  • Each rule has a RequestHeaderModifier filter that sets ISVC name and namespace headers.
  • If the predictor Service exposes both REST and gRPC ports, a gRPC rule (content-type: application/grpc* header plus /inference.GRPCInferenceService/ path) comes first and an HTTP fallback rule second.
  • Routes carry an ownerReference with the ISVC as controller, so deleting the ISVC garbage-collects them.
  • status.url is set from the top-level host. It contains no path.

The number of hosts grows with the number of models. The pattern in the Gateway API docs, one route and one Service per host, repeats once per model.

Behind Gateway prod-web, foo.example.com/login goes to foo-svc, while bar.example.com is split between bar-svc and bar-svc-canary on a canary header Source: Gateway API docs, HTTP routing, The Kubernetes Authors, Apache-2.0

There were two goals.

  • Callers know only llm.example.com and pick a model by path, for example http://llm.example.com/models/qwen/v1/chat/completions.
  • Routes are managed by the app deployment manifests (the GitOps repository), not by the KServe controller, so which path goes to which Service shows up in a Git diff.
PlantUML Diagram

The setting lives in the ingress entry of the inferenceservice-config ConfigMap in the kserve namespace. Two values changed.

{
"enableGatewayApi": true,
"kserveIngressGateway": "<gateway-namespace>/<gateway-name>",
"ingressDomain": "example.com",
"domainTemplate": "llm.{{ .IngressDomain }}",
"disableIngressCreation": true,
"urlScheme": "http"
}

disableIngressCreation: true stops HTTPRoute creation, and domainTemplate decides the host that goes into status.url. The v0.19 configmap comment also describes disableIngressCreation as a raw deployment mode setting.

The branch in Reconcile makes the behavior clear.

if !isInternal && !r.ingressConfig.DisableIngressCreation {
// predictor, transformer, explainer, top-level route reconcile
...
} else {
// Ingress creation is disabled. We set it to true as the isvc condition depends on it.
isvc.Status.SetCondition(v1beta1.IngressReady, ...ConditionTrue...)
}
if isvc.Status.URL, err = createRawURL(isvc, r.ingressConfig); err != nil {

Three facts with operational impact follow.

  • Existing routes are not deleted. The else branch has no delete code. Old routes stay while the ISVC lives, keep serving the old hosts, and are no longer updated by the controller. Because of the ownerReference they go away when the ISVC is deleted. To cut the old hosts, delete them yourself.
  • The IngressReady condition is always True. The ISVC looks Ready even with no route. Whether routing works cannot be read from ISVC status; check your own HTTPRoute status and a real call.
  • status.url switches to the new domainTemplate immediately. createRawURL only builds the host from the template, so every ISVC’s status.url becomes the same http://llm.example.com. With no path, that value alone no longer identifies a model.

Existing model calls kept working because of how the app was built. It read status.url once when a model was registered, stored it, and called the stored value afterwards. A client that re-reads status.url per request or periodically would have pointed every model at the same host the moment the setting changed. Before changing the setting, check when your callers read status.url.

The <isvc>-predictor route gives a separate host that goes straight to the predictor component. With a transformer, the top-level host goes to the transformer, so calling the predictor directly needs this route.

For an ISVC with only a predictor (no transformer or explainer), the source shows the top-level route also sends to the predictor Service in its else branch. Both routes have the same backend Service, so when managing routes yourself, one route per model is enough.

KServe has a path-based option too. Setting pathTemplate: "/serving/{{ .Namespace }}/{{ .Name }}" in ingress adds a path rule to the top-level route. We did not use it because of these constraints, confirmed in the v0.19 source.

  • The path rule is attached to ingressDomain itself. The source appends ingressConfig.IngressDomain to allowedHosts. It lands on example.com, not on a separate host such as llm.example.com.
  • Per-model hosts remain. The path rule is only added to the top-level route; the host-based rules and predictor route are still created.
  • The prefix is not stripped. The path rule matches <path>/ as a RegularExpression, and the only filter adds headers. There is no URLRewrite, so the model server receives the full path such as /serving/models/qwen/v1/.... That does not suit servers that only handle /v1/..., like OpenAI-compatible servers.
  • status.url does not include the path. createRawURL only builds the host.
  • The match type is RegularExpression. In Gateway API, RegularExpression path match is Implementation-specific, so regex syntax and behavior can differ between implementations.
  • The pathTemplate comment in the v0.19 configmap example says “only applicable to serverless deployment”, yet the HTTPRoute reconciler implements it. Documentation and code disagree, so verify per version before relying on it.

Turning generation off and writing routes ourselves was simpler than layering extra settings to work around these.

One route per model. For an ISVC named qwen in namespace models:

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: qwen
namespace: models
spec:
parentRefs:
- name: <gateway-name>
namespace: <gateway-namespace>
hostnames:
- llm.example.com
rules:
- matches:
- path:
type: PathPrefix
value: /models/qwen
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /
backendRefs:
- name: qwen-predictor
port: 80
  • The path follows /<namespace>/<isvc>, so ISVCs with the same name in different namespaces do not collide.
  • ReplacePrefixMatch: / strips the prefix, so the model server receives its original path (/v1/chat/completions and so on). The Gateway API CRD validates that a rule using ReplacePrefixMatch has exactly one PathPrefix match.
  • The backend is the <isvc>-predictor Service KServe creates, on port 80. The KServe source uses the same value as its default HTTP port (CommonDefaultHttpPort).
  • The Gateway listener’s allowedRoutes must accept routes from other namespaces. That is covered in Envoy Gateway Setup.

When another API started sharing the llm.example.com host, we narrowed that API’s route from all of / to a specific prefix such as /internal/v1/agent. Gateway API prefers the PathPrefix match with the most characters, but once routes from several teams share a host, it gets hard to read who owns which prefix. Not leaving broad prefixes around prevents mistakes.

No Envoy Gateway specific resources (SecurityPolicy, BackendTrafficPolicy and so on) are used for this routing. Gateway API support levels of the fields used, per the comments in apis/v1/httproute_types.go on the Gateway API repository’s main branch:

FieldSupport level
hostnamesCore
path match PathPrefixCore
Kubernetes Service in backendRefsCore
URLRewrite filterExtended

When moving to another implementation, only URLRewrite ReplacePrefixMatch support needs checking. The routes KServe generates use RegularExpression matches (Implementation-specific) and timeouts (Extended), so the generated routes actually need more checks when switching implementations. KServe v0.19’s disableHTTPRouteTimeout option exists for implementations that do not support the timeouts field.

An operational problem: the route outlives the ISVC

Section titled “An operational problem: the route outlives the ISVC”

Deleting an ISVC also deletes the predictor Service KServe created. A hand-made HTTPRoute has no such link, so it stays, and its parent condition in status shows an error of the form service ... not found. The exact message and reason can differ by implementation and version, so read status.parents[].conditions from kubectl get httproute <name> -o yaml directly.

Route lifetime has to be managed together with the ISVC. Keeping the ISVC and HTTPRoute in the same kustomize directory lets the GitOps tool create and delete them as one unit. If there is a procedure that deletes only the ISVC, route deletion must be part of it.

Changes were verified in this order.

Terminal window
# Does the manifest render as expected
kustomize build overlays/<env> > /tmp/rendered.yaml
# Schema and CRD validation by the API server (nothing is persisted)
kubectl apply --dry-run=server -f /tmp/rendered.yaml
# Route status after Git push and Argo CD sync
kubectl -n models get httproute qwen -o yaml
# A real call
curl -s http://llm.example.com/models/qwen/v1/models

--dry-run=server catches CRD schema and CEL validation (for example the ReplacePrefixMatch and PathPrefix rule), but it does not tell you whether the backend Service exists or whether the Gateway accepts the route. That can only be confirmed after sync, from the route’s Accepted and ResolvedRefs conditions and the curl result.

  • In KServe v0.19, disableIngressCreation only stops new route creation. Existing routes stay, IngressReady becomes True, and status.url follows the new domainTemplate.
  • When callers read status.url decides whether the switch is safe.
  • A predictor-only ISVC needs just one route per model, using PathPrefix and URLRewrite.
  • Hand-made routes must share the ISVC’s lifetime.