Managed instance groups offer autoscaling capabilities that allow you to automatically add or remove instances from a managed instance group based on increases or decreases in load. Autoscaling helps your applications gracefully handle increases in traffic and reduces cost when the need for resources is lower. You just define the autoscaling policy and the autoscaler performs automatic scaling based on the measured load.
Before you begin
- Read the VM instances documentation.
- If you want to use the command-line examples in this guide:
- If you want to use the API examples in this guide, set up API access.
Autoscaling uses the following fundamental concepts and services.
Managed instance groups
Autoscaling is a feature of managed instance groups. A managed instance group is a pool of homogeneous instances, created from a common instance template. An autoscaler adds or remove instances from a managed instance group. Although Compute Engine has both managed and unmanaged instance groups, only managed instance groups can be used with autoscaler.
To understand the difference between a managed instance group and unmanaged instance group, see the Instance Groups documentation.
Autoscaling policy and target utilization
To create an autoscaler, you must specify the autoscaling policy and a target utilization level that the autoscaler uses to determine when to scale the group. You can choose to scale using the following policies:
- Average CPU utilization
- Stackdriver Monitoring metrics
- HTTP load balancing serving capacity, which can be based on either utilization or requests per second.
- Google Cloud Pub/Sub queuing workload (Alpha)
The autoscaler will collect information based on the policy, compare it to your desired target utilization, and determine if it needs to perform scaling.
The target utilization level is the level at which you want to maintain your virtual machine instances. For example, if you scale based on CPU utilization, you can set your target utilization level at 75% and the autoscaler will maintain the CPU utilization of the specified group of instances at or close to 75%. The utilization level for each metric is interpreted differently based on the autoscaling policy.
For a brief summary of each policy, see Autoscaling policies in Overviews. For a detailed discussion of each policy, see:
- Scaling Based on CPU or Load Balancing Serving Capacity
- Scaling Based on Stackdriver Monitoring Metrics
- Scaling Based on a Queue-based Workload (Alpha)
Before you begin
Learn about managed instance groups
Autoscaler is a feature of managed instance groups so you should understand how managed instance groups work before you use autoscaling.
Get a managed instance group name or URL
For all autoscaling requests, you must provide either a managed instance group name or managed instance group URL. In the
gcloud, command-line tool, you can use a managed instance group name, while the API requires a fully-qualified URL.
To get the URL to an existing managed instance group, you can use either the
instance-groups managed list --uricommand or the
instance-groups managed list [INSTANCE_GROUP] --uricommand. For example, the following command provides the URL of a managed instance group in the us-central1-f zone:
gcloud compute instance-groups managed list example-group --uri --zone us-central1-f
gcloudtool returns the managed instance groups URL:
If you do not have an existing managed instance group, review how to create a managed instance group.