本文档介绍了如何查看代管式实例组 (MIG) 中的实例灵活性配置以及组中每个虚拟机使用的机器类型。
在 MIG 中添加或更改实例灵活性后,您可以执行以下操作:
查看实例灵活性配置,以验证是否已应用配置,或检查 MIG 是否已具有实例灵活性。
查看每个虚拟机使用的机器类型,确保您要从实例选择中移除的机器类型未被任何虚拟机使用,或检查 MIG 中使用的不同机器类型。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以通过选择以下选项之一向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
在 Google Cloud 控制台中,转到实例群组页面。
在名称列中,点击要查看实例灵活性配置的 MIG 的名称。
系统会打开此 MIG 的概览页面。
点击详情标签页。
在实例灵活性部分中,实例选择表会显示实例选择名称、排名以及选择中的机器类型。如果 MIG 未配置实例灵活性,系统不会显示实例灵活性部分。
INSTANCE_GROUP_NAME
:您要查看实例灵活性配置的 MIG 的名称。REGION
:MIG 所在的区域。PROJECT_ID
:您的项目 ID。REGION
:MIG 所在的区域。INSTANCE_GROUP_NAME
:您要查看实例灵活性配置的 MIG 的名称。在 Google Cloud 控制台中,转到实例群组页面。
在名称列中,点击您要查看其中每个虚拟机所用机器类型的 MIG 的名称。
系统会打开 MIG 的概览页面,其中列出了该组中的所有虚拟机、其机器类型和其他详细信息。
REGION
:MIG 所在的区域。INSTANCE_GROUP_NAME
:您要查看实例灵活性配置的 MIG 的名称。PROJECT_ID
:您的项目 ID。REGION
:MIG 所在的区域。INSTANCE_GROUP_NAME
:您要查看实例灵活性配置的 MIG 的名称。如果您的 MIG 不支持实例灵活性,请添加实例灵活性。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
查看实例灵活性配置
控制台
gcloud
如需查看实例灵活性配置,请使用
instance-groups managed describe
命令。添加--format
标志以过滤instanceFlexibilityPolicy.instanceSelections
属性。gcloud compute instance-groups managed describe INSTANCE_GROUP_NAME \ --region REGION \ --format="json(instanceFlexibilityPolicy.instanceSelections)"
以下是输出示例:
{ "instanceFlexibilityPolicy": { "instanceSelections": { "instance-selection-1": { "machineTypes": [ "n1-standard-16", "n2-standard-16", "e2-standard-16" ], "rank": 1 } } } }
如果 MIG 未配置实例灵活性,则输出会返回
null
。替换以下内容:
REST
如需查看实例灵活性配置,请使用
regionInstanceGroupManagers.get
方法。在请求网址中添加fields
参数以过滤instanceFlexibilityPolicy.instanceSelections
媒体资源。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME?fields=instanceFlexibilityPolicy.instanceSelections
以下是输出示例:
{ "instanceFlexibilityPolicy": { "instanceSelections": { "instance-selection-1": { "machineTypes": [ "n1-standard-16", "n2-standard-16", "e2-standard-16" ], "rank": 1 } } } }
如果 MIG 未配置实例灵活性,则输出会返回
null
。替换以下内容:
查看每个虚拟机使用的机器类型
控制台
gcloud
如需查看 MIG 中每个虚拟机使用的机器类型,请使用
instance-groups managed list-instances
命令列出虚拟机,并添加--format
标志以过滤propertiesFromFlexibilityPolicy.machineType
字段。您还可以根据需要过滤其他字段。gcloud compute instance-groups managed list-instances INSTANCE_GROUP_NAME \ --region REGION \ --format='(name,instanceStatus,currentAction,propertiesFromFlexibilityPolicy.machineType,lastAttempt.errors.errors)'
以下是输出示例:
NAME: example-mig-0md2 STATUS: RUNNING ACTION: NONE MACHINE_TYPE: n1-standard-16 LAST_ERROR: NAME: example-mig-vbgg STATUS: RUNNING ACTION: NONE MACHINE_TYPE: n1-standard-16 LAST_ERROR:
替换以下内容:
REST
如需查看 MIG 中每个虚拟机使用的机器类型,请使用
listManagedInstances
方法列出虚拟机,然后检查响应中的propertiesFromFlexibilityPolicy.machineType
字段。POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/listManagedInstances
以下是输出示例;查找用于设置虚拟机的
machineType
字段的propertiesFromFlexibilityPolicy
字段。{ "managedInstances": [ { "instance": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-b/instances/example-mig-0md2", "instanceStatus": "RUNNING", "id": "2656095434923471959", "version": { "instanceTemplate": "https://www.googleapis.com/compute/v1/projects/example-project/global/instanceTemplates/example-instance-template" }, "targetStatus": "RUNNING", "name": "example-mig-0md2", "propertiesFromFlexibilityPolicy": { "machineType": "n1-standard-16" } }, { "instance": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-b/instances/example-mig-vbgg", "instanceStatus": "RUNNING", "currentAction": "NONE", "id": "9171259522409694366", "version": { "instanceTemplate": "https://www.googleapis.com/compute/v1/projects/example-project/global/instanceTemplates/example-instance-template" }, "targetStatus": "RUNNING", "name": "example-mig-vbgg", "propertiesFromFlexibilityPolicy": { "machineType": "n1-standard-16" } } ] }
替换以下内容:
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-09。
-