NGF에서 Gateway API Inference Extension으로 LLM Canary 배포 구성하기

NGINX Gateway Fabric(NGF)과 Gateway API Inference Extension을 사용하면 하나의 Gateway에서 여러 LLM 백엔드로 요청을 분기할 수 있습니다. 이 글에서는 백엔드 파드와 InferencePool을 먼저 생성한 뒤, 하나의 HTTPRoute에 여러 Pool을 연결하는 LLM Canary 구성을 소개합니다.

Stable은 기존 Qwen2.5 파드 2개를 사용하고 Canary는 LFM2.5-2.6B-Q4_K_M.gguf를 실행하는 llama.cpp 파드로 구성합니다. 이후 경로 기반 라우팅, 헤더 기반 라우팅, backendRefs의 90/10 가중치 분배를 차례로 검증합니다.

목차

1. 환경 및 기능 확인
2. LLM 백엔드 생성
  2-1. Stable Qwen 백엔드
  2-2. LFM Canary 백엔드
3. InferencePool과 EPP 구성
4. 단일 HTTPRoute에 복수 Pool 연결
  4-1. 경로·헤더 기반 라우팅
  4-2. backendRefs 가중치 기반 Canary
5. 배포 및 요청 테스트
6. 결론

1. 환경 및 기능 확인

  • Kubernetes : v1.35.7
  • NGINX Gateway Fabric : 2.6.7
  • Gateway API : v1.5.1

InferencePool CRD를 설치하고 NGF 컨트롤러의 기능 플래그를 확인합니다.

kubectl kustomize \
"https://github.com/nginx/nginx-gateway-fabric/config/crd/inference-extension/?ref=v2.6.7" \
| kubectl apply -f -
kubectl -n nginx-gateway get deploy ngf-nginx-gateway-fabric \
-o jsonpath='{.spec.template.spec.containers[0].args}'
# 다음 플래그가 포함되어 있어야 함
--gateway-api-inference-extension

2. LLM 백엔드 생성

HTTPRoute나 InferencePool보다 먼저 모델 서버 파드를 준비합니다. InferencePool은 label selector로 파드를 찾기 때문에 모델별 label과 포트를 먼저 고정해야 합니다.

2-1. Stable Qwen 백엔드

Stable은 이전 포스트에 사용한 qwen25-cpu Deployment를 재사용합니다. 두 파드는 모두 app=qwen25-cpu 라벨과 8080 포트를 사용해야 합니다.

2-2. LFM Canary 백엔드

Canary는 llama.cpp 서버로 LFM2.5 GGUF 모델을 실행합니다.
모델 파일은 Git 저장소에 넣지 않고 llm-workernode의 전용 hostPath 캐시에 저장합니다. nodeSelector를 사용해 Stable과 같은 LLM 노드에 고정합니다.

apiVersion: apps/v1
kind: Deployment
metadata:
name: lfm25-canary
namespace: llm
spec:
replicas: 1
selector:
matchLabels:
app: lfm25-canary
template:
metadata:
labels:
app: lfm25-canary
spec:
nodeSelector:
kubernetes.io/hostname: llm-workernode
containers:
- name: llama-server
image: ghcr.io/ggml-org/llama.cpp:server
args:
- --hf-repo
- LiquidAI/LFM2.5-2.6B-GGUF:Q4_K_M
- --alias
- lfm2.5-2.6b
- --host
- 0.0.0.0
- --port
- "8080"
ports:
- name: http
containerPort: 8080
readinessProbe:
httpGet:
path: /health
port: http
periodSeconds: 10
volumeMounts:
- name: model-cache
mountPath: /root/.cache/huggingface
volumes:
- name: model-cache
hostPath:
path: /var/lib/llm-model-cache/lfm25-canary
type: DirectoryOrCreate

파드가 Ready=True가 된 뒤에야 Canary Pool의 endpoint로 사용됩니다. 모델 다운로드와 로딩이 끝나기 전에는 Canary 요청이 실패할 수 있으므로 readiness 상태를 먼저 확인합니다.

3. InferencePool과 EPP 구성

백엔드 파드가 준비되면 Pool과 EPP를 생성합니다. 두 모델을 별도의 Pool로 분리해야 HTTPRoute에서 각각의 가중치를 지정할 수 있습니다.

  • qwen-stable: app=qwen25-cpu 파드 선택
  • lfm-canary: app=lfm25-canary 파드 선택
  • 모델 서버 포트: 8080, EPP 포트: 9002

