本文档介绍了如何查看托管式实例组 (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
-
安装 Google Cloud CLI,然后使用联合身份登录 gcloud CLI。 登录后,运行以下命令来初始化 Google Cloud CLI:
gcloud init - Set a default region and zone.
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭证。
安装 Google Cloud CLI,然后使用联合身份登录 gcloud CLI。 登录后,运行以下命令来初始化 Google Cloud CLI:
gcloud init如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
-
查看实例灵活性配置
控制台
在 Google Cloud 控制台中,转到实例群组页面。
在名称列中,点击要查看实例灵活性配置的 MIG 的名称。
系统会打开此 MIG 的概览页面。
点击详情标签页。
在实例灵活性部分的实例选择表中,显示了实例选择名称、排名和选择中的机器类型。如果 MIG 未配置实例灵活性,则不会显示实例灵活性部分。
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。
替换以下内容:
INSTANCE_GROUP_NAME:您要查看实例灵活性配置的 MIG 的名称。REGION:MIG 所在的区域。
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。
替换以下内容:
PROJECT_ID:您的项目 ID。REGION:MIG 所在的区域。INSTANCE_GROUP_NAME:您要查看实例灵活性配置的 MIG 的名称。
查看每个虚拟机使用的机器类型
控制台
在 Google Cloud 控制台中,转到实例群组页面。
在名称列中,点击您要查看其中每个虚拟机所用机器类型的 MIG 的名称。
系统会打开 MIG 的概览页面,其中列出了该组中的所有虚拟机、其机器类型和其他详细信息。
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:
替换以下内容:
REGION:MIG 所在的区域。INSTANCE_GROUP_NAME:您要查看实例灵活性配置的 MIG 的名称。
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"
}
}
]
}
替换以下内容:
PROJECT_ID:您的项目 ID。REGION:MIG 所在的区域。INSTANCE_GROUP_NAME:您要查看实例灵活性配置的 MIG 的名称。
后续步骤
如果您的 MIG 没有实例灵活性,请添加实例灵活性。