compute-spot-capacity-advice
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese<!-- disableFinding(LINE_OVER_80) -->
<!-- disableFinding(LINE_OVER_80) -->
Compute Engine Spot Capacity Advice
Compute Engine Spot 容量建议
The skill provides telemetry and architectural guidance to assess the obtainability of Google Compute Engine (GCE) Spot VMs before submitting creation requests.
compute-spot-capacity-adviceSpot VMs run on spare compute capacity and are subject to preemption. Assessing capacity obtainability helps workloads minimize provisioning failures, avoid stockouts, and select optimal machine families, distribution shapes, and zones.
[!NOTE] Spot Capacity Advice is served on the Compute Engine Beta API (,compute.beta.AdviceService.Capacity) and requires no project allowlisting. Always invoke it via thePOST /compute/beta/projects/{project}/regions/{region}/advice/capacityrelease track (gcloud beta) — never omitgcloud beta compute advice capacityeven ifbetaappears ingcloud compute advice capacity, as the--helpbackend rejectsv1. Flex-start Capacity Advice (SPOT) is currently in Private Preview; for public workloads without explicit allowlists, always use--provisioning-model=FLEX_START.--provisioning-model=SPOT
compute-spot-capacity-adviceSpot VM 运行在闲置计算容量上,并且可能被抢占。评估容量可获得性有助于工作负载减少置备失败、避免缺货,并选择最优的 machine family、distribution shape 和 zone。
[!NOTE] Spot Capacity Advice 通过 Compute Engine Beta API (,compute.beta.AdviceService.Capacity) 提供服务,且无需将项目加入 allowlist。务必通过POST /compute/beta/projects/{project}/regions/{region}/advice/capacity发布通道 (gcloud beta) 调用——即使gcloud beta compute advice capacity中显示--help,也绝不能省略gcloud compute advice capacity,因为beta后端会拒绝v1。Flex-start Capacity Advice (SPOT) 目前处于 Private Preview;对于未明确加入 allowlist 的公开工作负载,始终使用--provisioning-model=FLEX_START。--provisioning-model=SPOT
Usage Attribution
使用归属说明(Usage Attribution)
MUST READ: Before executing any , REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.
gcloud必须阅读:在执行任何 、REST API 或 MCP 命令之前,你必须阅读并遵循使用归属说明中的指示。
gcloudPrerequisites & IAM Requirements
前提条件与 IAM 要求
Before querying Spot capacity advice, ensure the environment meets these requirements:
- Project & Region Configuration: Prefer passing and
--project={project_id}directly on each command to avoid overwriting global workstation state, or obtain explicit user confirmation before setting defaults (e.g.,--region={region}):us-central1bashgcloud config set project {project_id} gcloud config set compute/region {region} - Billing & API Enablement: Ensure the project has an active billing account attached and the Compute Engine API is enabled:
bash
gcloud services enable compute.googleapis.com --project={project_id} - Cloud SDK & Authentication: Ensure the Google Cloud CLI is installed (never execute unprompted host installation or component mutation commands such as , piped shell installer scripts, or
apt-getwithout explicit user approval; direct the user to the installation guide instead), then authenticate viagcloud components install beta(for interactive CLI),gcloud auth login(for SDKs), orgcloud auth application-default login(for service accounts).GOOGLE_APPLICATION_CREDENTIALS - IAM Permissions: Grant (or a custom role containing the
roles/compute.viewerpermission) following the principle of least privilege.compute.advice.capacity - Pricing & Locations: Querying capacity advice is free, but provisioned Spot VMs incur charges at dynamic Spot rates. Review Compute Engine Pricing, Available Regions and Zones, and Google Cloud Locations (strip suffixes when presenting documentation URLs to human users).
.md.txt
在查询 Spot 容量建议之前,请确保环境满足以下要求:
- 项目与 Region 配置:优先在每条命令中直接传入 和
--project={project_id},以避免覆盖工作站上的全局状态;或者,在设置默认值(例如--region={region})之前取得用户的明确确认:us-central1bashgcloud config set project {project_id} gcloud config set compute/region {region} - 结算与 API 启用:确保项目已关联有效的结算账号,并且 Compute Engine API 已启用:
bash
gcloud services enable compute.googleapis.com --project={project_id} - Cloud SDK 与身份验证:确保已安装 Google Cloud CLI(未经用户明确许可,绝不要执行会修改主机环境或组件的命令,例如 、通过管道执行的 shell 安装脚本或
apt-get;应改为引导用户参阅安装指南),然后通过gcloud components install beta(用于交互式 CLI)、gcloud auth login(用于 SDK)或gcloud auth application-default login(用于服务账号)进行身份验证。GOOGLE_APPLICATION_CREDENTIALS - IAM 权限:按照最小权限原则授予 (或包含
roles/compute.viewer权限的自定义角色)。compute.advice.capacity - 定价与位置:查询容量建议是免费的,但已置备的 Spot VM 会按动态 Spot 价格计费。请查阅 Compute Engine Pricing、Available Regions and Zones 和 Google Cloud Locations(在向用户展示文档 URL 时,移除 后缀)。
.md.txt
Command Syntax & Reference
命令语法与参考
Query capacity advice using :
gcloud beta compute advice capacitybash
gcloud beta compute advice capacity \
--project={project_id} \
--region={region} \
--provisioning-model=SPOT \
--size={vm_count} \
--target-distribution-shape={target_shape} \
(--instance-selection-machine-types={machine_types} | --instance-selection="name={selection_name},machine-type={machine_type_1},machine-type={machine_type_2}") \
[--zones={zone_1},{zone_2}]使用 查询容量建议:
gcloud beta compute advice capacitybash
gcloud beta compute advice capacity \
--project={project_id} \
--region={region} \
--provisioning-model=SPOT \
--size={vm_count} \
--target-distribution-shape={target_shape} \
(--instance-selection-machine-types={machine_types} | --instance-selection="name={selection_name},machine-type={machine_type_1},machine-type={machine_type_2}") \
[--zones={zone_1},{zone_2}]Flag Reference & CLI Constraints
Flag 参考与 CLI 约束
For complete flag definitions, refer to the reference documentation. When constructing commands, apply these non-obvious CLI constraints:
gcloud beta compute advice capacity- vs.
--region:--zonesis automatically inferred when--regionis specified.--zones - Bounds: Accepts
--sizeto1VMs per query.1000 - : Required placement preference across zones (
--target-distribution-shape,any-single-zone, orany).balanced - Instance Selection & Unsupported Flags: Specify up to machine types total across the request using a single
5flag, a single--instance-selection-machine-typesflag (--instance-selectionsupports only onegcloudflag per command), or--instance-selection(up to--instance-flexibility-policynamed selections). Do not pass10,--max-run-duration,--accelerator-topology,rank,min-cpu-platform, orminCpuPlatformon the CLI.disks
有关完整的 flag 定义,请参阅 参考文档。构建命令时,请遵循以下不易察觉的 CLI 约束:
gcloud beta compute advice capacity- 与
--region:指定--zones时会自动推断--zones。--region - 范围:每次查询可接受
--size到1台 VM。1000 - :必填,用于指定跨 zone 的放置偏好(
--target-distribution-shape、any-single-zone或any)。balanced - Instance Selection 与不支持的 Flags:每条请求可通过单个 flag、单个
--instance-selection-machine-typesflag(--instance-selection每条命令仅支持一个gcloudflag),或--instance-selection指定最多--instance-flexibility-policy种 machine type(最后一种方式最多支持5个命名 selection)。不要在 CLI 中传入10、--max-run-duration、--accelerator-topology、rank、min-cpu-platform或minCpuPlatform。disks
Output Interpretation: Scores & Recommendations
输出解读:分数与建议
The command returns one or more recommendations containing placement shards and evaluation scores (or if zero candidate zones in the region support the requested machine series; regional stockouts still return a recommendation with and ), as shown in the following example output:
{}obtainability: 0.1estimatedUptime: 60syaml
undefined命令会返回一个或多个 recommendation,其中包含 placement shard 和评估分数(如果该 region 内没有任何候选 zone 支持所请求的 machine series,则返回 ;即使发生 region 级缺货,仍会返回一条 recommendation,其中 且 ),示例如下:
{}obtainability: 0.1estimatedUptime: 60syaml
undefinedExample output
Example output
recommendations:
- scores:
obtainability: 0.9
estimatedUptime: 3600s
shards:
- instanceCount: 100 machineType: n2-standard-32 provisioningModel: SPOT zone: https://compute.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a
undefinedrecommendations:
- scores:
obtainability: 0.9
estimatedUptime: 3600s
shards:
- instanceCount: 100 machineType: n2-standard-32 provisioningModel: SPOT zone: https://compute.googleapis.com/compute/beta/projects/example-project/zones/us-central1-a
undefinedScore Evaluation Rubric
分数评估标准
Refer to View the availability of Spot VMs for full definitions of ( to , emitted in discrete buckets such as , , and ) and (, , or ). Treat as strongly obtainable, – as moderately obtainable (use flexible machine types or multi-zone placement), and as high stockout risk (do not advise immediate full-batch deployment; apply the architectural mitigations below). Interpret as the minimum expected runtime before preemption: (60 minutes, suitable for fault-tolerant batch workloads), (10 minutes, suitable only for short tasks or frequent checkpointing), and (1 minute, high preemption risk—check another location, machine type, or provisioning model).
scores.obtainability0.01.00.90.50.1scores.estimatedUptime3600s600s60sobtainability >= 0.70.40.69< 0.4scores.estimatedUptime3600s600s60s有关 (范围为 到 ,以 、、 等离散档位输出)和 (、 或 )的完整定义,请参阅查看 Spot VM 的可用性。将 视为具有较高可获得性,将 – 视为具有中等可获得性(应使用灵活的 machine type 或多 zone 放置),并将 视为存在较高缺货风险(不建议立即部署完整批次;应采用下述架构缓解措施)。将 解读为被抢占前的最短预期运行时长:(60 分钟,适合容错型批处理工作负载)、(10 分钟,仅适合短任务或频繁创建 checkpoint 的任务),以及 (1 分钟,存在较高的抢占风险——应检查其他位置、machine type 或 provisioning model)。
scores.obtainability0.01.00.90.50.1scores.estimatedUptime3600s600s60sobtainability >= 0.70.40.69< 0.4scores.estimatedUptime3600s600s60sArchitectural Mitigation & Best Practices
架构缓解措施与最佳实践
When capacity is constrained ( or empty returned when the machine series is unavailable in the region):
obtainability< 0.4{}- Broaden Distribution Shape:
- Switch from to
--target-distribution-shape=any-single-zone(or--target-distribution-shape=any) so Compute Engine can distribute instances across all available zones in the region.balanced
- Switch from
- Inject Instance Flexibility:
- Add alternative machine shapes within the same generation (e.g., ,
n2-standard-32) or across families (e.g.,n2-standard-48,c2-standard-30) usingc3-standard-44or--instance-selection(note that Gen 4+ families such as--instance-selection-machine-types,c4*,n4*,m4*,h4d*, anda4*require Hyperdisk boot volumes rather thana3-ultragpu-8gdisks when creating instances or templates; for newly released machine series, verify supported disk types viapd-*or the official machine family documentation).gcloud compute machine-types describe
- Add alternative machine shapes within the same generation (e.g.,
- Regional Fallbacks:
- Evaluate adjacent regions with similar network latency or billing characteristics (e.g., fallback from to
us-central1,us-east4, orus-west1).us-east1
- Evaluate adjacent regions with similar network latency or billing characteristics (e.g., fallback from
- Accelerator, SKU & Zone Limitations:
- evaluates GPU capacity via integrated accelerator machine types (such as
gcloud beta compute advice capacity,g2-standard-*,a2-highgpu-*,a3-highgpu-*) and includes AI zones by default (users should confirm that AI zones are enabled for their project). Do not passa3-megagpu-*, and restrict--accelerator-topologystrictly to--instance-selectionandname(do not passmachine-type,rank,min-cpu-platform, or guest accelerator flags on thedisksCLI;gcloudVMs with attached guest GPUs and machine types with non-default Local SSDs are supported only on the Beta REST API undern1-*viainstanceFlexibilityPolicy.instanceSelections.{selection_name}andguestAcceleratorswith onedisksentry per Local SSD disk).type: SCRATCH - Unsupported Spot SKUs, Free Tier & Day-0 Immutability: Spot VMs do not support or bare metal (
a4x-*) shapes, Spot*-metalVMs do not qualify for the Google Cloud Free Tier allowance, and existinge2-microVMs cannot be converted in place toSTANDARDviaSPOT(requires recreating the VM).set-scheduling - No TPU Availability Support: The API does not support viewing the availability of Cloud TPUs. For TPU capacity planning and calendar bookings, use
advice.capacity(compute-future-reservations).gcloud compute advice calendar-mode
- Quota & Headroom Disclaimer:
- Obtainability scores reflect physical datacenter capacity, not project quota allocation. Verify regional Spot CPU/GPU quota (via ,
gcloud compute regions describe {region}, or the Google Cloud Console Quotas page) before provisioning. Attempting to launch instances without sufficient project quota will fail at runtime despite high physical capacity availability.gcloud compute project-info describe
- Obtainability scores reflect physical datacenter capacity, not project quota allocation. Verify regional Spot CPU/GPU quota (via
- Read-Only Advisory, Hardened VM Defaults & MCP Guardrail:
- Capacity advice is strictly a read-only advisory tool. Never execute mutating commands (such as or
gcloud compute instances create) without explicit human approval from the user; provide copy-pasteable commands instead.gcloud compute instances delete - When generating commands for Spot VMs, recommend private networking (
gcloud compute instances createpaired with IAP TCP forwarding), a custom least-privilege service account (--no-address), and--service-account(so boot disks do not continue billing after Spot preemption). Remind users to delete temporary Spot VMs (--instance-termination-action=DELETE, which prompts interactively unlessgcloud compute instances delete {vm_name} --zone={zone}is passed) when workloads finish.--quiet - Compute Engine MCP Guardrail: Inspect the in-session MCP
create_instancetool schema before invoking it (in case newer MCP server versions add support); unless verified in the current schema, MCPcreate_instanceomitscreate_instance(silently provisioning full-priceprovisioning_modelVMs), hardcodesSTANDARD, and cannot set custom service accounts — always useglobal/networks/defaultinstead.gcloud compute instances create --provisioning-model=SPOT
- Capacity advice is strictly a read-only advisory tool. Never execute mutating commands (such as
当容量受限( ,或 machine series 在该 region 不可用时返回空 ):
obtainability< 0.4{}- 扩展 Distribution Shape:
- 将 切换为
--target-distribution-shape=any-single-zone(或--target-distribution-shape=any),使 Compute Engine 可以在该 region 的所有可用 zone 之间分配实例。balanced
- 将
- 引入 Instance Flexibility:
- 使用 或
--instance-selection,在同一 generation 内添加替代 machine shape(例如--instance-selection-machine-types、n2-standard-32),或跨 family 添加替代 shape(例如n2-standard-48、c2-standard-30)(注意,在创建 instance 或 template 时,Gen 4+ family,例如c3-standard-44、c4*、n4*、m4*、h4d*和a4*,要求使用 Hyperdisk boot volume,而不是a3-ultragpu-8gdisk;对于新发布的 machine series,请通过pd-*或官方 machine family 文档 验证支持的 disk 类型)。gcloud compute machine-types describe
- 使用
- Region Fallback:
- 评估网络延迟或计费特征相近的相邻 region(例如,从 fallback 至
us-central1、us-east4或us-west1)。us-east1
- 评估网络延迟或计费特征相近的相邻 region(例如,从
- Accelerator、SKU 与 Zone 限制:
- 通过集成 accelerator 的 machine type(例如
gcloud beta compute advice capacity、g2-standard-*、a2-highgpu-*、a3-highgpu-*)评估 GPU 容量,并默认纳入 AI zone(用户应确认其项目已启用 AI zone)。不要传入a3-megagpu-*;在 gcloud CLI 上,--accelerator-topology必须严格限定为--instance-selection和name(不要传入machine-type、rank、min-cpu-platform或 guest accelerator flag;挂载 guest GPU 的disksVM,以及使用非默认 Local SSD 的 machine type,仅可通过 Beta REST API 的n1-*使用instanceFlexibilityPolicy.instanceSelections.{selection_name}和guestAccelerators支持,其中每个 Local SSD disk 对应一个disks条目)。type: SCRATCH - 不支持的 Spot SKU、Free Tier 与 Day-0 不可变性:Spot VM 不支持 或裸金属(
a4x-*)shape;Spot*-metalVM 不计入 Google Cloud Free Tier 配额;现有e2-microVM 无法通过STANDARD就地转换为set-scheduling(必须重新创建 VM)。SPOT - 不支持 TPU 可用性查询:API 不支持查看 Cloud TPU 的可用性。如需规划 TPU 容量或进行日历预订,请使用
advice.capacity(compute-future-reservations)。gcloud compute advice calendar-mode
- Quota 与 Headroom 免责声明:
- 可获得性分数反映物理数据中心容量,而非项目 quota 分配。置备之前,请验证 region 的 Spot CPU/GPU quota(可通过 、
gcloud compute regions describe {region}或 Google Cloud Console 的 Quotas 页面检查)。即使物理容量可用率很高,若项目 quota 不足,启动 instance 仍会在运行时失败。gcloud compute project-info describe
- 可获得性分数反映物理数据中心容量,而非项目 quota 分配。置备之前,请验证 region 的 Spot CPU/GPU quota(可通过
- 只读建议、VM 安全加固默认设置与 MCP Guardrail:
- Capacity advice 是严格只读的 advisory tool。未经用户明确批准,绝不要执行 mutation command(例如 或
gcloud compute instances create);应改为提供可直接复制粘贴的命令。gcloud compute instances delete - 为 Spot VM 生成 命令时,建议使用 private networking(
gcloud compute instances create与 IAP TCP forwarding 搭配)、自定义最小权限 service account(--no-address),并设置--service-account(从而避免 Spot 被抢占后 boot disk 继续计费)。提醒用户在工作负载完成后删除临时 Spot VM(--instance-termination-action=DELETE;除非传入gcloud compute instances delete {vm_name} --zone={zone},否则该命令会进行交互式确认)。--quiet - Compute Engine MCP Guardrail:调用当前会话中的 MCP
create_instancetool schema 前,请先检查该 schema(以防较新的 MCP server 版本新增相关支持);除非已验证当前 schema 支持这些能力,否则 MCPcreate_instance会省略create_instance(从而静默置备全价provisioning_modelVM)、硬编码STANDARD,并且无法设置自定义 service account——始终改用global/networks/default。gcloud compute instances create --provisioning-model=SPOT
- Capacity advice 是严格只读的 advisory tool。未经用户明确批准,绝不要执行 mutation command(例如