大規模言語モデル (LLM) アプリケーションは通常、実行に GPU を必要とします。また、GPU アクセラレーションノードまたは仮想ノードは CPU ノードよりも高価です。Gateway with Inference Extension を使用すると、CPU 計算能力を使用して、LLM 推論シナリオのインテリジェントな負荷分散機能を迅速に体験できます。このトピックでは、Gateway with Inference Extension を使用してモック環境を構築し、推論サービスのインテリジェントな負荷分散機能を実証する方法について説明します。
適用性
Gateway with Inference ExtensionGateway with Inference Extension がインストールされており、クラスターの作成時に [Gateway API Inference Extension を有効にする] が選択されている必要があります。詳細については、「手順 2: Gateway with Inference ExtensionGateway with Inference Extension コンポーネントをインストールする」をご参照ください。
このトピックで構築するモック環境は、Gateway with Inference Extension コンポーネントの基本的な AI 機能の一部 (たとえば、段階的リリース、リクエストサーキットブレーキング、トラフィックミラーリング など) を体験することのみを目的としています。これは、ストレステストシナリオには適しておらず、本番環境での使用は推奨されません。
手順
手順 1: モックサンプルアプリケーションをデプロイする
mock-vllm.yaml を作成します。
apiVersion: v1 kind: ServiceAccount metadata: name: mock-vllm --- apiVersion: v1 kind: Service metadata: name: mock-vllm labels: app: mock-vllm service: mock-vllm spec: ports: - name: http port: 8000 targetPort: 8000 selector: app: mock-vllm --- apiVersion: apps/v1 kind: Deployment metadata: name: mock-vllm spec: replicas: 1 selector: matchLabels: app: mock-vllm template: metadata: labels: app: mock-vllm spec: serviceAccountName: mock-vllm containers: - image: registry-cn-hangzhou.ack.aliyuncs.com/dev/mock-vllm:v0.1.7-g3cffa27-aliyun imagePullPolicy: IfNotPresent name: mock-vllm ports: - containerPort: 8000サンプルアプリケーションをデプロイします。
kubectl apply -f mock-vllm.yaml次の内容で sleep.yaml ファイルを作成します。
apiVersion: v1 kind: ServiceAccount metadata: name: sleep --- apiVersion: v1 kind: Service metadata: name: sleep labels: app: sleep service: sleep spec: ports: - port: 80 name: http selector: app: sleep --- apiVersion: apps/v1 kind: Deployment metadata: name: sleep spec: replicas: 1 selector: matchLabels: app: sleep template: metadata: labels: app: sleep spec: terminationGracePeriodSeconds: 0 serviceAccountName: sleep containers: - name: sleep image: registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/curl:asm-sleep command: ["/bin/sleep", "infinity"] imagePullPolicy: IfNotPresentテストアプリケーションをデプロイして、サンプルアプリケーションにテストリクエストを送信します。
kubectl apply -f sleep.yaml
手順 2: 推論リソースをデプロイする
inference-rule.yaml を作成します。
apiVersion: inference.networking.x-k8s.io/v1alpha2 kind: InferencePool metadata: name: mock-pool spec: extensionRef: group: "" kind: Service name: mock-ext-proc selector: app: mock-vllm targetPortNumber: 8000 --- apiVersion: inference.networking.x-k8s.io/v1alpha2 kind: InferenceModel metadata: name: mock-model spec: criticality: Critical modelName: mock poolRef: group: inference.networking.x-k8s.io kind: InferencePool name: mock-pool targetModels: - name: mock weight: 100InferencePool と InferenceModel をデプロイします。
kubectl apply -f inference-rule.yaml
手順 3: ゲートウェイとルーティングルールをデプロイする
デフォルトでは、Gateway with Inference Extension をインストールすると GatewayClass が作成されます。次のコマンドを実行して、その存在を確認します。
kubectl get gatewayclassGatewayClass リソースが見つからない場合は、手動で作成します。
gateway.yaml を作成します。
apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: mock-gateway spec: gatewayClassName: ack-gateway infrastructure: parametersRef: group: gateway.envoyproxy.io kind: EnvoyProxy name: custom-proxy-config listeners: - name: llm-gw protocol: HTTP port: 80 --- apiVersion: gateway.envoyproxy.io/v1alpha1 kind: EnvoyProxy metadata: name: custom-proxy-config namespace: default spec: provider: type: Kubernetes kubernetes: envoyService: type: ClusterIP --- apiVersion: gateway.envoyproxy.io/v1alpha1 kind: ClientTrafficPolicy metadata: name: mock-client-buffer-limit spec: connection: bufferLimit: 20Mi targetRefs: - group: gateway.networking.k8s.io kind: Gateway name: mock-gateway ---httproute.yaml を作成します。
apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: mock-route spec: parentRefs: - group: gateway.networking.k8s.io kind: Gateway name: mock-gateway sectionName: llm-gw rules: - backendRefs: - group: inference.networking.x-k8s.io kind: InferencePool name: mock-pool weight: 1 matches: - path: type: PathPrefix value: /ゲートウェイとルーティングルールをデプロイします。
kubectl apply -f gateway.yaml kubectl apply -f httproute.yaml
手順 4: テストリクエストを送信する
ゲートウェイの IP アドレスを取得します。
export GATEWAY_ADDRESS=$(kubectl get gateway/mock-gateway -o jsonpath='{.status.addresses[0].value}') echo ${GATEWAY_ADDRESS}テストアプリケーションからリクエストを送信します。
kubectl exec deployment/sleep -it -- curl -X POST ${GATEWAY_ADDRESS}/v1/chat/completions \ -H 'Content-Type: application/json' -H "Host: example.com" -v -d '{ "model": "mock", "max_completion_tokens": 100, "temperature": 0, "messages": [ { "role": "user", "content": "introduce yourself" } ] }'期待される出力:
* Trying 192.168.12.230:80... * Connected to 192.168.12.230 (192.168.12.230) port 80 > POST /v1/chat/completions HTTP/1.1 > Host: example.com > User-Agent: curl/8.8.0 > Accept: */* > Content-Type: application/json > Content-Length: 184 > * upload completely sent off: 184 bytes < HTTP/1.1 200 OK < date: Tue, 27 May 2025 08:21:37 GMT < server: uvicorn < content-length: 354 < content-type: application/json < * Connection #0 to host 192.168.12.230 left intact {"id":"3bcc1fdd-e514-4a06-95aa-36c904015639","object":"chat.completion","created":1748334097.297188,"model":"mock","choices":[{"index":"0","message":{"role":"assistant","content":"As a mock AI Assitant, I can only echo your last message: introduce yourself"},"finish_reason":"stop"}],"usage":{"prompt_tokens":18,"completion_tokens":76,"total_tokens":94}}
手順 5: 環境をクリーンアップする
この環境が不要になった場合は、クリーンアップします:
クラスターリソースを削除します:
# ゲートウェイとルートを削除します。 kubectl delete -f gateway.yaml kubectl delete -f httproute.yaml # テストアプリケーションを削除します。 kubectl delete -f sleep.yaml # バックエンドアプリケーションを削除します。 kubectl delete -f mock-vllm.yaml kubectl delete -f inference-rule.yaml[コンポーネント管理] ページで Gateway with Inference Extension を検索し、コンポーネントカードの [アンインストール] をクリックします。