Managing autoscalers

Perform administrative tasks for your autoscalers, such as creating, describing, updating, stopping, and deleting an autoscaler using the instructions provided here.

To learn more about managed instance group (MIG) autoscaling, read the overview.

Before you begin

Creating an autoscaler

Creating an autoscaler is slightly different depending on which autoscaling policy you want to use. For instructions on creating an autoscaler, see:

Getting information about an autoscaler

To get more information about a particular autoscaler, or to confirm that an autoscaler was successfully created, use the console, the gcloud compute instance-groups managed describe sub-command, or the get method in the Compute Engine API for a zonal or regional autoscaler resource.

Console

  1. In the Cloud Console, go to the Instance groups page.

    Go to the Instance groups page

  2. Click the name of a MIG from the list to open the group's details page.
  3. Click Details to view the group's details, including its autoscaling settings.

gcloud

In the gcloud command-line tool, use the describe command:

gcloud beta compute instance-groups managed describe instance-group-name

The command returns details about the autoscaler:

...
autoscaler:
  autoscalingPolicy:
    coolDownPeriodSec: 60
    cpuUtilization:
      utilizationTarget: 0.6
    maxNumReplicas: 20
    minNumReplicas: 10
    mode: 'ON'
    scaleDownControl:
      timeWindowSec: 300
      maxScaledDownReplicas:
        fixed: 3
        calculated: 3
...

API

To see the autoscaler resource that is attached to a MIG, use the instanceGroupManagers.get method method. For a regional MIG, replace zones/zone with regions/region.

GET https://compute.googleapis.com/compute/beta/projects/myproject/zones/zone/instanceGroupManagers/name
200 OK

{
  ...
  "status": {
    ...
    "autoscaler": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-c/autoscalers/example-group"
  },
}

To retrieve details about the autoscaler resource, use the autoscaler's get method. For a regional autoscaler, replace zones/zone with regions/region.

GET https://compute.googleapis.com/compute/beta/projects/myproject/zones/zone/autoscalers/example-autoscaler
200 OK

{
 "kind": "compute#autoscaler",
 "id": "8744945839459481093",
 "creationTimestamp": "2018-09-28T13:02:50.553-07:00",
 "name": "example-group",
 "target": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-c/instanceGroupManagers/example-group",
 "autoscalingPolicy": {
  "minNumReplicas": 10,
  "maxNumReplicas": 20,
  "mode": "ON",
  "scaleDownControl": {
    "timeWindowSec": 60,
    "maxScaledDownReplicas": {
      "calculated": 3,
      "percent": 15
    }
  },
  "coolDownPeriodSec": 60,
  "cpuUtilization": {
   "utilizationTarget": 0.6
  }
 },
 "zone": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-c",
 "selfLink": "https://www.googleapis.com/compute/beta/projects/my-project/zones/us-east1-c/autoscalers/example-group",
 "status": "ACTIVE"
}

Updating an autoscaler

To update an autoscaler, use the Google Cloud Console, the gcloud tool, or the Compute Engine API.

When you update an autoscaler, it might take some time for the changes to propagate, and it might be a couple of minutes before your new autoscaler settings are reflected.

console

  1. In the Cloud Console, go to the Instance groups page.

    Go to the Instance Groups page

  2. Click the name of a managed instance group from the list to open the group's details page.
  3. Click Edit group to view and update the group's current configuration, including its autoscaling settings.
  4. Click Save when you are done.

gcloud

Use the update-autoscaling command.

gcloud compute instance-groups managed update-autoscaling name \
        --max-num-replicas max-num ...

For instructions on how to create an autoscaler, see Creating an autoscaler.

API

To update an autoscaler resource for a zonal MIG, use the zonal autoscaler's patch method. For a regional MIG, use the regionAutoscaler's patch method. Provide a request body that contains the new configuration.

PATCH https://compute.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/autoscalers/example-autoscaler

{
 "autoscalingPolicy": {
  "maxNumReplicas": 20
 }
}
200 OK

{
 "kind": "compute#operation",
 "id": "4244494732310423322",
 "name": "operation-1556912627871-58800f8216ed7-74ab1720-7d360603",
 "zone": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f",
 "operationType": "compute.autoscalers.patch",
 "targetLink": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/autoscalers/example-autoscaler",
 "targetId": "340775527929467142",
 "status": "RUNNING",
 ...
}

When you perform any requests that modify data, a zoneOperations or regionOperations resource is returned, and you can query the operation to check the status of your change.

Turning off or restricting an autoscaler

Turn off an autoscaler to temporarily prevent it from scaling your MIG, or restrict your autoscaler so that it can only scale up your MIG. This feature is useful when you want to:

  • Investigate VM instances without interference from scaling in.
  • Reconfigure multiple properties of your MIG without scaling actions being triggered while your group is only partially reconfigured.
  • Maintain MIG capacity for a fast rollback while redirecting a workload to a new MIG.

If and when you re-enable the autoscaler, the autoscaler automatically returns to normal operation.

