关于 gke-batch-hpc
这是一项介绍如何在 GKE 上运行批处理和高性能计算工作负载的参考技能,涵盖作业编排、MPI、调度、扩缩容与容错实践,适用于数据处理、模拟和训练任务。
主要功能
- 01配置 Kubernetes Jobs 和 JobSet
- 02使用 Kueue 排队工作负载
- 03运行 MPI 工作负载
- 04为 HPC 使用紧凑型放置
- 05优化扩缩容和 Spot 使用
适用场景
- 01在 GKE 上运行批处理数据流水线
- 02编排 MPI 模拟任务
- 03调度分布式训练作业
- 04运行 CI/CD 构建集群
MCP 相关
它列出用于应用 Kubernetes 清单、检查资源和日志、删除资源以及列出事件的 MCP 工具。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ google/ skills --skill gke-batch-hpc安装后在 Claude Code 中输入/gke-batch-hpc确认已加载。
附带文件references/attribution.md
详细介绍
GKE 批处理与 HPC 工作负载
本参考介绍如何在 GKE 上运行批处理和高性能计算(HPC)工作负载。
MCP 工具:
apply_k8s_manifest、get_k8s_resource、describe_k8s_resource、get_k8s_logs、delete_k8s_resource、list_k8s_events
归属信息
必须阅读:在执行任何 gcloud、REST API 或 MCP 命令之前,你必须阅读 使用归属信息。对于直接在终端中执行的命令(绝不在生成的脚本、Terraform 或用户代码中执行),请在 gcloud 前添加
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:gke-batch-hpc)"
,并在 User-Agent 请求头中追加 agent-skills/1.0 (skill:gke-batch-hpc)。
适用场景
- 运行批处理数据处理管道
- HPC 仿真(CFD、分子动力学、金融建模)
- 大规模并行计算(MPI、MapReduce)
- ML 训练作业
- CI/CD 构建集群
在 GKE 上进行批处理
Kubernetes Job
apiVersion: batch/v1
kind: Job
metadata:
name: batch-job
spec:
parallelism: 10
completions: 100
backoffLimit: 3
template:
spec:
containers:
- name: worker
image: <IMAGE>
resources:
requests:
cpu: "1"
memory: "2Gi"
restartPolicy: Never
JobSet(用于复杂的多作业工作流)
黄金路径启用 JobSet 监控(在 monitoringConfig 中设置 JOBSET)。
apiVersion: jobset.x-k8s.io/v1alpha2
kind: JobSet
metadata:
name: training-job
spec:
replicatedJobs:
- name: workers
replicas: 4
template:
spec:
parallelism: 1
completions: 1
template:
spec:
containers:
- name: worker
image: <IMAGE>
resources:
requests:
cpu: "4"
memory: "8Gi"
Kueue(作业排队)
Kueue 管理批处理工作负载的作业调度和资源分配:
# Install Kueue
kubectl apply --server-side -f https://github.com/kubernetes-sigs/kueue/releases/latest/download/manifests.yaml
# Define a ClusterQueue
apiVersion: kueue.x-k8s.io/v1beta1
kind: ClusterQueue
metadata:
name: batch-queue
spec:
namespaceSelector: {}
resourceGroups:
- coveredResources: ["cpu", "memory"]
flavors:
- name: default
resources:
- name: "cpu"
nominalQuota: 100
- name: "memory"
nominalQuota: "200Gi"
---
# Allow a namespace to use the queue
apiVersion: kueue.x-k8s.io/v1beta1
kind: LocalQueue
metadata:
name: batch-local
namespace: batch-jobs
spec:
clusterQueue: batch-queue
在 GKE 上运行 HPC
紧凑放置(低延迟网络)
对于需要低延迟节点间通信的紧密耦合 HPC 工作负载:
# Standard clusters: create node pool with compact placement
gcloud container node-pools create hpc-pool \
--cluster <CLUSTER_NAME> --region <REGION> \
--machine-type c3-standard-44 \
--placement-type COMPACT \
--num-nodes 8 \
--enable-autoscaling --min-nodes 0 --max-nodes 16 \
--quiet
MPI 工作负载
使用 MPI Operator 运行基于 MPI 的 HPC 应用:
# Install MPI Operator
kubectl apply -f https://raw.githubusercontent.com/kubeflow/mpi-operator/master/deploy/v2beta1/mpi-operator.yaml
apiVersion: kubeflow.org/v2beta1
kind: MPIJob
metadata:
name: hpc-simulation
spec:
slotsPerWorker: 4
mpiReplicaSpecs:
Launcher:
replicas: 1
template:
spec:
containers:
- name: launcher
image: <MPI_IMAGE>
command: ["mpirun", "-np", "32", "./simulation"]
resources:
requests:
cpu: "1"
memory: "2Gi"
limits:
cpu: "2"
memory: "4Gi"
Worker:
replicas: 8
template:
spec:
containers:
- name: worker
image: <MPI_IMAGE>
resources:
requests:
cpu: "4"
memory: "8Gi"
limits:
cpu: "8"
memory: "16Gi"
批处理/HPC 成本优化
批处理使用 Spot VM
批处理工作负载非常适合使用 Spot VM(可中断,并且可以进行检查点保存)。使用优先选择 Spot 的 ComputeClass,并配置 activeMigration,以便在 Spot 可用时切回 Spot。有关 Spot 回退模式,请参阅 gke-compute-classes 技能。
缩容至零
对于批处理集群,在没有作业运行时允许节点池缩容至零:
- Autopilot(黄金路径):自动执行;没有 Pod 处于调度状态时,节点会缩容至零
- Standard:在批处理节点池上设置
--min-nodes 0
最佳实践与生产指南
- 资源配额:始终为所有批处理/HPC 清单指定资源请求和限制(CPU、 内存,以及可选的 GPU/TPU)。这对于 Kueue 准入、自动扩缩容以及防止 集群资源耗尽至关重要。
- TPU/Spot 集群维护:对于在 Spot VM/TPU 上运行的长时间 AI 训练任务,建议使用 GKE 维护排除项,在训练期间阻止自动集群升级/重启,以尽量减少不必要的抢占。
- MPI 工作负载:使用 Kubeflow Training Operator,通过
MPIJob自定义资源编排分布式 MPI 应用。 - Kueue 与 JobSet:使用 Kueue 实现多租户作业排队和公平共享;使用 JobSet 管理多组件紧密耦合工作负载。
- 弹性:始终为 Job 设置
backoffLimit,并实现应用级检查点机制(例如使用 Orbax 或 PyTorch 检查点),以应对 Spot VM 抢占。