查看執行個體彈性


本文說明如何查看代管執行個體群組 (MIG) 中的執行個體彈性設定,以及群組中每個 VM 使用的機型。

在 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

      1. 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.

      2. Set a default region and zone.
      3. 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 驗證說明文件中的「Authenticate for using REST」。

查看執行個體彈性設定

控制台

  1. 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。

    前往「Instance groups」(執行個體群組) 頁面

  2. 在「Name」(名稱) 欄中,按一下要查看執行個體彈性設定的 MIG 名稱。

    MIG 的總覽頁面隨即開啟。

  3. 按一下 [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 使用的機器類型

控制台

  1. 前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。

    前往「Instance groups」(執行個體群組) 頁面

  2. 在「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 名稱。

後續步驟