全部產品
Search
文件中心

Container Service for Kubernetes:自訂Gateway配置

更新時間:Aug 09, 2025

Gateway with Inference Extension基於Envoy Gateway實現,您可以通過調整EnvoyProxy資源配置來調整實際的Gateway參數,如Service類型、Deployment副本數以及Resources等。本文介紹如何為不同範圍的Gateway配置副本數和資源用量。

配置說明

在使用Gateway with Inference Extension組件管理產生式 AI 推理服務時,您需要建立 GatewayClass 和 Gateway 資源。

實際Gateway的運行參數(如副本數、資源用量等)可以通過關聯一個 EnvoyProxy 資源來定義。關聯方式有兩種:

  • 精細化配置 (針對單個Gateway):將 EnvoyProxy 資源直接關聯到指定的 Gateway 資源上,實現對單個Gateway的獨立配置。

  • 統一配置 (針對整個Gateway Class):將 EnvoyProxy 資源關聯到 GatewayClass 上。這樣,該 GatewayClass 下所有未進行獨立配置的 Gateway 都會繼承這套統一的資源參數。

重要

上述兩種配置若同時存在時,獨立配置的Gateway資源參數會優先生效。

指定Gateway配置方式

您可以通過在Gateway資源的infrastructure欄位中,引用EnvoyProxy資源來配置Gateway的副本數和資源用量。 樣本如下:

apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: eg
spec:
  gatewayClassName: eg
  infrastructure:
    parametersRef:
      group: gateway.envoyproxy.io
      kind: EnvoyProxy
      name: custom-proxy-config
  listeners:
    - name: http
      protocol: HTTP
      port: 80
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: custom-proxy-config
spec:
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        replicas: 2
        container:
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
            limits:
              cpu: 1
              memory: 2Gi

上述樣本中,在Gateway資源的infrastructure欄位通過parametersRef欄位引用了名為custom-proxy-configEnvoyProxy資源,用於配置副本數和資源用量。

重要

Gateway資源只能引用相同命名空間的EnvoyProxy資源。

指定GatewayClass配置方式

您也可以通過在GatewayClass下引用EnvoyProxy資源,來為所有屬於當前GatewayClassGateway配置副本數和資源用量。樣本如下:

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: eg
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
  parametersRef:
    group: gateway.envoyproxy.io
    kind: EnvoyProxy
    name: custom-proxy-config
    namespace: default
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: custom-proxy-config
  namespace: default
spec:
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        replicas: 2
        container:
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
            limits:
              cpu: 1
              memory: 2Gi

上述樣本中,在GatewayClass資源的parametersRef欄位引用了名為custom-proxy-configEnvoyProxy資源,用於配置副本數和資源用量。

EnvoyProxy資源的完整配置及常用欄位說明

以下為EnvoyProxy的完整配置樣本:

apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  name: custom-proxy-config
spec:
  provider:
    type: Kubernetes
    kubernetes:
      envoyDeployment:
        replicas: 2  # 若同時配置了envoyHpa,則不需要配置replicas
        strategy:
          rollingUpdate:
            maxSurge: 2
            maxUnavailable: 1
        pod:
          affinity: ...
          tolerations: ...
          nodeSelector: ...
        container:
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
            limits:
              cpu: 1
              memory: 2Gi
      envoyService:
        annotations:
          key: value
        labels:
          key: value
        type: LoadBalancer
        loadBalancerClass: ...
        externalTrafficPolicy: Cluster # or Local
      envoyHpa:
        minReplicas: 1
        maxReplicas: 10
        metrics:
        - type: Resource
          resource:
            name: cpu
            target:
              type: Utilization
              averageUtilization: 80
        - type: Resource
          resource:
            name: memory
            target:
              type: Utilization
              averageUtilization: 80
      envoyPDB:
        minAvailable: 1
重要

若同時配置envoyDeploymentenvoyHpa,則envoyDeployment下無需配置replicas

此處僅列舉一些常見的欄位。完整的EnvoyProxy資源定義,請參見EnvoyProxy

欄位名

類型

是否必填

說明

envoyDeployment

KubernetesDeploymentSpec

自訂Gateway的工作負載配置。

envoyService

KubernetesServiceSpec

自訂Gateway的Service配置。

envoyHpa

KubernetesHorizontalPodAutoscalerSpec

自訂Gateway的HPA配置。

envoyPDB

KubernetesPodDisruptionBudgetSpec

自訂Gateway的PodDisruptionBudget配置。