Simulate a host maintenance event

Linux Windows

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

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 thesimulate_maintenance_event_requests_per_region metric.

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:

  1. At the start of the simulation, the value of themaintenance-eventmetadata key changes fromNONE toMIGRATE_ON_HOST_MAINTENANCE.
  2. Throughout the duration of the simulation event, the value remains asMIGRATE_ON_HOST_MAINTENANCE.
  3. After the simulation ends, the value returns toNONE.

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

  1. Use thecompute instances simulate-maintenance-event commandto simulate a maintenance event for an instance and test its configuredhost maintenance policy settings. You can optionally include the--with-extended-notifications flag.

    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.

  2. Optional: To manually start the simulated maintenance event, use thecompute instances perform-maintenance command.

    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

  1. Construct aPOST request to thecompute.instances.simulateMaintenanceEvent method. 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.
  2. Optional: To manually start the simulated maintenance event, construct aPOST request to thecompute.instances.performMaintenance method.

    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

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.