本頁說明如何測試 Compute Engine 執行個體的主機維護政策對應用程式的影響。
您可以模擬 VM 的維護事件,測試下列項目:
- 即時遷移對應用程式的影響。
- 使用一或多個 Spot VM 時,應用程式和批次作業如何處理先占和關閉作業。
- 應用程式如何處理執行個體的關機和重新啟動程序。這些執行個體已設定在維護事件期間終止並重新啟動,而不是即時遷移。
- 瞭解在單一租戶節點上執行的工作負載在主機維護事件期間的行為,並查看單一租戶 VM 的主機維護政策對 VM 上執行的應用程式有何影響。
如果嘗試在不支援即時遷移的執行個體上模擬主機維護事件,系統會根據設定的主機維護政策終止或重新啟動執行個體。
事前準備
- 請參閱
SimulateMaintenanceEventRequestsPerMinutePerProjectPerRegion
的區域 API 使用頻率限制。 -
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
限制
- 如要在主機維護政策設為「在節點群組中遷移」的單一租戶節點群組上,正確模擬維護事件,您必須依序在每個節點上觸發維護事件。
- 如果是單一租戶節點群組,當您嘗試模擬主機維護事件,且節點群組的主機維護政策設為在節點群組內遷移時:
- 如果指定的節點數量小於或等於預留的保留節點總數,主機維護事件模擬就會同時針對所有指定節點執行。
- 如果指定的節點數量大於保留的暫緩節點總數,模擬就會失敗。
- 每個區域每分鐘可啟動的維護事件模擬次數,會受到
simulate_maintenance_event_requests_per_region
指標的 API 頻率限制。
模擬主機維護事件,測試即時遷移
您可以透過 Google Cloud CLI 或 API 要求,模擬運算執行個體的維護事件。這項模擬活動包含一般維護作業中會進行的各種維護活動。這樣一來,您就能觀察端對端程序,並測試可能已導入的任何自動化功能。
模擬使用即時遷移的執行個體主機維護事件時,執行個體的
maintenance-event
中繼資料鍵會經歷下列變更:- 在模擬開始時,
maintenance-event
中繼資料鍵的值會從NONE
變更為MIGRATE_ON_HOST_MAINTENANCE
。 - 在模擬事件期間,值會保持為
MIGRATE_ON_HOST_MAINTENANCE
。 - 模擬結束後,值會恢復為
NONE
。
如要查詢維護事件鍵,請參閱「查詢維護事件中繼資料鍵」。
gcloud
使用
compute instances simulate-maintenance-event
指令模擬執行個體的維護事件,並測試所設定的主機維護政策設定:gcloud compute instances simulate-maintenance-event INSTANCE_NAME \ --zone=ZONE --with-extended-notifications=True
更改下列內容:
INSTANCE_NAME
:您要模擬維護事件的運算執行個體名稱。您可以指定多個執行個體名稱 (以單一空格分隔),在位於相同區域的多個執行個體上模擬維護作業。例如
instance-1 instance-2 instance-3
。ZONE
:執行個體所在的區域。
REST
建構對
compute.instances.simulateMaintenanceEvent
方法的POST
要求:POST https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/simulateMaintenanceEvent
更改下列內容:
PROJECT_ID
:這項要求的專案 ID。INSTANCE_NAME
:要模擬維護事件的執行個體名稱。ZONE
:執行個體所在的區域。
模擬終止的 Compute 執行個體主機維護作業
您可以透過 Google Cloud CLI 或 API 要求,模擬運算執行個體的維護事件。這項模擬活動包含一般維護作業中會進行的各種維護活動。這樣一來,您就能觀察端對端程序,並測試可能已導入的任何自動化功能。
此外,您也可以搭配支援的機器類型使用
--with-extended-notifications
參數,在模擬事件期間手動測試啟動主機維護作業。gcloud
使用
compute instances simulate-maintenance-event
指令模擬執行個體的維護事件,並測試所設定的主機維護政策設定。您可以選擇加入--with-extended-notifications
旗標。gcloud compute instances simulate-maintenance-event INSTANCE_NAME \ --zone=ZONE --with-extended-notifications=True
更改下列內容:
INSTANCE_NAME
:您要模擬維護事件的運算執行個體名稱。您可以指定多個執行個體名稱 (以單一空格分隔),在位於相同區域的多個執行個體上模擬維護作業。例如
instance-1 instance-2 instance-3
。ZONE
:執行個體所在的區域。
選用:如要手動啟動模擬維護事件,請使用
compute instances perform-maintenance
指令。gcloud compute instances perform-maintenance INSTANCE_NAME \ --zone=ZONE
更改下列內容:
INSTANCE_NAME
:您要模擬維護事件的運算執行個體名稱。您可以指定多個執行個體名稱 (以單一空格分隔),在位於相同區域的多個執行個體上模擬維護作業。例如
instance-1 instance-2 instance-3
。ZONE
:執行個體所在的區域。
REST
建構對
compute.instances.simulateMaintenanceEvent
方法的POST
要求。您可以選擇加入查詢參數withExtendedNotifications
。POST https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/simulateMaintenanceEvent?withExtendedNotifications=True
更改下列內容:
PROJECT_ID
:這項要求的專案 ID。INSTANCE_NAME
:要模擬維護事件的執行個體名稱。ZONE
:執行個體所在的區域。
選用:如要手動啟動模擬維護事件,請向
compute.instances.performMaintenance
方法建構POST
要求。POST https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/performMaintenance
更改下列內容:
INSTANCE_NAME
:要啟動維護事件的運算執行個體名稱。您可以指定多個執行個體名稱 (以單一空格分隔),在位於相同區域的多個執行個體上執行維護作業。例如
instance-1 instance-2 instance-3
。ZONE
:執行個體所在的區域。
在單一用戶群節點上模擬主機維護事件
您可以透過 Google Cloud CLI 或 API 要求,在單一租戶節點上模擬主機維護事件。在單一租戶 VM 上模擬主機維護事件時,
maintenance-event
中繼資料鍵值不會變更,在整個模擬過程中都會維持NONE
。gcloud
執行
sole-tenancy node-groups simulate-maintenance-event
指令,強制單一租戶節點啟用所設定的維護政策:gcloud compute sole-tenancy node-groups simulate-maintenance-event NODE_GROUP \ --nodes=NODE_NAMES \ --zone=ZONE \ --async
更改下列內容:
NODE_GROUP
:要模擬維護事件的節點群組名稱。NODE_NAMES
:要模擬維護事件的節點名稱。指定多個節點名稱時,請使用以半形逗號分隔的值,例如node-1,node-2,node-3
。ZONE
:節點所在的可用區。
REST
建構對
compute.nodeGroups.simulateMaintenanceEvent
方法的POST
要求:POST https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/zones/ZONE/nodeGroups/NODE_GROUP/simulateMaintenanceEvent { "nodes": [ "NODE_NAMES" ] }
更改下列內容:
PROJECT_ID
:這項要求的專案 ID。ZONE
:節點所在的可用區。NODE_GROUP
:要模擬維護事件的節點群組名稱。NODE_NAMES
:要模擬維護作業的節點名稱。以雙引號括住節點名稱,例如"node-1"
。指定多個節點名稱時,請使用以半形逗號分隔的值,例如"node-1","node-2","node-3"
。
後續步驟
- 進一步瞭解如何主辦活動。
- 進一步瞭解單一用戶群節點上的主機維護作業。
- 進一步瞭解如何設定 VM 主機維護政策選項。
- 瞭解如何查看 VM 作業。
- 進一步瞭解多用戶群和單一用戶群。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-08 (世界標準時間)。"],[[["This page details how to simulate host maintenance events on Compute Engine instances to test the impact of different host maintenance policies on applications, including live migration, preemption, and shutdown behaviors."],["You can simulate maintenance events for both regular compute instances and sole-tenant nodes, observing how applications handle migration, termination, or restart processes during such events."],["The simulation process for standard compute instances will alter the `maintenance-event` metadata key, switching its value during the event, whereas with sole-tenant VMs, the value will remain unchanged at `NONE`."],["Simulating maintenance events can be done through the Google Cloud CLI or REST API, offering options to test various scenarios such as live migration, termination, or manual intervention in maintenance procedures."],["For sole-tenant node groups there are specific limitations to consider, such as the number of nodes that can have simultaneous maintenance events and the fact that the maintenance event needs to be sequentially triggered."]]],[]] -