查看執行個體彈性


本文說明如何查看代管執行個體群組 (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.

    REST

    To use the REST API samples on this page in a local development environment, you use the credentials you provide to the 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.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

查看執行個體彈性設定

控制台

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

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

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

    MIG 的總覽頁面隨即開啟。

  3. 按一下 [Details] (詳細資料) 分頁標籤。

    在「Instance flexibility」部分,「Instance selections」表格會顯示選取的執行個體名稱、排名和機器類型。如果 MIG 未設定執行個體彈性,系統就不會顯示「Instance flexibility」部分。

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 名稱。

後續步驟