本文說明如何設定 MIG,以便在修復作業期間重新建立 VM 時,套用最新的執行個體範本和個別執行個體設定。在維修作業期間套用最新可用設定,也稱為「維修時更新」。本文也說明如何檢查 MIG 是否已啟用修復時更新功能,以及如何停用這項功能。
根據預設,MIG 會在修復期間使用當初建立 VM 時的執行個體設定,重新建立 VM。如果群組的執行個體範本或每個執行個體的設定有更新,您可以選擇將這些變更套用至正在修復的 VM。
如要自動將設定更新套用至所有或一組 VM (PROACTIVE
),或選擇性更新特定執行個體 (OPPORTUNISTIC
),請參閱「將新的設定套用至 MIG 中的 VM」一文。
事前準備
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 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
-
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.
- Set a default region and zone.
前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要設定修復後更新的 MIG 名稱。
按一下「編輯」修改 MIG。
在「VM instance lifecycle」(VM 執行個體生命週期) 區段中,針對「Updates during VM instance repair」(VM 執行個體修復期間的更新設定),選取「Update the instance configuration」(更新執行個體設定)。
按一下 [儲存]。
MIG_NAME
:執行個體群組的名稱。INSTANCE_TEMPLATE_URL
:您要用來在 MIG 中建立 VM 的執行個體範本網址。網址可以包含執行個體範本的ID 或名稱。指定下列其中一個值:- 如果是區域執行個體範本:
projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
- 全域執行個體範本:
INSTANCE_TEMPLATE_ID
- 如果是區域執行個體範本:
SIZE
:執行個體群組的目標大小。前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要檢查設定的 MIG 名稱。
按一下「詳細資料」分頁標籤。
在「VM 執行個體生命週期」部分,查看為「VM 執行個體修復期間的更新設定」選取的選項。如果選取「更新執行個體設定」,系統會啟用「在修復時更新」。
NO
:預設值。MIG 不會在 VM 修復時更新 VM。YES
:MIG 會在 VM 修復期間更新 VM。NO
:預設值。MIG 不會在 VM 修復時更新 VM。YES
:MIG 會在 VM 修復期間更新 VM。PROJECT_ID
:您的專案 ID。ZONE
:MIG 所在的可用區。MIG_NAME
:執行個體群組的名稱。前往 Google Cloud 控制台的「Instance groups」(執行個體群組) 頁面。
按一下要停用維修更新的 MIG 名稱。
按一下「編輯」修改 MIG。
在「VM instance lifecycle」(VM 執行個體生命週期) 區段中,針對「Updates during VM instance repair」(VM 執行個體修復期間的更新設定),選取「Keep the same instance configuration」(保留相同的執行個體設定)。
按一下 [儲存]。
PROJECT_ID
:您的專案 ID。ZONE
:MIG 所在的可用區。MIG_NAME
:執行個體群組的名稱。- 設定應用程式健康狀態檢查和自動修復。
- 如果您已為 MIG 設定以應用程式為準的健康狀態檢查,請監控 VM 健康狀態的變化。
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」。
設定維修更新
如要設定修復時更新,請使用 Google Cloud 控制台、gcloud CLI 或 REST。
主控台
gcloud
如果是現有的 MIG,請使用
update
指令:gcloud compute instance-groups managed update MIG_NAME \ --force-update-on-repair
如果是新的 MIG,請使用
create
指令:gcloud compute instance-groups managed create MIG_NAME \ --template INSTANCE_TEMPLATE_URL_ \ --size SIZE \ --force-update-on-repair
更改下列內容:
REST
如果是現有的區域 MIG,請使用
instanceGroupManagers.patch
方法;如果是現有的地區 MIG,請使用regionInstanceGroupManagers.patch
方法。如要在現有的區域 MIG 中設定修復時更新,請進行下列呼叫:
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME { "instanceLifecyclePolicy": { "forceUpdateOnRepair": YES } }
如果是新的區域 MIG,請使用
instanceGroupManagers.insert
方法;如果是新的區域 MIG,請使用regionInstanceGroupManagers.insert
方法。建立可用區 MIG 時,請進行下列呼叫,設定修復時更新:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers { "name": "MIG_NAME", "instanceTemplate": "INSTANCE_TEMPLATE_URL", "targetSize": SIZE, "instanceLifecyclePolicy": { "forceUpdateOnRepair": YES } }
更改下列內容:
檢查是否已啟用維修更新
根據預設,MIG 不會在修復期間更新 VM。如要檢查 MIG 是否已啟用修復時更新功能,請使用 Google Cloud 控制台、gcloud CLI 或 REST 查看修復時更新設定。
主控台
gcloud
使用
describe
指令,如下所示:gcloud compute instance-groups managed describe MIG_NAME \ --format="(instanceLifecyclePolicy)"
在回應主體中,檢查
forceUpdateOnRepair
欄位,該欄位的值為下列其中之一:以下是輸出範例:
instanceLifecyclePolicy: forceUpdateOnRepair: YES
REST
如果是區域 MIG,請使用
instanceGroupManagers.get
方法;如果是區域 MIG,請使用regionInstanceGroupManagers.get
方法。舉例來說,在區域 MIG 中,請使用下列指令:
GET https://compute.googleapis.com/compute/v1/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME
在回應主體中,檢查
instanceLifecyclePolicy.forceUpdateOnRepair
欄位,該欄位具有下列其中一個值:以下是回應範例:
{ ... "name": "example-mig", "targetSize": 12, ... "instanceLifecyclePolicy": { "forceUpdateOnRepair": "YES" }, ... }
更改下列內容:
停用維修更新
如果希望 MIG 修復 VM 時,使用當初建立 VM 時的原始執行個體範本或個別執行個體設定,就必須停用修復時更新。根據預設,系統會為 MIG 停用維修時更新功能。
使用 Google Cloud 控制台、gcloud CLI 或 REST,停用修復時更新。
主控台
gcloud
使用
update
指令,將--no-force-update-on-repair
旗標設為如下:gcloud compute instance-groups managed update MIG_NAME \ --no-force-update-on-repair
REST
如果是區域 MIG,請使用
instanceGroupManagers.patch
方法;如果是區域 MIG,請使用regionInstanceGroupManagers.patch
方法。舉例來說,如要停用區域 MIG 的修復更新,請使用下列指令:
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME { "instanceLifecyclePolicy": { "forceUpdateOnRepair": NO } }
更改下列內容:
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-09 (世界標準時間)。
-