In the Google Cloud Console, the gcloud tool, or the Compute Engine API, set an autoscaler's mode to:

  • OFF: Temporarily disables autoscaling. Use this mode to prevent automatic changes of the MIG's size. The autoscaling configuration remains intact so you can re-enable autoscaling later.
  • ONLY_UP: Restrict autoscaling only to adding new VM instances. Use this mode to protect the group from shrinking and allow the group to provision extra VMs when load increases.
  • ON: Enables all autoscaling operations per its policy.

console

  1. In the Cloud Console, go to the Instance groups page.

    Go to the Instance groups page

  2. Click the name of a MIG from the list to open the group's details page.
  3. Click Edit group to view the group's current configuration, including its autoscaling settings.
  4. Under Autoscaling, set the Autoscaing mode to disable or restrict autoscaling for the group, or to turn the autoscaler back on.

gcloud

Use the set-autoscaling command with the --mode flag, to disable, restrict, or re-enable an an autoscaler.

gcloud compute instance-groups managed set-autoscaling name 
--mode mode

Replace the following:

  • mode:
    • OFF to disable the autoscaler but maintain its configuration
    • ONLY_UP to restrict the autoscaler to adding VM instances only
    • ON to re-enable all autoscaler activities according to its policy

API

To update the mode of an autoscaler resource for a zonal MIG, use the autoscaler's patch method. For a regional MIG, use the regionAutoscaler's patch method. Provide a request body that includes the autoscalingPolicy.mode property.

PATCH https://www.googleapis.com/compute/v1/projects/my-project/regions/us-central1-f/autoscalers?autoscaler=my-autoscaler

{
  "autoscalingPolicy": {
    "mode":"mode"
  }
}

Replace the following:

  • mode:
    • OFF to disable the autoscaler but maintain its configuration
    • ONLY_UP to restrict the autoscaler to adding instances only
    • ON to re-enable all autoscaler activities according to its policy

Controlling the scale-in rate of an autoscaler (beta)

If your workloads take many minutes to initialize, configure scale-in controls to reduce the risk of response latency and outages due to abrupt scale-in events. Specifically, if you routinely expect a load spike to follow soon after a decline in load, you can limit the scale-in rate to prevent the autoscaler from reducing a MIG's size by more VM instances than your workload can tolerate to lose.

Configuring scale-in controls

Configure scale-in controls using the gcloud tool or the Compute Engine API. Configuring scale-in controls is optional. By default, scale-in controls are not configured. When not configured, the autoscaler still relies on its default stabilization mechanism. That is, it maintains the recommended size at a level required to serve peak load, observed during the stabilization period of the trailing 10 minutes.

gcloud

You can configure scale-in controls when creating an autoscaler or when updating an autoscaler.

Configuring scale-in controls when creating an autoscaler

Set scale-in controls when creating an autoscaler for a MIG by using the --scale-in-control flag with the gcloud beta compute instance-groups managed set-autoscaling command. For example, use the following command to configure autoscaling for an example-group:

gcloud beta compute instance-groups managed set-autoscaling instance-group-name \
    --target-cpu-utilization 0.6 \
    --max-num-replicas 50 \
    --scale-in-control max-scaled-in-replicas=max-scale-in-replicas,time-window=time-window

Configuring scale-in controls when updating an autoscaler

Update scale-in controls in a MIG's existing autoscaler by using the --scale-in-control flag with the gcloud beta compute instance-groups managed update-autoscaling command. For example, use the following command to set scale-in controls in an existing autoscaling configuration for example-group:

gcloud beta compute instance-groups managed update-autoscaling instance-group-name \
    --scale-in-control max-scaled-in-replicas=max-scale-in-replicas,time-window=time-window

Replace the following:

  • instance-group-name: The name of the MIG to update.
  • max-scale-in-replicas: The maximum number of VMs allowed to be deducted from the peak size, taken from the specified trailing time window. The specified number of VM instances can be scaled in all at once, so your service should be able to afford losing this many VMs all at once. You can specify a number of VMs or a percentage. Use the % sign for percentages; for example: 50%.
  • time-window: Trailing time window to take the peak size from. Autoscaling won't scale in by more than the maximum allowed number of replicas from the peak size taken during this trailing time window. Specify this value in seconds within a [60, 3600] interval.

For example, say you set the time window to 1800 seconds (30 minutes). When calculating the current recommended size for the MIG, the autoscaler takes the peak size from the last 30 minutes (let's say 100 VMs), takes max-scaled-in-replicas (let's say 10 VMs), and won't set the current recommended size for the group below 90 VMs (100-10).

API

Configure scale-in controls by setting the maxScaledDownReplicas and timeWindowSec fields within the autoscalingPolicy.scaleDownControl structure in a zonal or regional autoscaler resource. There are no default values for these fields, you must provide values for both fields.

You can configure scale-in controls when creating an autoscaler or when updating an autoscaler.

Configuring scale-in controls when creating an autoscaler

