手動即時遷移 VM


如要將單一用戶群 VM 移至其他節點或節點群組,您可以手動啟動即時遷移。您也可以手動啟動即時遷移,將多租戶 VM 遷移至單一租戶。如要瞭解如何將 VM 移出單一用戶群,請參閱「將 VM 移出單一用戶群」。

事前準備

  • 如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    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.

API 頻率限制

手動即時遷移要求會歸類為「查詢」API 頻率限制

手動即時遷移單一用戶群 VM 或在單一用戶群內部遷移 VM

如要手動將 VM 即時遷移至單一用戶群或單一用戶群內,請使用 gcloud CLI 或 REST。

如果 VM 的目的地位於節點群組中,Compute Engine 會選取群組中具有足夠 VM 空間和最少備用容量的節點。

使用共用單一用戶群節點群組時,無法在專案之間執行即時遷移。

這項工作需要的權限

如要執行這項工作,您必須具備以下權限

  • VM 上的 compute.instances.update 權限。

gcloud

如要手動將 VM 即時遷移至單一租戶環境或其中,請使用下列 gcloud compute instances update 指令

gcloud compute instances update VM_NAME \
    ( --node=NODE \
      --node-group=NODE_GROUP \
      --node-affinity-file=NODE_AFFINITY_FILE )

更改下列內容:

  • VM_NAME:要更新節點相依性標籤的 VM 名稱。

請更換下列任一項目:

  • NODE:要將 VM 即時遷移至的節點名稱。

  • NODE_GROUP:要將 VM 即時遷移至其中的節點群組名稱。

  • NODE_AFFINITY_FILE:JSON 檔案名稱,其中包含可排定此 VM 的節點設定。詳情請參閱「設定節點相依性標籤」。

REST

如要手動將 VM 即時遷移至單一用戶群或單一用戶群內,請使用下列 instances.update 方法

PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME

{
  ...
  "scheduling": {
    "nodeAffinities": [
      {
        "key": "NODE_AFFINITY_LABEL_KEY",
        "operator": "IN",
        "values": [
          "[NODE_AFFINITY_LABEL_VALUE]"
        ]
      }
    ]
  }
  ...
}

更改下列內容:

  • PROJECT_ID:含有 VM 的專案 ID,用於更新節點相依性標籤。

  • ZONE:要更新節點相依性標籤的 VM 區域。

  • VM_NAME:要更新節點相依性標籤的 VM 名稱。

  • NODE_AFFINITY_LABEL_KEY:下列字串之一,用來指定是否要將 VM 即時遷移至節點群組或節點:

    VM 目的地 要指定的鍵
    節點群組 compute.googleapis.com/node-group-name
    節點 compute.googleapis.com/node-name
  • NODE_AFFINITY_LABEL_VALUE:要將 VM 即時遷移至其中的節點群組或節點名稱。

後續步驟