Manually suspend or stop VMs in a MIG


This document explains how to suspend and stop virtual machine (VM) instances in a managed instance group (MIG), and how to resume their operation.

Before you begin

  • Review the introductory page about suspended and stopped VMs in a MIG.
  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    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, then initialize it 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, then initialize it by running the following command:

      gcloud init

Suspend specific VMs in a MIG

You can suspend a running VM in a MIG using the Google Cloud console, the Google Cloud CLI, or the Compute Engine API.

Console

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

    Go to the Instance groups page

  2. Click the instance group name where you want to suspend VMs.
  3. In the instance group Overview page, under VM instances, select all the VMs that you want to suspend.
  4. Click Suspend.
  5. In the confirmation dialog that appears, click Suspend to confirm.

gcloud

Use the beta instance-groups managed suspend-instances command.

gcloud beta compute instance-groups managed suspend-instances MIG_NAME \
  --instances=INSTANCE_NAME \
  [--region=REGION | --zone=ZONE]

Replace the following:

  • MIG_NAME: the name of the MIG in which to suspend an instance.
  • INSTANCE_NAME: the name of the instance to suspend. To suspend multiple instances, provide a comma-separated list of names.
  • REGION: for a regional MIG, the region where the MIG is located.
  • ZONE: for a zonal MIG, the zone where the MIG is located.

API

Use the beta.instanceGroupManager.suspendInstances method and specify the instances in the request body. For regional MIGs, use the beta.regionInstanceGroupManager.suspendInstances method.

POST https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/suspendInstances

{
  "instances": [
    "INSTANCE_NAME_URL"
  ]
}

Replace the following:

  • PROJECT_ID: the project ID for the request.
  • ZONE: for a zonal MIG, the zone where the MIG is located.
    • For a regional MIG, replace zones/ZONE with regions/REGION and specify the region of the MIG.
  • MIG_NAME: the name of the MIG in which to suspend an instance.
  • INSTANCE_NAME_URL: the URL of the instance to suspend—for example, zones/us-central1-a/instances/example-instance-name1. To suspend multiple instances, provide a comma-separated list of URLs—for example, "zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2".

Resume selected VMs in a MIG

You can resume a suspended VM in a MIG using the Google Cloud console, the gcloud CLI, or the Compute Engine API.

Console

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

    Go to the Instance groups page

  2. Click the instance group name where you want to resume VMs.
  3. In the instance group Overview page, under VM instances, select all the suspended VMs that you want to resume, then click Start/Resume.

gcloud

Use the beta instance-groups managed resume-instances command.

gcloud beta compute instance-groups managed resume-instances MIG_NAME \
  --instances=INSTANCE_NAME \
  [--region=REGION | --zone=ZONE]

Replace the following:

  • MIG_NAME: the name of the MIG in which to resume an instance.
  • INSTANCE_NAME: the name of the instance to resume. To resume multiple instances, provide a comma-separated list of names.
  • REGION: for a regional MIG, the region where the MIG is located.
  • ZONE: for a zonal MIG, the zone where the MIG is located.

API

Use the beta.instanceGroupManager.resumeInstances method and specify the instances in the request body. For regional MIGs, use the beta.regionInstanceGroupManager.resumeInstances method.

POST https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/resumeInstances

{
  "instances": [
    "INSTANCE_NAME_URL"
  ]
}

Replace the following:

  • PROJECT_ID: the project ID for the request.
  • ZONE: for a zonal MIG, the zone where the MIG is located.
    • For a regional MIG, replace zones/ZONE with regions/REGION and specify the region of the MIG.
  • MIG_NAME: the name of the MIG in which to resume an instance.
  • INSTANCE_NAME_URL: the URL of the instance to resume—for example, zones/us-central1-a/instances/example-instance-name1. To resume multiple instances, provide a comma-separated list of URLs—for example, "zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2".

Stop selected VMs in a MIG

You can stop a running VM in a MIG using the Google Cloud console, the Google Cloud CLI, or the Compute Engine API.

Console

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

    Go to the Instance groups page

  2. Click the instance group name where you want to stop VMs.
  3. In the instance group Overview page, under VM instances, select all the VMs that you want to stop, then click Stop.
  4. In the confirmation dialog that appears, click Stop to confirm.

gcloud

Use the beta instance-groups managed stop-instances command.

gcloud beta compute instance-groups managed stop-instances MIG_NAME \
  --instances=INSTANCE_NAME \
  [--region=REGION | --zone=ZONE]

Replace the following:

  • MIG_NAME: the name of the MIG in which to stop an instance.
  • INSTANCE_NAME: the name of the instance to stop. To stop multiple instances, provide a comma-separated list of names.
  • REGION: for a regional MIG, the region where the MIG is located.
  • ZONE: for a zonal MIG, the zone where the MIG is located.

API

Use the beta.instanceGroupManager.stopInstances method and specify the instances in the request body. For regional MIGs, use the beta.regionInstanceGroupManager.stopInstances method.

POST https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/stopInstances

{
  "instances": [
    "INSTANCE_NAME_URL"
  ]
}

Replace the following:

  • PROJECT_ID: the project ID for the request.
  • ZONE: for a zonal MIG, the zone where the MIG is located.
    • For a regional MIG, replace zones/ZONE with regions/REGION and specify the region of the MIG.
  • MIG_NAME: the name of the MIG in which to stop an instance.
  • INSTANCE_NAME_URL: the URL of the instance to stop—for example, zones/us-central1-a/instances/example-instance-name1. To stop multiple instances, provide a comma-separated list of URLs—for example, "zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2".

Start selected VMs in a MIG

You can start a stopped VM in a MIG using the Google Cloud console, the gcloud CLI, or the Compute Engine API.

Console

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

    Go to the Instance groups page

  2. Click the instance group name where you want to start VMs.
  3. In the instance group Overview page, under VM instances, select all the stopped VMs that you want to start, then click Start/Resume.

gcloud

Use the beta instance-groups managed start-instances command.

gcloud beta compute instance-groups managed start-instances MIG_NAME \
  --instances=INSTANCE_NAME \
  [--region=REGION | --zone=ZONE]

Replace the following:

  • MIG_NAME: the name of the MIG in which to start an instance.
  • INSTANCE_NAME: the name of the instance to start. To start multiple instances, provide a comma-separated list of names.
  • REGION: for a regional MIG, the region where the MIG is located.
  • ZONE: for a zonal MIG, the zone where the MIG is located.

API

Use the beta.instanceGroupManager.startInstances method and specify the instances in the request body. For regional MIGs, use the beta.regionInstanceGroupManager.startInstances method.

POST https://www.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME/startInstances

{
  "instances": [
    "INSTANCE_NAME_URL"
  ]
}

Replace the following:

  • PROJECT_ID: the project ID for the request.
  • ZONE: for a zonal MIG, the zone where the MIG is located.
    • For a regional MIG, replace zones/ZONE with regions/REGION and specify the region of the MIG.
  • MIG_NAME: the name of the MIG in which to start an instance.
  • INSTANCE_NAME_URL: the URL of the instance to start—for example, zones/us-central1-a/instances/example-instance-name1. To start multiple instances, provide a comma-separated list of URLs—for example, "zones/us-central1-a/instances/example-instance-name1","zones/us-central1-a/instances/example-instance-name2".

What's next