在 Arm 架構上部署 Autopilot 工作負載

本頁面說明如何設定 Google Kubernetes Engine (GKE) Autopilot 部署作業,要求以 Arm 架構為基礎的節點。

關於 Autopilot 中的 Arm 架構

Autopilot 叢集提供運算類別,可滿足有特定硬體需求的工作負載。部分運算類別支援多個 CPU 架構,例如 amd64 和 arm64。

Arm 節點的用途

與類似的 x86 節點相比,採用 Arm 架構的節點可提供更具成本效益的效能。在下列情況中,您應為 Autopilot 工作負載選取 Arm:

  • 您的環境依賴 Arm 架構進行建構和測試。
  • 您正在為搭載 Arm CPU 的 Android 裝置開發應用程式。
  • 您使用多架構映像檔,並想在執行工作負載時盡可能提高成本效益。

事前準備

開始之前,請務必先完成下列工作:

  • 啟用 Google Kubernetes Engine API。
  • 啟用 Google Kubernetes Engine API
  • 如要使用 Google Cloud CLI 執行這項工作,請安裝並初始化 gcloud CLI。如果您先前已安裝 gcloud CLI,請執行 gcloud components update 指令,取得最新版本。較舊的 gcloud CLI 版本可能不支援執行本文件中的指令。

需求條件

  • 如要使用 autopilot-arm ComputeClass,請確認叢集執行的是 GKE 1.35.3-gke.1389000 以上版本。
  • 如要在使用 Autopilot ComputeClass 的 GKE Standard 叢集中,使用智慧預設值 (僅指定 kubernetes.io/arch: arm64 標籤)、autopilot-arm-spot ComputeClass 或 autopilot-arm ComputeClass 等功能,叢集必須執行 1.36.0-gke.3302001 以上版本。
  • 確認您擁有 C4A、N4A 或 Tau T2A Compute Engine 機型的配額。
  • 確認您有為 Arm 架構建構的容器映像檔 Pod。

如何在 Autopilot 中要求 Arm 節點

如要讓 Autopilot 在 Arm 節點上執行 Pod,請使用 nodeSelector 或節點親和性規則,指定下列其中一個選取器 (視 GKE 類型和版本而定):

  • 在 Autopilot 叢集 (智慧預設) 中:僅指定架構類型:

    • kubernetes.io/arch: arm64

    如果工作負載在 Autopilot 叢集上執行,這會選取一般用途的 Arm 平台。

  • 在 Autopilot 叢集或使用 Autopilot ComputeClass 的 Standard 叢集 (僅限 ComputeClass):指定 ComputeClass:

    • cloud.google.com/compute-class: autopilot-arm (或 autopilot-arm-spot)

    選取這個類別後,系統會在容器最佳化的 Arm 平台 (或其 Spot VM 變體) 上排定工作負載,並在准入期間自動將必要的 kubernetes.io/arch: arm64 選取器新增至 Pod。

  • 明確選取 (舊版 GKE):在執行 1.35.3-gke.1389000 以上版本,但低於 1.36.0-gke.3302001 的 Autopilot 叢集中,請指定下列兩個選取器,選取一般用途的 Arm 平台。為確保回溯相容性,新版 GKE 也支援這個組合:

    • cloud.google.com/compute-class: autopilot-arm
    • kubernetes.io/arch: arm64
  • 針對有特定硬體需求的工作負載:請指定下列其中一項:

    • kubernetes.io/arch: arm64。GKE 預設會將 Pod 放在 C4A 機型上。
    • cloud.google.com/machine-family: ARM_MACHINE_SERIES。將 ARM_MACHINE_SERIES 替換為 Arm 機器系列,例如 C4A、N4A 或 T2A。GKE 會將 Pod 放在指定的系列中。

根據預設,使用 Performance 以外的任何標籤,GKE 都能在節點有可用容量時,將其他 Pod 放在同一節點上。如要為每個 Pod 要求專屬節點,請在資訊清單中加入 cloud.google.com/compute-class: Performance 標籤,以及架構或機器系列標籤。詳情請參閱「選擇機器系列,提升 Autopilot Pod 效能」。

或者,您也可以搭配使用 Scale-Out 和 arm64 標籤,要求 T2A。您也可以為 Spot Pod 要求 Arm 架構。

部署工作負載時,Autopilot 會執行下列操作:

  1. 自動佈建 Arm 節點來執行 Pod。
  2. 自動汙染新節點,防止非 Arm Pod 排定至這些節點。
  3. 自動在 Arm Pod 中新增容許條件,允許在新節點上排程。

Arm 架構的要求範例

以下範例規格說明如何在 Autopilot 中使用節點選取器或節點親和性規則,要求 Arm 架構。

nodeSelector

下列資訊清單範例使用智慧預設值,要求 Autopilot 容器最佳化 Arm 節點:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-arm
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-arm
  template:
    metadata:
      labels:
        app: nginx-arm
    spec:
      nodeSelector:
        kubernetes.io/arch: arm64
      containers:
      - name: nginx-arm
        image: nginx
        resources:
          requests:
            cpu: 2000m
            memory: 2Gi

或者,您也可以明確指定 autopilot-arm (或 Spot VM 的 autopilot-arm-spot),要求使用容器最佳化 Arm 平台:

...
    spec:
      nodeSelector:
        cloud.google.com/compute-class: autopilot-arm
...

如要要求特定硬體,而非 Autopilot 容器最佳化節點,請取代 ComputeClass 或在選取器中新增 cloud.google.com/machine-family: C4A。

nodeAffinity

您可以使用節點親和性要求 Arm 節點。

下列資訊清單範例使用智慧預設值,要求 Autopilot 容器最佳化 Arm 節點:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-arm
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-arm
  template:
    metadata:
      labels:
        app: nginx-arm
    spec:
      terminationGracePeriodSeconds: 25
      containers:
      - name: nginx-arm
        image: nginx
        resources:
          requests:
            cpu: 2000m
            memory: 2Gi
            ephemeral-storage: 1Gi
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/arch
                operator: In
                values:
                - arm64

如要要求特定硬體,而非 Autopilot 容器最佳化節點,請將 kubernetes.io/arch 替換為特定機器家族親和性規則或要求類別,例如 Performance 或 Scale-Out。

建議

  • 建構及使用多架構映像檔,做為管道的一部分。多架構映像檔可確保 Pod 即使放置在 x86 節點上,也能正常運作。
  • 在工作負載資訊清單中明確要求架構和運算類別。否則,Autopilot 會使用所選運算級別的預設架構,這可能不是 Arm。

可用性

您可以在下列區域的 Arm 架構上部署 Autopilot 工作負載:us-east1、us-west1、europe-west1、europe-west2、europe-west4、asia-southeast1 和 us-central1。

疑難排解

如需常見錯誤和疑難排解資訊,請參閱「排解 Arm 工作負載問題」。

後續步驟