기본 배포
이 문서는 kgateway + Bifrost 기반 추론 게이트웨이의 핵심 구성 요소를 배포하는 절차를 다룹니다. 단일 NLB 엔드포인트 뒤에서 여러 서비스를 경로 기반으로 라우팅하고, Bifrost Gateway Mode로 멀티 프로바이더 통합을 구현합니다.
학습: 30분 | 배포: 45분
kgateway 설치 및 기본 리소스 구성
1.1 Gateway API CRD 설치
# Gateway API 표준 CRD 설치 (v1.5.1+)
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml
# 실험적 기능 포함 설치 (HTTPRoute 필터 등)
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/experimental-install.yaml
1.2 kgateway Helm 설치 (CRDs → 메인 차트)
kgateway 차트는 OCI 레지스트리(cr.kgateway.dev)로 배포됩니다. OCI 레지스트리는 helm repo add 대상이 아니므로 helm upgrade -i로 직접 참조하며, CRDs 차트를 먼저 설치한 뒤 메인 차트를 설치합니다.
# 최신 안정 버전으로 설정 (릴리스: github.com/kgateway-dev/kgateway/releases)
export KGW_VERSION=v2.3.5
# 1) CRDs 차트 먼저 설치
helm upgrade -i kgateway-crds \
oci://cr.kgateway.dev/kgateway-dev/charts/kgateway-crds \
--version ${KGW_VERSION} \
--namespace kgateway-system --create-namespace --wait
# 2) 메인 kgateway 차트 설치
helm upgrade -i kgateway \
oci://cr.kgateway.dev/kgateway-dev/charts/kgateway \
--version ${KGW_VERSION} \
--namespace kgateway-system \
--wait
차트 버전은 kgateway releases에서 최신 2.x를 확인하세요. 컨트롤러 replica/리소스, 메트릭 등 튜닝 값은 helm show values oci://cr.kgateway.dev/kgateway-dev/charts/kgateway --version ${KGW_VERSION}로 실제 키를 확인한 뒤 --set/-f values.yaml로 지정하세요(차트 버전마다 키가 다를 수 있음).
KV-aware(L2) 라우팅을 구성하려면 InferencePool + EPP를 별도 설치합니다. 고급 기능: Inference Extension을 참조하세요.
1.3 GatewayClass 정의
kgateway Helm 차트는 기본 GatewayClass(이름 kgateway)를 함께 설치합니다. 직접 정의할 경우 controllerName은 kgateway.dev/kgateway입니다.
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: kgateway
spec:
controllerName: kgateway.dev/kgateway
description: "kgateway for AI inference routing"
kgateway v2.x에서 프록시 replica·리소스 등 인프라 설정은 별도 GatewayParameters(group gateway.kgateway.dev/v1alpha1) 리소스로 정의하고, **Gateway 리소스의 spec.infrastructure.parametersRef**에서 참조합니다(GatewayClass의 parametersRef가 아님).
apiVersion: gateway.kgateway.dev/v1alpha1
kind: GatewayParameters
metadata:
name: kgateway-params
namespace: ai-gateway
spec:
kube:
deployment:
replicas: 3
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: unified-gateway
namespace: ai-gateway
spec:
gatewayClassName: kgateway
infrastructure:
parametersRef:
group: gateway.kgateway.dev
kind: GatewayParameters
name: kgateway-params
# listeners 는 아래 1.4 참조
정확한 spec.kube 하위 필드는 설치한 차트 버전의 GatewayParameters CRD 스키마(kubectl explain gatewayparameters.spec.kube)로 확인하세요.
1.4 Gateway 리소스 (단일 NLB 통합)
아래는 개발/테스트용 기본 구성입니다. 프로덕션 환경에서는 반드시 고급 기능: CloudFront + WAF/Shield를 적용하여 NLB를 직접 노출하지 마세요. 인증 없이 퍼블릭으로 SG를 오픈하면 회사 정책에 의해 자동 차단됩니다.
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: unified-gateway
namespace: ai-gateway
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: "external"
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip"
service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
spec:
gatewayClassName: kgateway
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: All
1.5 ReferenceGrant (크로스 네임스페이스 접근)
HTTPRoute가 다른 네임스페이스의 Service를 참조하려면 ReferenceGrant가 필요합니다.
# ai-inference 네임스페이스의 Service 접근 허용
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
name: allow-gateway-to-services
namespace: ai-inference
spec:
from:
- group: gateway.networking.k8s.io
kind: HTTPRoute
namespace: ai-gateway
to:
- group: ""
kind: Service
---
# observability 네임스페이스의 Langfuse Service 접근 허용
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
name: allow-gateway-to-langfuse
namespace: observability
spec:
from:
- group: gateway.networking.k8s.io
kind: HTTPRoute
namespace: ai-gateway
to:
- group: ""
kind: Service
2. HTTPRoute 설정
단일 NLB 엔드포인트 뒤에서 여러 서비스를 경로 기반으로 라우팅합니다.
2.1 vLLM 직접 라우팅
Bifrost 없이 kgateway에서 vLLM으로 직접 라우팅하는 패턴입니다. 단일 모델만 사용하는 경우 가장 단순합니다.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: vllm-route
namespace: ai-inference
spec:
parentRefs:
- name: unified-gateway
namespace: ai-gateway
hostnames:
- "api.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /v1/
backendRefs:
- name: vllm-service
port: 8000
2.2 Bifrost 경유 라우팅
멀티 프로바이더 통합, Cascade Routing, OTel 모니터링이 필요한 경우 Bifrost를 경유합니다.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: bifrost-route
namespace: ai-gateway
spec:
parentRefs:
- name: unified-gateway
namespace: ai-gateway
hostnames:
- "api.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /v1/
backendRefs:
- name: bifrost-service
namespace: ai-external
port: 8080
2.3 Langfuse Sub-path 라우팅 (URLRewrite)
Langfuse (Next.js)는 /에서 서빙하므로, /langfuse prefix로 접근하려면 URLRewrite가 필요합니다. Langfuse 아키텍처 및 배포 상세는 Langfuse 배포 가이드를 참조하세요.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: langfuse-route
namespace: observability
spec:
parentRefs:
- name: unified-gateway
namespace: ai-gateway
hostnames:
- "api.example.com"
rules:
# /langfuse → / prefix 제거
- matches:
- path:
type: PathPrefix
value: /langfuse/
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /
backendRefs:
- name: langfuse-web
port: 3000
# Next.js static assets
- matches:
- path:
type: PathPrefix
value: /_next
backendRefs:
- name: langfuse-web
port: 3000
# Langfuse auth API
- matches:
- path:
type: PathPrefix
value: /api/auth
backendRefs:
- name: langfuse-web
port: 3000
# Langfuse public API
- matches:
- path:
type: PathPrefix
value: /api/public
backendRefs:
- name: langfuse-web
port: 3000
# Favicon 등 static files
- matches:
- path:
type: PathPrefix
value: /icon.svg
backendRefs:
- name: langfuse-web
port: 3000
2.4 OTel URLRewrite (Bifrost → Langfuse)
Bifrost OTel 플러그인은 collector_url을 전체 URL(경로 포함)로 사용하므로, config.json에서 전체 OTLP 경로를 직접 지정할 수 있습니다. 단, kgateway에서 경로 변환이 필요한 경우 아래 HTTPRoute를 사용할 수 있습니다. OTel 연동 상세는 Langfuse OTel 설정을 참조하세요.
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: langfuse-otel-route
namespace: observability
spec:
parentRefs:
- name: unified-gateway
namespace: ai-gateway
hostnames:
- "api.example.com"
rules:
- matches:
- path:
type: PathPrefix
value: /api/public/otel
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /api/public/otel/v1/traces
backendRefs:
- name: langfuse-web
port: 3000