GKE 中的内置 ComputeClass 简介

本页面介绍了 Google Kubernetes Engine (GKE) 在集群中安装的 ComputeClass。您将了解每个内置 ComputeClass 的名称、可用性和节点配置。本页面适用于希望根据充分的信息来选择可用 ComputeClass 并选择最适合特定工作负载的类的平台工程师和应用运维人员。

您应当已熟悉 ComputeClass

内置 ComputeClass 概览

许多 GKE 工作负载都是通用工作负载,不需要使用专用硬件,例如 Web 服务器或小规模批量作业。对于这些工作负载,优先事项通常是减少与手动管理节点基础设施和自动扩缩配置相关的开销。

GKE 具有各种内置 ComputeClass,可用于各种应用场景,例如在 Standard 集群中运行 Autopilot 工作负载或将容错通用工作负载放置在 Spot 虚拟机上。对于不需要特定硬件(例如 GPU)或特定节点设置(例如 Linux sysctl 标志)的工作负载,请使用内置 ComputeClass。如果您的工作负载需要更专业的硬件,请使用自定义 ComputeClass

GKE 中可用的内置 ComputeClass

下表介绍了 GKE 中可用的内置 ComputeClass:

内置 ComputeClass
autopilot

创建使用 Autopilot 容器优化型计算平台的按需 x86 节点。 此 ComputeClass 是任何 GKE 版本中 Autopilot 集群的默认设置,但在 特定 GKE 版本中可进行明确选择。

这是 Autopilot ComputeClass,这意味着即使在 Standard 集群中,GKE 也会为您管理节点。您可以使用此 ComputeClass 在 Standard 集群中运行 Autopilot 模式工作负载

适用于运行 GKE 1.34.1-gke.1829001 版或更高版本的 Autopilot 集群和 Standard 集群。

autopilot-spot

创建使用 Autopilot 容器优化型计算平台的 Spot 虚拟机。此 ComputeClass 默认应用于 Autopilot 集群中在 Pod 规范中明确选择 Spot 虚拟机的所有 Pod。

这是 Autopilot ComputeClass,这意味着即使在 Standard 集群中,GKE 也会为您管理节点。您可以使用此 ComputeClass 在 Standard 集群中运行 Autopilot 模式工作负载

适用于运行 GKE 1.34.1-gke.1829001 版或更高版本的 Autopilot 集群和 Standard 集群 。

autopilot-arm

创建使用 Autopilot 容器优化型计算平台的按需 Arm 节点。 此平台没有代系,这意味着它不与特定机器家族绑定。这使其与指定 C4A、N4A 或 T2A 等机器系列不同。 建议将 autopilot-arm ComputeClass 用于通用 Arm 工作负载。

适用于运行 GKE 1.35.3-gke.1389000 版或更高版本的 Autopilot 集群。此功能仅在以下区域提供:us-east1us-west1europe-west1europe-west4us-central1

autopilot-arm 计算类仅通过 Autopilot 提供。

如需查看这些内置 ComputeClass 的规范,请使用 kubectl get 命令:

kubectl get computeclass COMPUTECLASS_NAME -o yaml

价格

Autopilot 的计费方式因 Pod 请求的 ComputeClass 而异。如需了解详情,请参阅 Google Kubernetes Engine 价格

工作负载中的内置 ComputeClass 选择

如需在部署 GKE 工作负载时选择内置或自定义 ComputeClass,您可以在工作负载清单中选择 cloud.google.com/compute-class 标签,如以下示例所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloweb
  labels:
    app: hello
spec:
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      nodeSelector:
        # Replace with the name of a compute class
        cloud.google.com/compute-class: COMPUTE_CLASS 
      containers:
      - name: hello-app
        image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: "250m"
            memory: "1Gi"

在此示例中,COMPUTE_CLASS 是计算类的名称。您无法在特定工作负载中选择多个 ComputeClass。

当您部署选择某个 ComputeClass 的工作负载时,GKE 会使用该 ComputeClass 的属性创建新节点来运行 Pod。例如,如果您在工作负载中选择 autopilot 内置 ComputeClass,GKE 会以 Autopilot 模式运行这些 Pod

内置 ComputeClass 的默认应用

您可以将集群中的任何 ComputeClass 设置为特定命名空间或整个集群的 默认 ComputeClass。GKE 会将该 ComputeClass 应用于未明确选择其他 ComputeClass 的任何 Pod。 如需将内置 ComputeClass 设置为默认值,请执行以下操作之一:

  • 如需将 ComputeClass 设置为命名空间默认值,请向命名空间添加 ComputeClass 的标签。
  • 如需将 ComputeClass 设置为集群级默认值,请创建一个名为 default 的新 ComputeClass,该 ComputeClass 具有与内置 ComputeClass 相同的优先级规则。

如需详细了解如何将 ComputeClass 设置为 命名空间或集群的默认值,请参阅 默认将 ComputeClass 应用于 Pod

例如,假设有一个 Standard 集群在运行许多通用 Pod,例如 Web 服务器或小型批处理作业。如果您将模仿 autopilot 内置 ComputeClass 的 ComputeClass 设置为集群的默认值,则这些通用工作负载会在 Autopilot 容器优化型计算平台上运行,无需更改工作负载规范。需要不同硬件的工作负载可以为特定 ComputeClass 添加选择器。

后续步骤