Canary 가중치는 HTTPRoute에서 처리하므로, 이 글의 비율 검증에는 EPP 커스텀 플러그인이 필요하지 않습니다. 아래 values 파일은 기본 EPP 플러그인을 사용하면서 리소스와 포트만 명시합니다.

inferenceExtension:
replicas: 1
failureMode: FailClose
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
cpu: "1"
memory: 1Gi
inferencePool:
modelServerProtocol: http
targetPorts:
- number: 8080
helm upgrade --install qwen-stable \
oci://registry.k8s.io/gateway-api-inference-extension/charts/inferencepool \
--version v1.5.0 \
--namespace llm \
--values epp-values.yaml \
--set-string inferencePool.modelServers.matchLabels.app=qwen25-cpu \
--wait --timeout 10m
helm upgrade --install lfm-canary \
oci://registry.k8s.io/gateway-api-inference-extension/charts/inferencepool \
--version v1.5.0 \
--namespace llm \
--values epp-values.yaml \
--set-string inferencePool.modelServers.matchLabels.app=lfm25-canary \
--wait --timeout 10m

각 Helm 릴리스가 해당 이름의 InferencePool과 EPP Service를 생성합니다. 따라서 같은 이름의 InferencePool YAML을 별도로 중복 적용하지 않습니다.

4. 단일 HTTPRoute에 복수 Pool 연결

이제 Gateway와 하나의 HTTPRoute를 적용합니다. HTTPRoute의 backendRef에는 Service가 아니라 InferencePool을 지정합니다.

# gateway.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: inference-gateway
namespace: llm
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP

4-1. 경로·헤더 기반 라우팅

# httproute.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: llm-canary
namespace: llm
spec:
parentRefs:
- name: inference-gateway
sectionName: http
rules:
# /qwen/v1/... → Stable Qwen
- matches:
- path:
type: PathPrefix
value: /qwen
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /
backendRefs:
- group: inference.networking.k8s.io
kind: InferencePool
name: qwen-stable
weight: 100
# x-model: lfm → Canary LFM
- matches:
- headers:
- type: Exact
name: x-model
value: lfm
backendRefs:
- group: inference.networking.k8s.io
kind: InferencePool
name: lfm-canary
weight: 100
# /canary/v1/... → Stable 90%, Canary 10%
- matches:
- path:
type: PathPrefix
value: /canary
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /
backendRefs:
- group: inference.networking.k8s.io
kind: InferencePool
name: qwen-stable
weight: 90
- group: inference.networking.k8s.io
kind: InferencePool
name: lfm-canary
weight: 10

현재 클러스터의 InferencePool API 그룹은 inference.networking.k8s.io입니다. 다른 API 그룹을 지정하면 backendRef를 해석하지 못할 수 있습니다. 또한 경로 접두어는 URLRewrite로 제거해야 llama.cpp의 /v1 API에 연결됩니다.

weight: 90과 weight: 10은 Pool 사이의 상대적인 요청 분배 비율입니다. 고정된 순서가 아닌 확률적 분배이므로 단일 요청이나 적은 표본만으로 비율을 판단하지 않습니다.

5. 배포 및 요청 테스트

리소스는 백엔드, Pool/EPP, Gateway/HTTPRoute 순서로 적용합니다.

현재 Gateway 주소는 172.16.61.71입니다.

해당 Gateway로 요청하여 Qwen, LFM 모델을 라우팅 되는지 확인합니다.
먼저 /qwen 경로로 요청하여 모델이 잘 라우팅되는지 확인합니다.

$ curl -sS --max-time 120 \
-H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"안녕하세요"}],"max_tokens":128}' \
http://172.16.61.71/qwen/v1/chat/completions | jq .
응답 원문
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"role": "assistant",
"content": "안녕하세요! 어떻게 도와드릴까요?"
}
}
],
"created": 1787808575,
"model": "qwen2.5-0.5b",
"system_fingerprint": "b10398-8e7f22b67",
"object": "chat.completion",
"usage": {
"completion_tokens": 12,
"prompt_tokens": 32,
"total_tokens": 44,
"prompt_tokens_details": {
"cached_tokens": 31
}
},
"id": "chatcmpl-iiqdmCjTJ7rEuJIa6n5aycqsD2MHPxPy",
"timings": {
"cache_n": 31,
"prompt_n": 1,
"prompt_ms": 129.121,
"prompt_per_token_ms": 129.121,
"prompt_per_second": 7.744673600731097,
"predicted_n": 12,
"predicted_ms": 635.293,
"predicted_per_token_ms": 52.94108333333333,
"predicted_per_second": 18.888922119400025
}
}

