Delete a MIG

This document describes how to delete a managed instance group (MIG) that you no longer need so you can stop paying for the resources it uses.

Before you begin

  • If you haven't already, set up authentication. 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:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    1. Install the Google Cloud CLI, and then sign in to the gcloud CLI with your federated identity. After signing in, initialize the Google Cloud CLI by running the following command:

      gcloud init
    2. 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, and then sign in to the gcloud CLI with your federated identity.

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

Delete a MIG

When you delete a MIG, all VMs in the group are deleted. You can't recover the MIG or its VMs. Before you delete a MIG, consider the following:

  • If you want to keep any of the VMs, abandon the VMs first to remove those VMs from the group. Then, delete the MIG.

  • If you enabled graceful shutdown in the instance template that your MIG uses, then the VMs in your MIG gracefully shut down when you delete the MIG. Because VMs continue to incur charges for memory and vCPUs while a graceful shutdown is in progress, you can end the graceful shutdown early when your tasks finish running, or skip it entirely if you don't need to finish active tasks.

The disks in a MIG are deleted only if you had set the disk's auto-delete property to true when defining the disks in the MIG's instance template. If a disk's auto-delete property is set to false, then you can manually clean up the disks when you no longer need them.

When you delete a managed instance group and its instances by using the Google Cloud console or the gcloud CLI, any attached autoscaler is automatically deleted. However, if you use the REST, you must first issue a separate request to delete any attached autoscaler with the autoscalers.delete method or regionAutoscalers.delete method. If you happen to delete the managed instance group first, you can still delete the attached autoscaler by using REST.

For each disk, you can also override the auto-delete property to specify whether the disk should be deleted when its associated instance is deleted.

Console

  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Select one or more groups on the list that you want to delete.

  3. Click Delete. If there is no Delete option, then click More actions, and then select Delete.

  4. In the dialog that appears, do the following:

    1. Optional: To delete the compute instances without gracefully shutting them down, or to end an ongoing graceful shutdown, select the Skip graceful shutdown (if applicable) checkbox.

    2. To confirm, click Delete.

gcloud

Use the delete command.

gcloud compute instance-groups managed delete INSTANCE_GROUP_NAME \
    --zone ZONE

If you want to delete a MIG without gracefully shutting down its VMs, or end an ongoing graceful shutdown, then use the same command with the --no-graceful-shutdown flag:

gcloud compute instance-groups managed delete INSTANCE_GROUP_NAME \
    --no-graceful-shutdown \
    --zone ZONE

REST

Call the delete method for a zonal or regional MIG resource. If the MIG has an attached autoscaler, you must first delete the autoscaler using the autoscalers.delete method or regionAutoscalers.delete method.

DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME

If the instance group is a regional managed instance group, replace zones/ZONE with regions/REGION.

If you want to delete a MIG without gracefully shutting down its VMs, or to end an ongoing graceful shutdown, then include the noGracefulShutdown query parameter set to true in the request URL:

DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME?noGracefulShutdown=true

What's next