compute mig autoscaling troubleshooting
Diagnoses and resolves Google Compute Engine Managed Instance Group (MIG) autoscaling failures, scale-out blocks, and scale-in stalls. Use ONLY when a Compute Engine MIG fails to add or remove VM instances during load changes, hits quota or zonal stockout limits, reaches maxNumReplicas (CAPPED_AT_MAX_NUM_REPLICAS), conflicts with HTTP(S) load balancer maxRate settings, fails to scale in to zero instances, or fails to read Cloud Monitoring scaling metrics. DO NOT read or use for Google Kubernetes
Documentation & Preview
--- name: compute-mig-autoscaling-troubleshooting description: >- Diagnoses and resolves Google Compute Engine Managed Instance Group (MIG) autoscaling failures, scale-out blocks, and scale-in stalls. Use ONLY when a Compute Engine MIG fails to add or remove VM instances during load changes, hits quota or zonal stockout limits, reaches maxNumReplicas (CAPPED_AT_MAX_NUM_REPLICAS), conflicts with HTTP(S) load balancer maxRate settings, fails to scale in to zero instances, or fails to read Cloud Monitoring scaling metrics. DO NOT read or use for Google Kubernetes Engine (GKE) Horizontal Pod Autoscaler (HPA), GKE Cluster Autoscaler, standalone single-VM creation, or single-VM host maintenance reboots. metadata: version: "1.0.0" category: Compute
---
Compute Engine Managed Instance Group (MIG) Autoscaling Troubleshooting
This skill diagnoses and resolves autoscaling failures in Google Compute Engine
Managed Instance Groups (MIGs). It isolates root causes across
Project Quotas vs. Physical Zonal Stockouts, Autoscaler Policy Limits (maxNumReplicas, minNumReplicas: 0 scale-to-zero rules, scaleInControl, mode, --cool-down-period, Load Balancer UTILIZATION vs. RATE), and
Cloud Monitoring Metric / Service Agent IAM Availability.
> MCP Tools: get_instance_group_manager_basic_info, > list_instance_group_managers, list_managed_instances, > list_instance_templates, get_instance_template_basic_info, > get_instance_template_properties
Usage Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you MUST read and follow the instructions in Usage Attribution.
---
Prerequisites & Environment Setup
Any host, project, IAM, or MIG modifications (installing gcloud, configuring MCP, enabling APIs or Log Analytics, adding IAM bindings, updating autoscalers or backend services, or deleting resources) must be explicitly approved by the user before execution.
- Google Cloud SDK: Verify
gcloudis installed (gcloud --version). If
missing or outdated, seek user approval before installing via Install the gcloud CLI.
- Compute Engine MCP Server & Capability Boundary:
- The Compute Engine MCP server
(Use the Compute Engine MCP server) exposes read-only zonal MIG and template discovery tools (get_instance_group_manager_basic_info, list_instance_group_managers, list_managed_instances, list_instance_templates, get_instance_template_basic_info, get_instance_template_properties) and requires roles/mcp.toolUser.
- Critical Routing Rule:
get_instance_group_manager_basic_inforequires
a single zone (no regional MIG RPCs exist in Compute Engine MCP) and returns InstanceGroupManagerBasicInfo (name, id, instance_template, target_size, status), which omits autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, and autoscaler.autoscalingPolicy. Compute Engine MCP also lacks list-errors, Cloud Logging/Monitoring queries, and update-autoscaling / set-autoscaling mutations. Always route regional MIG inspection, autoscaler.* diagnostics, list-errors, Cloud Logging/Monitoring queries, and autoscaling mutations to gcloud (or Compute Engine / Monitoring / Logging REST APIs).
- Authentication: Local CLI (
gcloud auth login), Application Default
Credentials (gcloud auth application-default login), or Service Accounts (GOOGLE_APPLICATION_CREDENTIALS).
- Project, Region, Billing & API Enablement:
gcloud config set project {project_id}
gcloud config set compute/region {region}
gcloud config set compute/zone {zone}
gcloud services enable compute.googleapis.com logging.googleapis.com monitoring.googleapis.com*Note: An active billing account attachment is required (even when using Free Tier eligible resources). Default to a well-supported region such as us-central1 if unspecified, and consult Google Cloud locations to verify regional and zonal machine family availability.*
- Required IAM Roles:
- Human Caller / Agent Roles:
roles/compute.viewer,
roles/logging.viewer (plus roles/logging.viewAccessor for Log Analytics, and roles/bigquery.jobUser + roles/bigquery.dataViewer for linked BigQuery datasets), and roles/monitoring.viewer for read-only diagnostics; roles/compute.instanceAdmin.v1 (plus roles/iam.serviceAccountUser when updating templates with a VM service account, roles/compute.loadBalancerAdmin for Backend Service updates, and roles/resourcemanager.projectIamAdmin to repair project IAM bindings) for remediation; and roles/mcp.toolUser for Compute Engine MCP calls.
- Google-Managed Service Agents (Project-Level):
- Compute Engine Service Agent
(service-{project_number}@compute-system.iam.gserviceaccount.com): requires roles/compute.serviceAgent (includes Cloud Monitoring metric read permissions).
- Google APIs Service Agent
({project_number}@cloudservices.gserviceaccount.com): requires roles/compute.instanceGroupManagerServiceAgent (creates and deletes MIG member VMs).
---
Step 1: Identify Problem Scope & Inspect Autoscaler Status
A. Inspect Live MIG Stability, Autoscaler Status & Per-VM Actuation Errors
Inspect status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy, and targetSize via gcloud compute instance-groups managed describe (pass --region={region} for Regional MIGs or --zone={zone} for Zonal MIGs), and run gcloud compute instance-groups managed list-errors to surface asynchronous VM creation errors:
# 1. Inspect Autoscaler status, statusDetails, recommendedSize, and policy (Regional MIG):
gcloud compute instance-groups managed describe {mig_name} --project={project_id} --region={region} \
--format="yaml(name, targetSize, status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy)"
# (For a Zonal MIG, replace --region={region} with --zone={zone}:)
gcloud compute instance-groups managed describe {mig_name} --project={project_id} --zone={zone} \
--format="yaml(name, targetSize, status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy)"
# 2. Inspect per-instance actuation errors logged by the MIG controller:
gcloud compute instance-groups managed list-errors {mig_name} --project={project_id} --region={region} --limit=25Authoritative autoscaler.statusDetails[] (type & message) Values & Root Causes (see Understanding autoscaler decisions): Each item in autoscaler.statusDetails[] on the REST Autoscaler resource contains a structured type enum and a human-readable message string:
CAPPED_AT_MAX_NUM_REPLICAS("The number of instances has reached the
maxNumReplicas. The autoscaler cannot add more instances."): Current target size has hit the configured autoscalingPolicy.maxNumReplicas ceiling while demand warrants more VMs.
NOT_ENOUGH_QUOTA_AVAILABLE/QUOTA_EXCEEDED("Quota for some
resources is exceeded. Increase the quota or delete resources to free up more quota.", paired with QUOTA_EXCEEDED in list-errors and Cloud Audit Logs): Project or regional quota (CPUS, IN_USE_ADDRESSES, SSD_TOTAL_GB, or GPUs) is exhausted.
ZONE_RESOURCE_STOCKOUT/REGION_RESOURCE_STOCKOUT(paired with
ZONE_RESOURCE_POOL_EXHAUSTED or
ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS in list-errors and Cloud Audit Logs): Temporary physical hardware shortage in the target zone or region.
- **
MISSING_CUSTOM_METRIC_DATA_POINTS/CUSTOM_METRIC_INVALID/
CUSTOM_METRIC_DATA_POINTS_TOO_SPARSE** ("The monitoring metric that was specified does not exist or does not have the required labels. Check the metric."): The autoscaler cannot read valid 60-second data points from the configured Cloud Monitoring metric, or service-{project_number}@compute-system.iam.gserviceaccount.com lacks roles/compute.serviceAgent.
UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION("Autoscaling does
not work with an HTTP/S load balancer configured for maxRate."),
BACKEND_SERVICE_DOES_NOT_EXIST, MORE_THAN_ONE_BACKEND_SERVICE, or
MISSING_LOAD_BALANCING_DATA_POINTS: Load-balancing autoscaling conflicts with a Backend Service configured in RATE (maxRate) balancing mode instead of UTILIZATION, references a deleted/multiple backend services, or receives no traffic.
ALL_INSTANCES_UNHEALTHY("All instances in the instance group are
unhealthy (not in RUNNING state). If this is an error, check the instances."): All MIG instances are not in RUNNING state, halting load-based scaling decisions until instances recover.
- **
MODE_ONLY_SCALE_OUT/MODE_ONLY_UP/MODE_OFF/MIN_EQUALS_MAX/
SCALING_SCHEDULE_AFFECTING_MIN_REPLICAS / WARNING_NO_INSTANCES**: Policy mode or schedule constraints actively restricting scale-in or scale-out.
B. Query Cloud Audit Logs for Autoscaler Decisions & Instance Creation Failures
Query Cloud Audit Logs across autoscaler, gce_autoscaler, gce_instance_group_manager, gce_instance_group, and gce_instance (passing --freshness=7d because gcloud logging read defaults to 1d). See Viewing autoscaler logs:
- Autoscaler
system_eventAudit Log Schemas (protoPayload.metadata): - **Resize decisions (
compute.autoscalers.resize,@type:
"type.googleapis.com/autoscaler.AutoscalerSizeChangeExplanation")**: Records protoPayload.metadata.oldSize, protoPayload.metadata.newSize, protoPayload.metadata.autoscalingMode, protoPayload.metadata.autoscalingReason.summary, protoPayload.metadata.autoscalingReason.scalingSignal (name, calculatedSize, calculationDetails.servingSize, calculationDetails.signalTarget, calculationDetails.signalValue), and protoPayload.metadata.autoscalingReason.scalingLimit (name, limitSize, limitPolicy, e.g., MAX_REPLICAS_LIMIT or SCALE_IN_LIMIT).
- **Status transitions (
compute.autoscalers.changeStatus,
@type: "type.googleapis.com/autoscaler.AutoscalerStatusChange")**: Records human-readable status message transitions in protoPayload.metadata.oldStatus.details and protoPayload.metadata.newStatus.details (for example, transitioning from "OK" to "Quota for some resources is exceeded. Increase the quota or delete resources to free up more quota."; statusDetails[].type enum codes live on the REST Autoscaler resource rather than inside changeStatus log entries).
# 1. Query failed MIG resize, autoscaler, and VM insertion Admin Activity logs (projecting errors[0].code):
gcloud logging read '(resource.type="autoscaler" OR resource.type="gce_autoscaler" OR resource.type="gce_instance_group_manager" OR resource.type="gce_instance_group" OR resource.type="gce_instance") AND severity>=ERROR AND protoPayload.methodName=~"compute\.(regionInstanceGroupManagers|instanceGroupManagers|instances|instanceGroups|autoscalers|regionAutoscalers)\.(resize|insert|addInstances|removeInstances|changeStatus|update|patch)" AND protoPayload.resourceName:"{mig_name}"' \
--project={pro