在 Arm 架构上部署 Autopilot 工作负载

本页面了介绍如何配置 Google Kubernetes Engine (GKE) Autopilot 部署以请求由 Arm 架构支持的节点。

关于 Autopilot 中的 Arm 架构

Autopilot 集群为具有特定硬件要求的工作负载提供计算类。其中一些计算类支持多个 CPU 架构,例如 amd64arm64

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 版或更高版本。
  • 确保您拥有 C4AN4ATau T2A Compute Engine 机器类型的配额。
  • 确保您有一个容器映像专为 Arm 架构而构建的 Pod。

如何在 Autopilot 中请求 Arm 节点

如需指示 Autopilot 在 Arm 节点上运行 Pod,请使用 nodeSelector节点亲和性规则指定以下选择器之一(具体取决于您的 GKE 类型和版本):

  • 在 Autopilot 集群中(智能默认):仅指定架构类型:

    • kubernetes.io/arch: arm64

    如果工作负载在 Autopilot 集群上运行,则此设置会选择通用 Arm 平台。

  • 在 Autopilot 集群或使用 Autopilot ComputeClass(仅限 ComputeClass)的标准集群中:指定 ComputeClass:

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

    选择此类别会在经过容器优化的 Arm 平台(或其 Spot 虚拟机变体)上调度工作负载,并在准入期间自动向 Pod 添加所需的 kubernetes.io/arch: arm64 选择器。

  • 显式选择(旧版 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 机器系列,例如 C4AN4AT2A。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(或 autopilot-arm-spot,如果是 Spot 虚拟机)ComputeClass 来请求经过容器优化的 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 替换为特定机器家族亲和性规则或请求类(例如 PerformanceScale-Out)。

建议

  • 作为流水线的一部分,构建并使用多架构映像。多架构映像可确保即使 Pod 放置在 x86 节点上也会运行。
  • 在工作负载清单中明确请求架构和计算类。如果没有指定,Autopilot 将使用所选计算类的默认架构,这可能不是 Arm。

可用性

您可以在以下区域中,在 Arm 架构上部署 Autopilot 工作负载:us-east1us-west1europe-west1europe-west2europe-west4asia-southeast1us-central1

问题排查

如需了解常见错误和问题排查信息,请参阅排查 Arm 工作负载问题

后续步骤