KServe HTTPRoute 자동 생성을 끄고 단일 host와 path로 모델 라우팅하기
이 글은 KServe를 Gateway API(구현체는 Envoy Gateway)와 함께 쓰면서, 모델마다 host가 하나씩 생기는 기본 동작 대신 llm.<도메인> 하나에 모델별 path를 붙여 호출하도록 바꾼 기록이다. Gateway API와 Envoy Gateway 자체의 구성은 왜 Gateway API인가, Envoy Gateway 구성, HTTPRoute 라우팅 및 검증에서 다뤘으니, 여기서는 KServe가 만드는 HTTPRoute와 그것을 끈 뒤의 동작에만 집중한다.
기준 버전은 KServe v0.19.0이고, 동작 설명은 해당 tag의 pkg/controller/v1beta1/inferenceservice/reconcilers/ingress/httproute_reconciler.go를 직접 읽고 확인한 내용이다. 예시의 도메인은 example.com, namespace는 models로 일반화했다.
KServe가 기본으로 만드는 HTTPRoute
섹션 제목: “KServe가 기본으로 만드는 HTTPRoute”Gateway API 모드(enableGatewayApi: true)의 Standard(Raw) 배포에서 KServe는 InferenceService(이하 ISVC)를 reconcile할 때마다 HTTPRoute를 직접 만든다. predictor만 있는 ISVC라면 두 개다.
| HTTPRoute 이름 | host | 보내는 곳 |
|---|---|---|
<isvc> (top-level) | domainTemplate으로 만든 host, 기본 <isvc>-<namespace>.<ingressDomain> | transformer가 있으면 transformer Service, 없으면 predictor Service |
<isvc>-predictor | 같은 template에 이름만 <isvc>-predictor를 넣은 host | predictor Service |
transformer나 explainer가 있으면 <isvc>-transformer, <isvc>-explainer route가 같은 방식으로 더 생긴다. 소스에서 확인한 세부 사항은 다음과 같다.
- 모든 route의 path match는
RegularExpression타입이다. 기본 rule은^/.*$로 모든 path를 받는다. explainer가 있으면 top-level route에^/v1/models/[\w-]+:explain$rule이 추가된다. - 각 rule에는
RequestHeaderModifierfilter로 ISVC 이름과 namespace header가 붙는다. - predictor Service에 REST와 gRPC port가 함께 있으면 gRPC rule(
content-type: application/grpc*header와/inference.GRPCInferenceService/path)이 먼저, HTTP fallback rule이 나중에 들어간다. - route에는 ISVC를 controller로 하는 ownerReference가 붙는다. ISVC를 지우면 garbage collection으로 같이 지워진다.
status.url은 top-level host로 정해진다. path는 들어가지 않는다.
모델이 늘수록 host가 늘어나는 구조다. Gateway API 문서의 그림처럼 host마다 route와 Service가 하나씩 대응되는 모양이 모델 수만큼 반복된다.

