Simulate a host maintenance event Stay organized with collections Save and categorize content based on your preferences.
This page describes how to test the effects of your Compute Engineinstance'shost maintenance policyon your applications.
You might simulate a maintenance event on your VMs to test the following:
- The effects oflive migrationon your applications.
- How your applications and batch jobs handle preemption and shutdownwhen using one or moreSpot VMs.
- How your applications handle the shutdown and restart process for instancesthat are configured toterminate and restartduring maintenance events rather than live migrate.
- How workloads that are running onsole-tenant nodesbehave during a host maintenance event, and see the effects of thesole-tenant VM'shost maintenance policyon the applications running on the VMs.
If you try to simulate a host maintenance event on an instance thatdoesn't support live migration,the instance is either terminated or restarted, depending on the configuredhost maintenance policy.
Before you begin
- Review theregional API rate limitfor
SimulateMaintenanceEventRequestsPerMinutePerProjectPerRegion. - If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- 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.
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Limitations
- To correctly simulate a maintenance event on a sole-tenant node group that hasa host maintenance policy set tomigrate within node group,you need to trigger the maintenance event sequentially on each node.
- For a sole-tenant node group, when you try to simulate a host maintenanceevent and the node group has a host maintenance policy set to migrate withinthe node group:
- If the number of nodes specified is less than or equal to the total numberof holdback nodes that are reserved, then the host maintenance eventsimulation runs for all the specified nodes simultaneously.
- If the number of nodes specified is greater than the total number ofreserved holdback nodes, then the simulation fails.
- The number of maintenance event simulations you can start per minute perregion is limited by theAPI rate limit for the
simulate_maintenance_event_requests_per_regionmetric.
Simulate host maintenance events to test live migration
You can simulate a maintenance event for a compute instance by using either theGoogle Cloud CLI or an API request. This simulated event includes thedifferent maintenance activities that occur in a regular maintenance event. Thislets you observe the end-to-end process and test any automation that youmight have implemented.
During the simulation of host maintenance event for an instance that uses livemigration, themaintenance-event metadata key of the instance goes throughthe following changes:
- At the start of the simulation, the value of the
maintenance-eventmetadata key changes fromNONEtoMIGRATE_ON_HOST_MAINTENANCE. - Throughout the duration of the simulation event, the value remains as
MIGRATE_ON_HOST_MAINTENANCE. - After the simulation ends, the value returns to
NONE.
To query the maintenance event key, seeQuery the maintenance event metadata key.
gcloud
Use thecompute instances simulate-maintenance-event commandto simulate a maintenance event for an instance and test its configuredhost maintenance policy settings:
gcloud compute instances simulate-maintenance-eventINSTANCE_NAME \ --zone=ZONE --with-extended-notifications=True
Replace the following:
INSTANCE_NAME: the name of the compute instancewhere you want to simulate the maintenance event.You can specify multiple instance names separated by single spacesto simulate maintenance events on more than one instance in the samezone. For example,
instance-1 instance-2 instance-3.ZONE: the zone where the instance is located.
REST
Construct aPOST request to thecompute.instances.simulateMaintenanceEvent method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/simulateMaintenanceEvent
Replace the following:
PROJECT_ID: the project ID for this request.INSTANCE_NAME: the name of the instance forwhich you want to simulate the maintenance event.ZONE: the zone where the instance is located.
Simulate host maintenance for compute instances that terminate
You can simulate a maintenance event for a compute instance by using either theGoogle Cloud CLI or an API request. This simulated event includes thedifferent maintenance activities that occur in a regular maintenance event. Thislets you observe the end-to-end process and test any automation that youmight have implemented.
Additionally, by using the parameter--with-extended-notifications with asupported machine typeyou can test manually starting host maintenance during the simulated event.
gcloud
Use the
compute instances simulate-maintenance-eventcommandto simulate a maintenance event for an instance and test its configuredhost maintenance policy settings. You can optionally include the--with-extended-notificationsflag.gcloud compute instances simulate-maintenance-eventINSTANCE_NAME \ --zone=ZONE --with-extended-notifications=True
Replace the following:
INSTANCE_NAME: the name of the compute instancewhere you want to simulate the maintenance event.You can specify multiple instance names separated by single spacesto simulate maintenance events on more than one instance in the samezone. For example,
instance-1 instance-2 instance-3.ZONE: the zone where the instance is located.
Optional: To manually start the simulated maintenance event, use the
compute instances perform-maintenancecommand.gcloud compute instances perform-maintenanceINSTANCE_NAME \ --zone=ZONE
Replace the following:
INSTANCE_NAME: the name of the compute instancewhere you want to simulate the maintenance event.You can specify multiple instance names separated by single spacesto simulate maintenance events on more than one instance in the samezone. For example,
instance-1 instance-2 instance-3.ZONE: the zone where the instances arelocated.
REST
Construct a
POSTrequest to thecompute.instances.simulateMaintenanceEventmethod. You can optionally include thequery parameterwithExtendedNotifications.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/simulateMaintenanceEvent?withExtendedNotifications=True
Replace the following:
PROJECT_ID: the project ID for this request.INSTANCE_NAME: the name of the instance forwhich you want to simulate the maintenance event.ZONE: the zone where the instance is located.
Optional: To manually start the simulated maintenance event, construct a
POSTrequest to thecompute.instances.performMaintenancemethod.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/performMaintenance
Replace the following:
INSTANCE_NAME: the name of the computeinstance where you want to start the maintenance event.You can specify multiple instance names separated by single spacesto perform maintenance events on more than one instance in the samezone. For example,
instance-1 instance-2 instance-3.ZONE: the zone where the instances arelocated.
Simulate host maintenance events on sole-tenant nodes
You can simulate a host maintenance event on sole-tenant nodes using either theGoogle Cloud CLI or an API request. During the simulation of the hostmaintenance event on a sole-tenant VM, themaintenance-event metadata keyvalue doesn't change and remainsNONE throughout the simulation.
gcloud
Run thesole-tenancy node-groups simulate-maintenance-event commandto force sole-tenant nodes to activate their configured maintenance policy:
gcloud compute sole-tenancy node-groups simulate-maintenance-eventNODE_GROUP \ --nodes=NODE_NAMES \ --zone=ZONE \ --async
Replace the following:
NODE_GROUP: the name of the node group where youwant to simulate the maintenance event.NODE_NAMES: the names of the nodes where youwant to simulate the maintenance event. While specifying multiple nodenames, use comma-separated values, for example,node-1,node-2,node-3.ZONE: the zone where the nodes are located.
REST
Construct aPOST request to thecompute.nodeGroups.simulateMaintenanceEvent method:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/nodeGroups/NODE_GROUP/simulateMaintenanceEvent{ "nodes": [ "NODE_NAMES" ]}Replace the following:
PROJECT_ID: the project ID for this request.ZONE: the zone where the nodes are located.NODE_GROUP: the name of the node group where youwant to simulate the maintenance event.NODE_NAMES: the names of the nodeswhere you want to simulate the maintenance event. Enclose the node namewithin double quotes, for example,"node-1". And, while specifyingmultiple node names, use comma-separated values, for example,"node-1","node-2","node-3".
What's next
- Learn more abouthost events.
- Learn more abouthost maintenance on sole-tenant nodes.
- Learn more aboutsetting VM host maintenance policy options.
- Learn how toview VM operations.
- Learn more aboutmulti- and sole-tenancy.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.