本文說明如何查看代管執行個體群組 (MIG) 中的執行個體彈性設定,以及群組中每個 VM 使用的機型。
在 MIG 中新增或變更執行個體彈性後,您可以執行下列操作:
查看執行個體彈性設定,確認設定是否已套用,或檢查 MIG 是否已具備執行個體彈性。
查看每個 VM 使用的機器類型,確認要從執行個體選取項目中移除的機器類型未遭任何 VM 使用,或檢查 MIG 中使用的不同機器類型。
事前準備
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS 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
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
查看執行個體彈性設定
控制台
前往 Trusted Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
在「Name」(名稱) 欄中,按一下要查看執行個體彈性設定的 MIG 名稱。
MIG 的總覽頁面隨即開啟。
按一下 [Details] (詳細資料) 分頁標籤。
在「執行個體彈性」部分,「執行個體選取項目」表格會顯示執行個體選取項目名稱、等級,以及選取項目中的機器類型。如果 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 名稱。
查看每個 VM 使用的機器類型
控制台
前往 Trusted Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
在「Name」(名稱) 欄中,按一下要查看各 VM 使用機器類型的 MIG 名稱。
系統會開啟 MIG 的「總覽」頁面,列出群組中的所有 VM、機器類型和其他詳細資料。
gcloud
如要查看 MIG 中每個 VM 使用的機器類型,請使用
instance-groups managed list-instances
指令列出 VM,並加入--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 中每個 VM 使用的機器類型,請使用
listManagedInstances
方法列出 VM,然後檢查回應中的propertiesFromFlexibilityPolicy.machineType
欄位。POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/listManagedInstances
以下是輸出範例;請在其中尋找 VM 的
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 沒有執行個體彈性,請新增執行個體彈性。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["This document provides instructions on how to view the instance flexibility configuration of a managed instance group (MIG)."],["You can verify if instance flexibility has been applied to a MIG or if it already has it configured."],["The content explains how to check the machine types used by each virtual machine (VM) within a MIG, ensuring desired machine types are not in use, or to review all the used ones."],["Instructions are available for using the Google Cloud Console, gcloud command-line tool, and REST API to access this information."]]],[]] -