For a zonal MIG, use the zonal autoscaler insert method method. For a regional MIG, use the regionAutoscalers insert method.

POST
https://www.googleapis.com/compute/beta/projects/project-id/regions/region/autoscalers

{
  "name": "name",
  "target": "https://compute.googleapis.com/compute/v1/projects/myproject/regions/region/instanceGroupManagers/instance-group-name",
  "autoscalingPolicy": {
    "minNumReplicas": 1,
    "maxNumReplicas": 5,
    "coolDownPeriodSec": 60,
    "cpuUtilization": {
      "utilizationTarget": 0.8
    },
    "scaleDownControl": {
      "maxScaledDownReplicas": {
           "fixed": max-scale-down-replicas
      },
      "timeWindowSec": time-window
    }
  }
}

For more information about creating an autoscaler, refer to the following articles:

Configuring scale-in controls when updating an autoscaler

For a zonal MIG, use the zonal autoscaler patch method. For a regional MIG, use the regionAutoscalers patch method.

PATCH
https://www.googleapis.com/compute/beta/projects/project-id/regions/region/autoscalers?autoscaler=name

{
  "autoscalingPolicy": {
    "minNumReplicas": 1,
    "maxNumReplicas": 5,
    "coolDownPeriodSec": 60,
    "cpuUtilization": {
      "utilizationTarget": 0.8
    },
    "scaleDownControl": {
      "maxScaledDownReplicas": {
           "fixed": max-scale-down-replicas
      },
      "timeWindowSec": time-window
    }
  }
}

Replace the following:

  • name: The name of the autoscaler to create. You can name your autoscaler after the MIG that will use it or name it something else.
  • instance-group-name: The name of the MIG to add the autoscaler to. For a regional MIG, replace zones/zone with regions/region.
  • max-scale-down-replicas: The maximum number of VMs allowed to be deducted from the peak recommended target size, taken from the specified trailing time window. The specified number of VM instances can be scaled in all at once, so your service should be able to afford losing this many VMs all at once. You can specify a number of VMs or a percentage. Use the maxScaledDownReplicas.percentage to specify a percent value.
  • time-window: The trailing time window to take the peak recommended size from. Autoscaling won't scale in by more than the maximum allowed number of replicas from the peak recommended size taken during this trailing time window. Specify this value in seconds within a [60, 3600] interval; for example: 1800.

For example, say you set the time window to 1800 seconds (30 minutes). When calculating the current recommended size for the MIG, the autoscaler takes the peak size from the last 30 minutes (let's say 100 VMs), takes max-scaled-down-replicas (let's say 10 VMs), and won't set the current recommended size for the group below 90 VMs (100-10).

For more information about how scale-in controls work, see Understanding autoscaler decisions.

Getting current configuration of scale-in controls

To get the current configuration of scale-in controls, see Getting information about an autoscaler.

Removing scale-in controls

You can remove scale-in controls to lift restrictions on the timing and magnitude of scale-in operations using the Compute Engine API.

Without scale-in controls, the autoscaler still relies on its default stabilization mechanism. Specifically, it maintains a recommended size at a level required to serve peak load, observed during the stabilization period of the trailing 10 minutes.

To remove scale-in controls, use the autoscalers.patch method and provide empty configuration for scale-in controls. For a regional MIG, replace zones/zone with regions/region.

PATCH
https://www.googleapis.com/compute/beta/projects/project-id/zones/zone/autoscalers?autoscaler=name

{
  "autoscalingPolicy": {
    "scaleDownControl": null
  }
}

Replace the following:

  • name: The name of the autoscaler to update. To get a list of existing autoscalers and their target MIGs, use the zonal or regional autoscaler aggregatedList method.

Deleting an autoscaler

You can permanently delete your autoscaler resource using the Google Cloud Console, the gcloud tool, or the Compute Engine API. If you want to temporarily stop autoscaling and keep your autoscaler resource and its configuration, disable your autoscaler instead.

console

  1. In the Cloud Console, go to the Instance groups page.

    Go to the Instance groups page

  2. Click the name of a MIG from the list to open the group's details page.

  3. Click Edit group to view the group's current configuration, including its autoscaling settings.

  4. Under Autoscaling, click Delete autoscaling configuration to stop the autoscaler and delete its configuration.

gcloud

Use the stop-autoscaling command to stop an autoscaler and delete its configuration.

gcloud compute instance-groups managed stop-autoscaling name

Stopping an autoscaler deletes it from the MIG. If you want to restart the autoscaler, you must recreate it by using the set-autoscaling command.

If you delete a MIG using the gcloud tool, any autoscalers attached to the MIG are also deleted.

API

To stop an autoscaler and delete its configuration, call the delete method. For a regional MIG, replace zones/zone with regions/region.

 DELETE https://compute.googleapis.com/compute/v1/projects/myproject/zones/zone/autoscalers/autoscaler-name

Feedback

We want to learn about your use cases, challenges, and feedback about autoscaling. Please share your feedback with our team at mig-discuss@google.com.

What's next