Create a MIG that uses preemptible VMs

This document describes how to create amanaged instance group (MIG)that uses preemptible virtual machine (VM) instances.Preemptible VMs are useful if yourworkload can tolerate disruptions and you want to take advantage of thecost-savings associated with preemptible VMs.

You can also read about otherbasic scenarios for creating a MIG.

Before you begin

Limitations

To see the full list of MIG limitations, which varies based on the configurationthat you use, seeMIG limitations.

Create an instance template with preemptible VMs

You can use a zonal or regional MIG to quickly create multiplepreemptible VMs, which can reducethe costs of the VMs in your managed instance groups. For example, youcan create a group of preemptible VMs, use them to run a batch processingtask, and then delete the group when the task is complete.

To create a group of preemptible VMs, set the preemptible option in aninstance template, and then use the templateto create the MIG.

Permissions required for this task

To perform this task, you must have the followingpermissions:

Console

  1. In the console, go to theInstance templates page.

    Go to Instance templates

    The remaining steps appear in the Google Cloud console.

  2. ClickCreate instance template.
  3. Fill in the properties that you want for your instance template.
  4. ClickAdvanced options and expand theManagement section.
  5. UnderAvailability policy, in theVM provision model list, chooseSpot.
  6. ClickCreate to create the template.

gcloud

Create an instance template by using theinstance-templates create command.Include the--preemptible flag.

gcloud compute instance-templates createINSTANCE_TEMPLATE \    --preemptible

Terraform

The following sample creates a global instance template. To provide thepreemptible option, include thescheduling block.For more information about the resource used in the sample, seegoogle_compute_instance_template resource. To create a regional instancetemplate, use thegoogle_compute_region_instance_template resource.

resource "google_compute_instance_template" "default" {  name         = "preemptible-template"  machine_type = "n1-standard-1"  disk {    source_image = "debian-cloud/debian-11"  }  network_interface {    network = "default"  }  scheduling {    preemptible       = "true"    automatic_restart = "false"  }}

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

REST

Call theinstanceTemplates.insert methodto create a new instance template. Include thescheduling.preemptibleproperty and set it totrue.

{"name": "INSTANCE_TEMPLATE","properties": {  "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",  "networkInterfaces": [    {      "network": "global/networks/default",      "accessConfigs":      [        {          "name": "external-IP",          "type": "ONE_TO_ONE_NAT"        }      ]    }  ],  "scheduling":  {    "preemptible": true  },  "disks":  [    {      "type": "PERSISTENT",      "boot": true,      "mode": "READ_WRITE",      "initializeParams":      {        "sourceImage": "projects/debian-cloud/global/images/family/debian-9"      }    }  ]  }}

After you create the instance template, use it to create a MIGwith VMs confined to a single zoneorwith VMs spread across multiple zones in a region.

What's next

  • Set up application-based autohealing,which periodically verifies that your application responds as expected oneach of the MIG's VMs and automatically recreates unresponsive VMs.
  • Enable autoscaling to automatically add or deleteVMs from your MIG based on increases or decreases in load.
  • Learn how toapply a new configurationto all or to a subset of the VMs in a MIG by setting and applying a newinstance template, all-instances configuration, or per-instance configuration.
  • Preserve disks, metadata, and IP addresses across disruptive events like VMrecreation, autohealing, and updates byadding stateful configuration.
  • Learn aboutworking with managed instances,for example, to delete, abandon, and recreate VMs in a MIG.
  • View info aboutMIGs and their VMs.

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.