qwen 모델로 정상적으로 라우팅 된 것을 확인할 수 있습니다.

curl -sS --max-time 120 \
-H 'x-model: lfm' \
-H 'Content-Type: application/json' \
-d '{"messages":[{"role":"user","content":"안녕하세요"}],"max_tokens":128}' \
http://172.16.61.71/v1/chat/completions | jq .

Header 기반 라우팅을 확인합니다.

응답 원문
{
"choices": [
{
"finish_reason": "length",
"index": 0,
"message": {
"role": "assistant",
"content": "안녕하세요! 😊\n\n저는",
"reasoning_content": "The user said \"안녕하세요\" which is Korean for \"Hello\" or \"Good morning/afternoon\". This is a standard greeting. I should respond politely in Korean, acknowledging their greeting and offering assistance.\n\nMy response should be:\n- Polite (using appropriate honorifics like ~합니다)\n- Friendly\n- Offer help\n\nExample response: \"안녕하세요! 저는 AI 어시스턴트입니다. 무엇을 도와드릴까요?\" (Hello! I am an AI assistant. How can I help you?)\n\nLet me construct a helpful and polite response."
}
}
],
"created": 1787810310,
"model": "lfm2.5-2.6b",
"system_fingerprint": "b10398-8e7f22b67",
"object": "chat.completion",
"usage": {
"completion_tokens": 128,
"prompt_tokens": 12,
"total_tokens": 140,
"prompt_tokens_details": {
"cached_tokens": 0
}
},
"id": "chatcmpl-SGYT6jBjbM0JdBdhKEx6vnrr06DLzjhf",
"timings": {
"cache_n": 0,
"prompt_n": 12,
"prompt_ms": 864.243,
"prompt_per_token_ms": 72.02025,
"prompt_per_second": 13.884983737212796,
"predicted_n": 128,
"predicted_ms": 12292.515,
"predicted_per_token_ms": 96.0352734375,
"predicted_per_second": 10.412840659539565
}
}

lfm2.5-2.6b 모델로 라우팅 되는 것을 확인할 수 있습니다.

Canary 엔트포인트에 요청을 전송하여 가중치에 따라 요청이 분산되는지 확인합니다.

(NGINX Gateway Fabric의 분산 알고리즘은 NGINX Split Clients와 동일합니다.
https://nginx.org/en/docs/http/ngx_http_split_clients_module.html)

$ for i in $(seq 1 100)
do
curl -sS --max-time 30 \
-w '\n' \
http://172.16.61.71/canary/v1/models
done | jq -r '.data[0].id // "ERROR"' | sort | uniq -c

가중치의 근삿값으로 라우팅이 배분 되는 것을 확인할 수 있습니다.

천천히 이전 qwen2.5 0.5b 모델에서 lfm2.5-2.6b 모델로 이전합니다.

Edit을 사용하여 가중치를 50:50으로 변경합니다.

kubectl edit -n llm httproute llm-canary

이후 저장하여 httproute 설정을 반영합니다.

구성이 적용된 것을 확인할 수 있습니다.

이후 lfm 모델로 전환합니다.

kubectl edit -n llm httproute llm-canary

가중치를 qwen 0 : lfm 100으로 지정하여 하나의 모델로 라우팅 될 수 있도록 구성합니다.

완전히 모델이 lfm2.5로 변경된 것을 확인할 수 있습니다.

6. 결론

실제 검증에서는 /canary 경로에 100회 요청을 보냈고 모두 HTTP 200으로 처리되었습니다. Stable 89회, Canary 11회가 관측되어 90/10 가중치가 정상적으로 적용된 것을 확인했습니다.

단일 HTTPRoute에 여러 InferencePool을 연결하면 모델별 Gateway를 추가하지 않고도 경로·헤더 기반 선택과 점진적인 Canary 배포를 함께 구현할 수 있습니다. HTTPRoute는 Pool 간 정책을, EPP는 Pool 내부 endpoint 선택을 담당하므로 두 계층을 분리해서 운영할 수 있습니다.

NGINX Plus Gateway Fabric 도입을 검토하고 계신가요? NGINX STORE를 통해 문의하여 NGINX One Trial로 NGINX Plus Gateway Fabric을 무료로 체험해 보세요.