Setting Instance Availability Policies

When there are system events that might cause your instances to be disrupted, Google Compute Engine automatically manages the scheduling decisions for your instances. For example, if your instance is terminated due to a system or hardware failure, Compute Engine automatically restarts that instance. You can modify this automatic behavior by changing the availability policies for this instance.

Before you begin

Contents

Choosing availability policies

You can set an instance's availability policies for:

  • The instance's maintenance behavior, which determines whether the instance is live migrated or terminated when there is a maintenance event.
  • The instance's restart behavior, which determines whether the instance automatically restarts if it crashes or gets terminated.

The default maintenance behavior for instances is to live migrate, but you can change the behavior to terminate your instance during maintenance events instead.

Live migrate

By default, standard instances are set to live migrate, where Google Compute Engine automatically migrates your instance away from an infrastructure maintenance event, and your instance remains running during the migration. Your instance might experience a short period of decreased performance, although generally most instances should not notice any difference. This is ideal for instances that require constant uptime, and can tolerate a short period of decreased performance.

When Google Compute Engine migrates your instance, it reports a system event that is published to the list of zone operations. You can review this event by performing a gcloud compute operations list --zones ZONE request or by viewing the list of operations in the Google Cloud Platform Console, or through an API request. The event will appear with the following text:

compute.instances.migrateOnHostMaintenance

Terminate and (optionally) restart

If you do not want your instance to live migrate, you can choose to terminate and optionally restart your instance. With this option, Google Compute Engine will signal your instance to shut down, wait for a short period of time for your instance to shut down cleanly, terminate the instance, and restart it away from the maintenance event. This option is ideal for instances that demand constant, maximum performance, and your overall application is built to handle instance failures or reboots.

When Google Compute Engine terminates and reboots your instances, it reports a system event that is published to the list of zone operations. Review this event by performing a gcloud compute operations list --zones ZONE request or by viewing the list of operations in the Google Cloud Platform Console, or through an API request. The event will appear with the following text:

compute.instances.terminateOnHostMaintenance

When your instance reboots, it uses the same persistent boot disk and reattaches any secondary persistent disks that you configured. The data on those disks persists through instance migration and restart.

Local SSD data does not persist through instance termination. When the instance restarts, it creates a new Local SSD that you must format and mount.

Automatic restart

If your instance is set to terminate when there is a maintenance event, or if your instance crashes because of an underlying hardware issue, you can set up Google Compute Engine to automatically restart the instance by setting the automaticRestart field to true. This setting does not apply if the instance is taken offline through a user action, such as calling sudo shutdown.

When Google Compute Engine automatically restarts your instance, it reports a system event that is published to the list of zone operations. You can review this event by performing a gcloud compute operations list --zones ZONE request or by viewing the list of operations in the Google Cloud Platform Console, or through an API request. The event appears with the following text:

compute.instances.automaticRestart

Setting availability policies

Configure an instance's maintenance behavior and automatic restart setting using the onHostMaintenance and automaticRestart properties. All instances are configured with default values unless you explicitly specify otherwise.

  • onHostMaintenance:
    • [Default] migrate, which causes Compute Engine to live migrate an instance when there is a maintenance event.
    • terminate, which terminates an instance instead of migrating it.
  • automaticRestart:
    • [Default] true, so Compute Engine restarts an instance if the instance crashes or is terminated.
    • false, so Compute Engine does not restart an instance if the instance crashes or is terminated.

You can change the availability policies of an instance when you first create an instance or after the instance is created, using the setScheduling method.

Set options during instance creation

Console


  1. In the Cloud Platform Console, go to the VM Instances page.

    Go to the VM Instances page

  2. Click the Create instance button.
  3. On the Create a new instance page, fill in the desired properties for your instance.
  4. Expand the Management, disk, networking, SSH keys option.
  5. Under the Management tab, scroll to the Availability policy section and set the Automatic restart and On host maintenance options.
  6. Click the Create button to create the instance.

gcloud


To specify the availability policies of a new instance in gcloud compute, use the --maintenance-policy flag to specify whether the instance is migrated or terminated. By default, instances are automatically set to restart unless you provide the --no-restart-on-failure flag.

 gcloud compute instances create INSTANCE .. \
     [--maintenance-policy MAINTENANCE_POLICY] \
     [--no-restart-on-failure]

API


In the API, make a POST request to the following URL, replacing the project and zone with your project ID and the zone of the instance:

 https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances

with the onHostMaintenance and automaticRestart parameters as part of the request body:

{
  "name": "example-instance",
  "description": "Front-end for real-time ingest; don't migrate.",
...
  // User options for influencing this Instance’s life cycle.
  "scheduling": {
    "onHostMaintenance": "migrate",
    "automaticRestart": "true" # specifies that Google Compute Engine should automatically restart your instance
  }
}

For more information, see the Instances reference documentation.

Update options for an instance

Console


  1. Go to the VM Instances page.
  2. Click the instance for which you want to change settings.
  3. Under Availability policies, click the Edit button to change the availability policies.

gcloud


To update the availability policies of an instance, use the instances set-scheduling subcommmand command with the same parameters and flags used in the instance creation command above:

gcloud compute instances set-scheduling INSTANCE \
    [--maintenance-policy BEHAVIOR] \
    [--no-restart-on-failure | --restart-on-failure]

API


In the API, you can make a request to the following URL, replacing the project and zone with your own project ID and the zone of the instance:

https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-f/instances/setScheduling

The body of your request must contain the new value for the availability policies:

{
  "onHostMaintenance": "migrate"
  "automaticRestart": "true" # specifies that Google Compute Engine should automatically restart your instance
}

For more information, see the instances().setScheduling reference documentation.

Availability policies for preemptible instances

You cannot configure a preemptible instances to live migrate. The maintenance behavior for preemptible instances is always set to TERMINATE by default, and you cannot change this option. It is also not possible to set the automatic restart option for preemptible instances.

Send feedback about...

Compute Engine Documentation