GKE 中的内置 ComputeClass 简介


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

您应当已熟悉 ComputeClasses

内置 ComputeClass 概览

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

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

GKE 中可用的内置 ComputeClass

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

内置 ComputeClasses
autopilot

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

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

适用于注册了快速发布渠道且运行 GKE 1.33.1-gke.1107000 版或更高版本的 Autopilot 集群和 Standard 集群。

autopilot-spot

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

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

适用于注册了快速发布渠道且运行 GKE 1.33.1-gke.1107000 版或更高版本的 Autopilot 集群和 Standard 集群。

价格

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: "4Gi"

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

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

内置 ComputeClass 的默认应用

您可以将集群中的任何 ComputeClass 设置为特定命名空间的默认 ComputeClass。GKE 会将该默认类应用于未明确选择 ComputeClass 的任何 Pod。

例如,假设有一个标准集群在 serving 命名空间中运行许多通用 Web 服务器 Pod。如果您将 autopilot 内置 ComputeClass 设置为命名空间的默认值,则您的 Web 服务器 Pod 默认在 Autopilot 容器优化计算平台上运行,无需更改工作负载规范。该命名空间中需要不同硬件的任何工作负载都可以添加其他 ComputeClass 的选择器。

如需详细了解如何在命名空间中将 ComputeClass 设置为默认值,请参阅为命名空间配置默认 ComputeClass

后续步骤