在 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 可能不支持运行本文档中的命令。
  • 查看 Arm 节点的要求和限制
  • 如需使用 autopilot-arm ComputeClass,请确保您的集群运行的是 GKE 1.35.3-gke.1389000 版或更高版本。
  • 确保您拥有 C4AN4ATau T2A Compute Engine 机器类型的配额。
  • 确保您有一个容器映像专为 Arm 架构而构建的 Pod。

如何在 Autopilot 中请求 Arm 节点

如需指示 Autopilot 在 Arm 节点上运行 Pod,请根据您的要求使用以下方法之一。您可以使用 nodeSelector节点亲和性规则指定这些标签:

  • 对于通用工作负载:通过指定以下两项来请求容器优化的 Arm 平台:
    • cloud.google.com/compute-class: autopilot-arm
    • kubernetes.io/arch: arm64
  • 对于有特定硬件要求的工作负载:请指定以下值之一:

    • kubernetes.io/arch: arm64。对于运行 1.31.3-gke.1056000 及更高版本的集群,GKE 会默认将 Pod 放置在 C4A 机器类型上。如果集群运行的是更早的版本,GKE 会将 Pod 放置在 T2A 机器类型上。

    • 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:
        cloud.google.com/compute-class: autopilot-arm
        kubernetes.io/arch: arm64
      containers:
      - name: nginx-arm
        image: nginx
        resources:
          requests:
            cpu: 2000m
            memory: 2Gi

如需请求特定硬件,而不是 Autopilot 容器优化节点,请将 nodeSelector 中的 autopilot-arm 替换为 PerformanceScale-Out

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: cloud.google.com/compute-class
                operator: In
                values:
                - autopilot-arm
              - key: kubernetes.io/arch
                operator: In
                values:
                - arm64

如需请求特定硬件,而不是 Autopilot 容器优化节点,请将 nodeAffinity 规则中的 autopilot-arm 替换为 PerformanceScale-Out

建议

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

可用性

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

问题排查

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

后续步骤