바꾸려던 모양
섹션 제목: “바꾸려던 모양”목표는 두 가지였다.
- 호출하는 쪽은
llm.example.com하나만 알고, 모델은 path로 고른다. 예를 들어http://llm.example.com/models/qwen/v1/chat/completions형태다. - route는 KServe controller가 아니라 앱 배포 manifest(GitOps 저장소)가 직접 관리한다. 어떤 path가 어떤 Service로 가는지가 Git diff로 보이게 하려는 것이다.
자동 생성 끄기
섹션 제목: “자동 생성 끄기”설정은 kserve namespace의 inferenceservice-config ConfigMap에 있는 ingress 항목이다. 바꾼 값은 두 개다.
{ "enableGatewayApi": true, "kserveIngressGateway": "<gateway-namespace>/<gateway-name>", "ingressDomain": "example.com", "domainTemplate": "llm.{{ .IngressDomain }}", "disableIngressCreation": true, "urlScheme": "http"}disableIngressCreation: true가 HTTPRoute 생성을 멈추고, domainTemplate은 status.url에 들어갈 host를 정한다. v0.19 configmap 주석에도 disableIngressCreation은 raw deployment mode용 설정으로 적혀 있다.
끄면 실제로 바뀌는 것
섹션 제목: “끄면 실제로 바뀌는 것”Reconcile 함수의 분기를 보면 동작이 분명하다.
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 {여기서 운영에 영향을 주는 사실 세 가지가 나온다.
- 이미 만들어진 route는 지워지지 않는다. else 분기에는 삭제 코드가 없다. 기존 route는 ISVC가 살아 있는 동안 그대로 남아 예전 host로 계속 트래픽을 받고, controller가 더는 갱신하지도 않는다. ownerReference가 있으니 ISVC를 지울 때 함께 사라진다. 기존 host를 끊고 싶으면 직접 지워야 한다.
IngressReadycondition은 무조건 True가 된다. route가 없어도 ISVC는 Ready로 보인다. 라우팅이 실제로 되는지는 ISVC status로 알 수 없고, 직접 만든 HTTPRoute의 status와 실제 호출로 확인해야 한다.status.url은 새domainTemplate기준으로 즉시 바뀐다.createRawURL은 host만 template으로 만들기 때문에 모든 ISVC의status.url이http://llm.example.com으로 같아진다. path가 없으므로 이 값만으로는 어느 모델인지 구분되지 않는다.
기존 모델 호출이 끊기지 않았던 이유는 앱 쪽 구현 덕분이었다. 앱이 모델 등록 시점에 status.url을 한 번 읽어 저장해 두고, 이후에는 저장한 값으로 호출했다. 매 요청이나 주기적으로 status.url을 다시 읽는 클라이언트였다면 설정을 바꾸는 순간 모든 모델이 같은 host를 가리키게 되어 영향이 있었을 것이다. 설정을 바꾸기 전에 호출하는 쪽이 status.url을 언제 읽는지부터 확인하는 것이 좋다.
predictor route는 다시 만들 필요가 없다
섹션 제목: “predictor route는 다시 만들 필요가 없다”<isvc>-predictor route는 top-level route와 별도로 predictor 컴포넌트에 직접 가는 host를 준다. transformer가 있는 구성에서 top-level host는 transformer로 가므로, predictor를 따로 부르려면 이 route가 필요하다.
transformer와 explainer 없이 predictor만 쓰는 ISVC라면 소스상 top-level route도 else 분기에서 predictor Service로 보낸다. 두 route의 backend가 같은 Service이므로, 직접 관리할 때는 모델당 route 하나만 만들면 된다.
pathTemplate을 쓰지 않은 이유
섹션 제목: “pathTemplate을 쓰지 않은 이유”KServe에도 path 기반 라우팅 옵션이 있다. ingress에 pathTemplate: "/serving/{{ .Namespace }}/{{ .Name }}"을 넣으면 top-level route에 path rule이 더해진다. 그래도 쓰지 않은 이유는 v0.19 소스에서 확인한 다음 제약 때문이다.
- path rule이 붙는 host가
ingressDomain그 자체다. 소스는allowedHosts에ingressConfig.IngressDomain을 추가한다.llm.example.com같은 별도 host가 아니라example.com에 붙는다. - 모델별 host가 없어지지 않는다. path rule은 top-level route에 추가될 뿐이고, 기존 host 기반 rule과 predictor route는 그대로 생긴다.
- prefix를 떼지 않는다. path rule은
<path>/를RegularExpression으로 match하고 filter는 header 추가뿐이다. URLRewrite가 없으므로 model server는/serving/models/qwen/v1/...같은 전체 path를 받는다. OpenAI 호환 서버처럼/v1/...만 처리하는 서버에는 맞지 않는다. status.url에 path가 반영되지 않는다.createRawURL은 host만 만든다.- match 타입이
RegularExpression이다. Gateway API에서 RegularExpression path match는 Implementation-specific 지원 등급이라 구현체마다 정규식 문법과 동작이 다를 수 있다. - v0.19 configmap 예시의
pathTemplate주석은 “only applicable to serverless deployment”라고 적혀 있지만 HTTPRoute reconciler에도 구현은 있다. 문서와 코드가 어긋나 있어 동작을 기대하기 전에 버전별로 확인이 필요하다.
이 제약을 우회하려고 추가 설정을 얹는 것보다, 자동 생성을 끄고 route를 직접 쓰는 편이 단순했다.
직접 관리하는 HTTPRoute
섹션 제목: “직접 관리하는 HTTPRoute”모델 하나에 route 하나를 둔다. ISVC 이름이 qwen, namespace가 models라면 다음과 같다.
apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: name: qwen namespace: modelsspec: 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- path는
/<namespace>/<isvc>규칙으로 정했다. 같은 이름의 ISVC가 다른 namespace에 있어도 겹치지 않는다. ReplacePrefixMatch: /로 접두사를 떼서 model server는 원래 path(/v1/chat/completions등)를 받는다. Gateway API CRD는ReplacePrefixMatch를 쓸 때 rule에 PathPrefix match가 정확히 하나만 있도록 검증한다.- backend는 KServe가 만드는
<isvc>-predictorService이고 port는 80이다. KServe 소스에서도 기본 HTTP port로 같은 값(CommonDefaultHttpPort)을 쓴다. - Gateway의 listener가 다른 namespace의 route를 받도록
allowedRoutes가 열려 있어야 한다. 이 부분은 Envoy Gateway 구성에서 다뤘다.
같은 llm.example.com host를 다른 API와 나눠 쓰게 되었을 때, 원래 / 전체를 받던 그 API의 route를 /internal/v1/agent 같은 좁은 prefix로 줄였다. Gateway API는 match가 더 긴 PathPrefix를 우선하지만, 한 host에 여러 팀의 route가 섞이면 누가 어떤 prefix를 쓰는지 읽기 어려워진다. 넓은 prefix를 남겨 두지 않는 편이 사고를 줄인다.
다른 구현체로 옮길 때
섹션 제목: “다른 구현체로 옮길 때”Envoy Gateway 전용 리소스(SecurityPolicy, BackendTrafficPolicy 등)는 이 라우팅에 쓰지 않았다. 사용한 필드의 Gateway API 지원 등급은 다음과 같다(Gateway API 저장소 main 브랜치의 apis/v1/httproute_types.go 주석 기준).
| 필드 | 지원 등급 |
|---|---|
hostnames | Core |
path match PathPrefix | Core |
backendRefs의 Kubernetes Service | Core |
URLRewrite filter | Extended |
다른 구현체로 옮길 때는 URLRewrite의 ReplacePrefixMatch 지원 여부만 확인하면 된다. 반대로 KServe가 자동으로 만드는 route는 RegularExpression match(Implementation-specific)와 timeouts(Extended)를 쓰므로, 구현체를 바꿀 때 오히려 자동 생성 쪽이 더 확인할 것이 많다. KServe v0.19에 disableHTTPRouteTimeout 옵션이 있는 것도 timeouts 필드를 지원하지 않는 구현체 때문이다.
운영에서 만난 문제: ISVC를 지웠는데 route가 남는다
섹션 제목: “운영에서 만난 문제: ISVC를 지웠는데 route가 남는다”ISVC를 지우면 KServe가 만든 predictor Service도 함께 지워진다. 직접 만든 HTTPRoute에는 그런 연결이 없어서 그대로 남고, route status의 parent condition에 service ... not found 형태의 오류가 뜬다. 오류 문구와 reason은 구현체와 버전에 따라 다를 수 있으니 kubectl get httproute <name> -o yaml의 status.parents[].conditions를 직접 보는 것이 확실하다.
route의 수명을 ISVC와 같이 관리해야 한다. 같은 kustomize 디렉터리에 ISVC와 HTTPRoute를 함께 두면 GitOps 도구가 둘을 같은 단위로 만들고 지운다. ISVC만 따로 지우는 절차가 있다면 route 삭제도 같은 절차에 넣어야 한다.
확인 순서
섹션 제목: “확인 순서”변경은 다음 순서로 확인했다.
# manifest가 기대한 대로 렌더링되는지kustomize build overlays/<env> > /tmp/rendered.yaml
# API server 기준 schema와 CRD 검증 (실제 반영은 하지 않음)kubectl apply --dry-run=server -f /tmp/rendered.yaml
# Git push와 Argo CD sync 후 route statuskubectl -n models get httproute qwen -o yaml
# 실제 호출curl -s http://llm.example.com/models/qwen/v1/models--dry-run=server는 CRD schema와 CEL 검증(예를 들어 ReplacePrefixMatch와 PathPrefix 조합 규칙)까지 잡아 주지만, backend Service가 존재하는지나 Gateway가 route를 받아들이는지는 알려 주지 않는다. 그 부분은 sync 뒤 route의 Accepted, ResolvedRefs condition과 curl 결과로만 확인할 수 있다.
- KServe v0.19의
disableIngressCreation은 새 route 생성만 멈춘다. 기존 route는 남고,IngressReady는 True가 되며,status.url은 새domainTemplate으로 바뀐다. - 호출하는 쪽이
status.url을 언제 읽는지가 전환의 안전성을 결정한다. - predictor만 쓰는 ISVC는 모델당 PathPrefix와 URLRewrite를 쓴 route 하나로 충분하다.
- 직접 만든 route는 ISVC와 수명을 묶어 관리해야 한다.