手動即時遷移 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.
      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」。

API 頻率限制

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

手動即時遷移 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 即時遷移至的節點群組或節點名稱。

後續步驟