{"data":{"slug":"github-google-skills-skills-cloud-compute-mig-autoscaling-troubleshooting-1c1509c31428","title":"Compute Engine MIG Autoscaling Troubleshooting","summary":"Diagnoses and resolves Compute Engine Managed Instance Group (MIG) autoscaling failures, scale-out blocks, and scale-in stalls. The deliverable includes analysis of autoscaler status, error logs, and recommendations for resolution.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-compute-mig-autoscaling-troubleshooting-1c1509c31428","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-compute-mig-autoscaling-troubleshooting-1c1509c31428","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-compute-mig-autoscaling-troubleshooting-1c1509c31428.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-compute-mig-autoscaling-troubleshooting-1c1509c31428\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any commands, ensure the user has explicitly approved modifications to the project, IAM roles, or MIG configurations. Required IAM roles include `roles\/monitoring.viewer` and `roles\/compute.viewer`. Verify that the `gcloud` CLI is installed and up to date, and that the Compute Engine MCP server is accessible with the `roles\/mcp.toolUser` role.","instructions":"---\nname: compute-mig-autoscaling-troubleshooting\ndescription: >-\n  Diagnoses and resolves Google Compute Engine Managed Instance Group\n  (MIG) autoscaling failures, scale-out blocks, and scale-in stalls. Use ONLY\n  when a Compute Engine MIG fails to add or remove VM instances during load\n  changes, hits quota or zonal stockout limits, reaches maxNumReplicas\n  (CAPPED_AT_MAX_NUM_REPLICAS), conflicts with HTTP(S) load balancer maxRate\n  settings, fails to scale in to zero instances, or fails to read Cloud\n  Monitoring scaling metrics. DO NOT read or use for Google Kubernetes Engine\n  (GKE) Horizontal Pod Autoscaler (HPA), GKE Cluster Autoscaler, standalone\n  single-VM creation, or single-VM host maintenance reboots.\nmetadata:\n  version: \"1.0.0\"\n  category: Compute\n---\n\n# Compute Engine Managed Instance Group (MIG) Autoscaling Troubleshooting\n\nThis skill diagnoses and resolves autoscaling failures in Google Compute Engine\n**Managed Instance Groups (MIGs)**. It isolates root causes across\n**Project Quotas vs. Physical Zonal Stockouts**, **Autoscaler Policy Limits\n(`maxNumReplicas`, `minNumReplicas: 0` scale-to-zero rules, `scaleInControl`,\n`mode`, `--cool-down-period`, Load Balancer `UTILIZATION` vs. `RATE`)**, and\n**Cloud Monitoring Metric \/ Service Agent IAM Availability**.\n\n> **MCP Tools:** `get_instance_group_manager_basic_info`,\n> `list_instance_group_managers`, `list_managed_instances`,\n> `list_instance_templates`, `get_instance_template_basic_info`,\n> `get_instance_template_properties`\n\n## Usage Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read and follow the instructions in\n[Usage Attribution](references\/attribution.md).\n\n---\n\n## Prerequisites & Environment Setup\n\nAny host, project, IAM, or MIG modifications (installing `gcloud`, configuring\nMCP, enabling APIs or Log Analytics, adding IAM bindings, updating autoscalers\nor backend services, or deleting resources) must be explicitly approved by the\nuser before execution.\n\n1. **Google Cloud SDK**: Verify `gcloud` is installed (`gcloud --version`). If\n   missing or outdated, seek user approval before installing via\n   [Install the gcloud CLI](https:\/\/docs.cloud.google.com\/sdk\/docs\/install-sdk.md.txt).\n2. **Compute Engine MCP Server & Capability Boundary**:\n   - The Compute Engine MCP server\n     ([Use the Compute Engine MCP server](https:\/\/docs.cloud.google.com\/compute\/docs\/use-compute-engine-mcp.md.txt))\n     exposes read-only **zonal** MIG and template discovery tools\n     (`get_instance_group_manager_basic_info`, `list_instance_group_managers`,\n     `list_managed_instances`, `list_instance_templates`,\n     `get_instance_template_basic_info`, `get_instance_template_properties`) and\n     requires `roles\/mcp.toolUser`.\n   - **Critical Routing Rule**: `get_instance_group_manager_basic_info` requires\n     a single `zone` (no regional MIG RPCs exist in Compute Engine MCP) and\n     returns `InstanceGroupManagerBasicInfo` (`name`, `id`, `instance_template`,\n     `target_size`, `status`), which **omits `autoscaler.status`,\n     `autoscaler.statusDetails`, `autoscaler.recommendedSize`, and\n     `autoscaler.autoscalingPolicy`**. Compute Engine MCP also lacks\n     `list-errors`, Cloud Logging\/Monitoring queries, and `update-autoscaling` \/\n     `set-autoscaling` mutations. Always route regional MIG inspection,\n     `autoscaler.*` diagnostics, `list-errors`, Cloud Logging\/Monitoring\n     queries, and autoscaling mutations to `gcloud` (or Compute Engine \/\n     Monitoring \/ Logging REST APIs).\n3. **Authentication**: Local CLI (`gcloud auth login`), Application Default\n   Credentials (`gcloud auth application-default login`), or Service Accounts\n   (`GOOGLE_APPLICATION_CREDENTIALS`).\n4. **Project, Region, Billing & API Enablement**:\n   ```sh\n   gcloud config set project {project_id}\n   gcloud config set compute\/region {region}\n   gcloud config set compute\/zone {zone}\n   gcloud services enable compute.googleapis.com logging.googleapis.com monitoring.googleapis.com\n   ```\n   *Note: An active billing account attachment is required (even when using Free\n   Tier eligible resources). Default to a well-supported region such as\n   `us-central1` if unspecified, and consult\n   [Google Cloud locations](https:\/\/cloud.google.com\/about\/locations) to verify\n   regional and zonal machine family availability.*\n5. **Required IAM Roles**:\n   - **Human Caller \/ Agent Roles**: `roles\/compute.viewer`,\n     `roles\/logging.viewer` (plus `roles\/logging.viewAccessor` for Log\n     Analytics, and `roles\/bigquery.jobUser` + `roles\/bigquery.dataViewer` for\n     linked BigQuery datasets), and `roles\/monitoring.viewer` for read-only\n     diagnostics; `roles\/compute.instanceAdmin.v1` (plus\n     `roles\/iam.serviceAccountUser` when updating templates with a VM service\n     account, `roles\/compute.loadBalancerAdmin` for Backend Service updates, and\n     `roles\/resourcemanager.projectIamAdmin` to repair project IAM bindings) for\n     remediation; and `roles\/mcp.toolUser` for Compute Engine MCP calls.\n   - **Google-Managed Service Agents (Project-Level)**:\n     - **Compute Engine Service Agent**\n       (`service-{project_number}@compute-system.iam.gserviceaccount.com`):\n       requires `roles\/compute.serviceAgent` (includes Cloud Monitoring metric\n       read permissions).\n     - **Google APIs Service Agent**\n       (`{project_number}@cloudservices.gserviceaccount.com`): requires\n       `roles\/compute.instanceGroupManagerServiceAgent` (creates and deletes MIG\n       member VMs).\n\n---\n\n## Step 1: Identify Problem Scope & Inspect Autoscaler Status\n\n### A. Inspect Live MIG Stability, Autoscaler Status & Per-VM Actuation Errors\n\nInspect `status.isStable`, `autoscaler.status`, `autoscaler.statusDetails`,\n`autoscaler.recommendedSize`, `autoscaler.autoscalingPolicy`, and `targetSize`\nvia `gcloud compute instance-groups managed describe` (pass `--region={region}`\nfor Regional MIGs or `--zone={zone}` for Zonal MIGs), and run `gcloud compute\ninstance-groups managed list-errors` to surface asynchronous VM creation errors:\n\n```sh\n# 1. Inspect Autoscaler status, statusDetails, recommendedSize, and policy (Regional MIG):\ngcloud compute instance-groups managed describe {mig_name} --project={project_id} --region={region} \\\n    --format=\"yaml(name, targetSize, status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy)\"\n\n# (For a Zonal MIG, replace --region={region} with --zone={zone}:)\ngcloud compute instance-groups managed describe {mig_name} --project={project_id} --zone={zone} \\\n    --format=\"yaml(name, targetSize, status.isStable, autoscaler.status, autoscaler.statusDetails, autoscaler.recommendedSize, autoscaler.autoscalingPolicy)\"\n\n# 2. Inspect per-instance actuation errors logged by the MIG controller:\ngcloud compute instance-groups managed list-errors {mig_name} --project={project_id} --region={region} --limit=25\n```\n\n**Authoritative `autoscaler.statusDetails[]` (`type` & `message`) Values &\nRoot Causes** (see\n[Understanding autoscaler decisions](https:\/\/docs.cloud.google.com\/compute\/docs\/autoscaler\/understanding-autoscaler-decisions.md.txt)):\nEach item in `autoscaler.statusDetails[]` on the REST `Autoscaler` resource\ncontains a structured `type` enum and a human-readable `message` string:\n- **`CAPPED_AT_MAX_NUM_REPLICAS`** (`\"The number of instances has reached the`\n  `maxNumReplicas. The autoscaler cannot add more instances.\"`):\n  Current target size has hit the configured `autoscalingPolicy.maxNumReplicas`\n  ceiling while demand warrants more VMs.\n- **`NOT_ENOUGH_QUOTA_AVAILABLE` \/ `QUOTA_EXCEEDED`** (`\"Quota for some`\n  `resources is exceeded. Increase the quota or delete resources to free up`\n  `more quota.\"`, paired with **`QUOTA_EXCEEDED`** in `list-errors` and Cloud\n  Audit Logs): Project or regional quota (`CPUS`, `IN_USE_ADDRESSES`,\n  `SSD_TOTAL_GB`, or GPUs) is exhausted.\n- **`ZONE_RESOURCE_STOCKOUT` \/ `REGION_RESOURCE_STOCKOUT`** (paired with\n  **`ZONE_RESOURCE_POOL_EXHAUSTED`** or\n  **`ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS`** in `list-errors` and Cloud\n  Audit Logs): Temporary physical hardware shortage in the target zone or\n  region.\n- **`MISSING_CUSTOM_METRIC_DATA_POINTS` \/ `CUSTOM_METRIC_INVALID` \/\n  `CUSTOM_METRIC_DATA_POINTS_TOO_SPARSE`** (`\"The monitoring metric that was`\n  `specified does not exist or does not have the required labels. Check the`\n  `metric.\"`):\n  The autoscaler cannot read valid 60-second data points from the configured\n  Cloud Monitoring metric, or\n  `service-{project_number}@compute-system.iam.gserviceaccount.com` lacks\n  `roles\/compute.serviceAgent`.\n- **`UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION`** (`\"Autoscaling does`\n  `not work with an HTTP\/S load balancer configured for maxRate.\"`),\n  **`BACKEND_SERVICE_DOES_NOT_EXIST`**, **`MORE_THAN_ONE_BACKEND_SERVICE`**, or\n  **`MISSING_LOAD_BALANCING_DATA_POINTS`**: Load-balancing autoscaling conflicts\n  with a Backend Service configured in `RATE` (`maxRate`) balancing mode instead\n  of `UTILIZATION`, references a deleted\/multiple backend services, or receives\n  no traffic.\n- **`ALL_INSTANCES_UNHEALTHY`** (`\"All instances in the instance group are`\n  `unhealthy (not in RUNNING state). If this is an error, check the`\n  `instances.\"`):\n  All MIG instances are not in `RUNNING` state, halting load-based scaling\n  decisions until instances recover.\n- **`MODE_ONLY_SCALE_OUT` \/ `MODE_ONLY_UP` \/ `MODE_OFF` \/ `MIN_EQUALS_MAX` \/\n  `SCALING_SCHEDULE_AFFECTING_MIN_REPLICAS` \/ `WARNING_NO_INSTANCES`**:\n  Policy mode or schedule constraints actively restricting scale-in or\n  scale-out.\n\n### B. Query Cloud Audit Logs for Autoscaler Decisions & Instance Creation Failures\n\nQuery Cloud Audit Logs across `autoscaler`, `gce_autoscaler`,\n`gce_instance_group_manager`, `gce_instance_group`, and `gce_instance` (passing\n`--freshness=7d` because `gcloud logging read` defaults to `1d`). See\n[Viewing autoscaler logs](https:\/\/docs.cloud.google.com\/compute\/docs\/autoscaler\/viewing-autoscaler-logs.md.txt):\n\n- **Autoscaler `system_event` Audit Log Schemas (`protoPayload.metadata`)**:\n  - **Resize decisions (`compute.autoscalers.resize`, `@type:`\n    `\"type.googleapis.com\/autoscaler.AutoscalerSizeChangeExplanation\"`)**:\n    Records `protoPayload.metadata.oldSize`, `protoPayload.metadata.newSize`,\n    `protoPayload.metadata.autoscalingMode`,\n    `protoPayload.metadata.autoscalingReason.summary`,\n    `protoPayload.metadata.autoscalingReason.scalingSignal` (`name`,\n    `calculatedSize`, `calculationDetails.servingSize`,\n    `calculationDetails.signalTarget`, `calculationDetails.signalValue`), and\n    `protoPayload.metadata.autoscalingReason.scalingLimit` (`name`, `limitSize`,\n    `limitPolicy`, e.g., `MAX_REPLICAS_LIMIT` or `SCALE_IN_LIMIT`).\n  - **Status transitions (`compute.autoscalers.changeStatus`,\n    `@type: \"type.googleapis.com\/autoscaler.AutoscalerStatusChange\"`)**:\n    Records human-readable status message transitions in\n    `protoPayload.metadata.oldStatus.details` and\n    `protoPayload.metadata.newStatus.details` (for example, transitioning from\n    `\"OK\"` to `\"Quota for some resources is exceeded. Increase the quota or`\n    `delete resources to free up more quota.\"`;\n    `statusDetails[].type` enum codes live on the REST `Autoscaler` resource\n    rather than inside `changeStatus` log entries).\n\n```sh\n# 1. Query failed MIG resize, autoscaler, and VM insertion Admin Activity logs (projecting errors[0].code):\ngcloud 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}\"' \\\n    --project={project_id} --freshness=7d --limit=25 \\\n    --format=\"table(timestamp, resource.type, protoPayload.methodName, protoPayload.status.message, protoPayload.response.error.errors[0].code, protoPayload.response.error.errors[0].message)\"\n\n# 2. Query autoscaler system_event resize decisions and status change explanations:\ngcloud logging read '(resource.type=\"autoscaler\" OR resource.type=\"gce_autoscaler\") AND log_id(\"cloudaudit.googleapis.com\/system_event\") AND protoPayload.methodName=~\"compute\\.autoscalers\\.(resize|changeStatus)\"' \\\n    --project={project_id} --freshness=7d --limit=25 \\\n    --format=\"yaml(timestamp, protoPayload.methodName, protoPayload.metadata.oldSize, protoPayload.metadata.newSize, protoPayload.metadata.autoscalingReason, protoPayload.metadata.oldStatus.details, protoPayload.metadata.newStatus.details)\"\n```\n\n**Distinguishing `QUOTA_EXCEEDED` vs. `ZONE_RESOURCE_POOL_EXHAUSTED`**:\n- **`QUOTA_EXCEEDED`**: A **project or regional quota limit** was reached (e.g.,\n  `Quota 'CPUS' exceeded. Limit: 24.0 in region us-central1`). Resolve by\n  requesting a quota increase, deleting idle resources, or switching to a\n  machine family with separate regional quota headroom.\n- **`ZONE_RESOURCE_POOL_EXHAUSTED` (or\n  `ZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS`)**: A physical **zonal hardware\n  stockout** (requesting a project quota increase will **not** fix this).\n  Resolve by migrating to a Regional MIG spanning multiple zones with `ANY`\n  target distribution shape, or switching zones\/machine series.\n\n### C. Compare Autoscaler Recommended Size vs. Actual MIG Size in Cloud Monitoring\n\n*Required IAM Roles*: `roles\/monitoring.viewer` and `roles\/compute.viewer`.\n\nQuery these two GA Cloud Monitoring metrics to compare autoscaler intent against\nactual group size:\n1. **`compute.googleapis.com\/instance_group\/size`**\n   (`resource.type=\"instance_group\"`, filtered by\n   `resource.labels.instance_group_name=\"{mig_name}\"`): Actual number of VM\n   instances currently in the group.\n2. **`autoscaler.googleapis.com\/recommended_size`**\n   (`resource.type=\"autoscaler\"`, filtered by\n   `resource.labels.instance_group_manager_name=\"{mig_name}\"`): Instance count\n   calculated and recommended by the autoscaler from active scaling signals.\n\n**How to Interpret Metric Divergence**:\n- **If `autoscaler.googleapis.com\/recommended_size >`\n  `compute.googleapis.com\/instance_group\/size` (Scale-Out Blocked)**:\n  The autoscaler wants more VMs, but actuation is blocked by:\n  1. `maxNumReplicas` ceiling (`CAPPED_AT_MAX_NUM_REPLICAS`),\n  2. Project\/regional `QUOTA_EXCEEDED` (`NOT_ENOUGH_QUOTA_AVAILABLE`), or\n  3. Physical stockout (`ZONE_RESOURCE_POOL_EXHAUSTED` \/\n     `ZONE_RESOURCE_STOCKOUT`).\n- **If `autoscaler.googleapis.com\/recommended_size <`\n  `compute.googleapis.com\/instance_group\/size` (Scale-In Delayed or Blocked)**:\n  Load dropped and the autoscaler recommends fewer VMs, but scale-in is held by:\n  1. The built-in **10-minute stabilization period** (`stabilizationPeriodSec`,\n     default `600` seconds of sustained lower demand to prevent flapping),\n  2. **Scale-in controls (`scaleInControl`)**, where `maxScaledInReplicas`\n     (`maxScaledInReplicas.fixed`, `maxScaledInReplicas.percent`, and\n     `maxScaledInReplicas.calculated`) caps VM deletions per trailing\n     `timeWindowSec`, or\n  3. Autoscaler `mode` set to **`ONLY_SCALE_OUT`** (`--mode=only-scale-out`).\n\n### D. Log Analytics SQL Query: Rank MIGs & VM Insertions by Failure Volume\n\nFailed `activity` audit logs (`severity_number >= 500`, `ERROR` and above) route\nto `_Default._AllLogs` (whereas `system_event` autoscaler status events route to\n`_Required._AllLogs`). Upgrade `_Default` if needed (with user approval):\n\n```sh\ngcloud logging buckets update _Default --project={project_id} --location=global --enable-analytics\n```\n\nIn `_AllLogs`, `resource.labels` has BigQuery type **`JSON`** (always extract\nlabels via `JSON_VALUE(...)`), and include `'gce_instance'` and `'autoscaler'`\nin `resource.type IN (...)` so failed `instances.insert` and `autoscalers.*`\noperations are captured alongside `instanceGroupManagers.resize`:\n\n```sql\nSELECT\n  TIMESTAMP_TRUNC(timestamp, HOUR) AS hour_bucket,\n  resource.type AS resource_type,\n  COALESCE(JSON_VALUE(resource.labels.location), JSON_VALUE(resource.labels.zone)) AS location,\n  REGEXP_EXTRACT(proto_payload.audit_log.resource_name, r'[^\/]+$') AS target_resource,\n  proto_payload.audit_log.method_name AS method_name,\n  proto_payload.audit_log.status.message AS status_message,\n  COUNT(*) AS error_count\nFROM `{project_id}.global._Default._AllLogs`\nWHERE\n  timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n  AND resource.type IN ('autoscaler', 'gce_autoscaler', 'gce_instance_group_manager', 'gce_instance_group', 'gce_instance')\n  AND severity_number >= 500\n  AND REGEXP_CONTAINS(\n    proto_payload.audit_log.method_name,\n    r'compute\\.(regionInstanceGroupManagers|instanceGroupManagers|instanceGroups|autoscalers|regionAutoscalers|instances)\\.(resize|addInstances|removeInstances|insert|update|patch|changeStatus)$'\n  )\nGROUP BY hour_bucket, resource_type, location, target_resource, method_name, status_message\nORDER BY hour_bucket DESC, error_count DESC;\n```\n\n---\n\n## Step 2: Diagnose & Remediate via 4-Branch Decision Tree\n\n### Branch 1: Resource Quota Constraints (`QUOTA_EXCEEDED` \/ `NOT_ENOUGH_QUOTA_AVAILABLE`)\n\nWhen `QUOTA_EXCEEDED` blocks scaling (e.g., `CPUS`, `IN_USE_ADDRESSES`,\n`SSD_TOTAL_GB`, or GPUs), **always include all 4 steps below**:\n\n1. **Verify Project & `compute.googleapis.com` API Configuration (Always\n   Include)**:\n   ```sh\n   gcloud config set project {project_id}\n   gcloud services enable compute.googleapis.com\n   ```\n2. **Inspect Regional Quota Usage and Limits**:\n   ```sh\n   gcloud compute regions describe {region} --project={project_id} \\\n       --format=\"table(quotas:format='table(metric,limit,usage)')\"\n   ```\n3. **Request a Quota Increase**: Submit a quota increase request in the Google\n   Cloud Console under **IAM & Admin > Quotas & System Limits** (`IAM & Admin >\n   Quotas`).\n4. **Immediate Workarounds to Unblock Scaling**:\n   - **Switch Machine Family**: Update the MIG's Instance Template to a machine\n     family governed by a separate regional CPU quota pool with headroom (e.g.,\n     switching between `e2`, `n2`, `n2d`, or `c3`).\n   - **Spread Load Across Another Region**: Add a sibling MIG in another region\n     behind a global Backend Service.\n   - **Delete Unused Resources**: Remove idle VMs, unattached static IPs, or\n     orphaned disks in the region.\n\n### Branch 2: Scale-Out Configuration & Thrashing (`CAPPED_AT_MAX_NUM_REPLICAS`, Load Balancer `maxRate`, `--cool-down-period`)\n\n1. **Ceiling Reached (`CAPPED_AT_MAX_NUM_REPLICAS`)**: Raise\n   `--max-num-replicas` via `update-autoscaling` (use `--region={region}` for\n   regional MIGs):\n   ```sh\n   gcloud compute instance-groups managed update-autoscaling {mig_name} \\\n       --project={project_id} --zone={zone} --max-num-replicas={new_max_replicas}\n   ```\n2. **HTTP(S) Load Balancer `RATE` vs. `UTILIZATION` Conflict\n   (`UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION`)**: Switch the Backend\n   Service backend from `RATE` to `UTILIZATION` (or switch the MIG autoscaler\n   signal to CPU or a Cloud Monitoring metric). Pass\n   `--instance-group-zone={zone}` for a Zonal MIG or\n   `--instance-group-region={region}` for a Regional MIG (and replace `--global`\n   with `--region={backend_service_region}` if the Backend Service is regional):\n   ```sh\n   # Zonal MIG attached to a global Backend Service:\n   gcloud compute backend-services update-backend {backend_service} --project={project_id} --global \\\n       --instance-group={mig_name} --instance-group-zone={zone} --balancing-mode=UTILIZATION --max-utilization=0.8\n\n   # Regional MIG attached to a global Backend Service:\n   gcloud compute backend-services update-backend {backend_service} --project={project_id} --global \\\n       --instance-group={mig_name} --instance-group-region={region} --balancing-mode=UTILIZATION --max-utilization=0.8\n   ```\n3. **Boot Disk \/ Missing Image Errors**: Inspect `gcloud compute instance-groups\n   managed list-errors {mig_name} --project={project_id} --zone={zone}` and\n   verify the template's boot image exists via `gcloud compute\n   instance-templates describe {template_name} --project={project_id}`.\n4. **Initialization Period (`--cool-down-period`) vs. Stabilization Period\n   (`--stabilization-period`)**:\n   - **Critical CLI Rule**: `--cool-down-period` (VM startup initialization\n     window, default `60`s) does **not** exist on `update-autoscaling`\u2014it is\n     accepted **only** on `set-autoscaling`. Because `set-autoscaling`\n     **replaces** the entire `autoscalingPolicy`, always inspect existing policy\n     signals via `describe` first and pass `--max-num-replicas` plus active\n     scaling targets (such as `--target-cpu-utilization`) together:\n     ```sh\n     gcloud compute instance-groups managed set-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n         --min-num-replicas={min_replicas} --max-num-replicas={max_replicas} \\\n         --target-cpu-utilization={target_cpu} --cool-down-period=120\n     ```\n   - To tune the **scale-in stabilization window** (default `600`s) without\n     replacing the policy, `--stabilization-period` **is** supported directly on\n     `update-autoscaling`:\n     ```sh\n     gcloud compute instance-groups managed update-autoscaling {mig_name} \\\n         --project={project_id} --zone={zone} --stabilization-period=600\n     ```\n\n### Branch 3: Scale-Down Blocked or Delayed (`scaleInControl`, `ONLY_SCALE_OUT`, or `minNumReplicas: 0`)\n\nIf traffic dropped hours ago and `autoscaler.googleapis.com\/recommended_size` is\nfar below `compute.googleapis.com\/instance_group\/size` (or the MIG refuses to\nscale in to `0` instances):\n\n1. **Inspect `autoscaler.autoscalingPolicy.mode`, `scaleInControl`, and\n   `minNumReplicas`**:\n   ```sh\n   gcloud compute instance-groups managed describe {mig_name} --project={project_id} --zone={zone} \\\n       --format=\"yaml(autoscaler.autoscalingPolicy.mode, autoscaler.autoscalingPolicy.minNumReplicas, autoscaler.autoscalingPolicy.scaleInControl, autoscaler.autoscalingPolicy.coolDownPeriodSec)\"\n   ```\n   - `scaleInControl` contains `timeWindowSec` and the nested object\n     `maxScaledInReplicas` (`maxScaledInReplicas.fixed`,\n     `maxScaledInReplicas.percent`, and `maxScaledInReplicas.calculated`).\n   - *(Note: REST\/`describe` outputs uppercase `ON` \/ `ONLY_SCALE_OUT` \/ `OFF`,\n     whereas `gcloud` CLI `--mode` requires **lowercase** `--mode=on`,\n     `--mode=only-scale-out`, or `--mode=off`.)*\n2. **Scaling In to Zero \/ Scaling Out from Zero (`minNumReplicas: 0`)**:\n   - Per [Understanding autoscaler decisions](https:\/\/docs.cloud.google.com\/compute\/docs\/autoscaler\/understanding-autoscaler-decisions.md.txt),\n     a MIG with `minNumReplicas: 0` **cannot scale in to `0` instances** if its\n     autoscaling policy includes **any per-instance signal** (CPU utilization,\n     HTTP load balancing serving capacity, or a per-instance Cloud Monitoring\n     metric), and cannot scale out from `0` if its only signal is a per-instance\n     metric (because `0` running VMs emit no per-instance metrics).\n   - To scale in to `0` and back out from `0`, configure only **scaling\n     schedules** (`scalingSchedules`) or a **group-level Cloud Monitoring\n     metric** using `--stackdriver-metric-single-instance-assignment`\n     (`singleInstanceAssignment`, such as a Pub\/Sub subscription backlog).\n3. **Remediate `mode` or `scaleInControl`**:\n   ```sh\n   # Enable full scaling (--mode=on) and relax scale-in throttling:\n   gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n       --mode=on --scale-in-control=max-scaled-in-replicas-percent=50,time-window=600\n\n   # Or clear scale-in controls completely for immediate scale-down after stabilization:\n   gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n       --mode=on --clear-scale-in-control\n   ```\n4. **Safe Rollback to Conservative Scale-In Limits (Always Include)**:\n   Whenever modifying `scaleInControl`, **always** provide rollback commands to\n   restore conservative scale-in limits after recovery so sudden traffic\n   rebounds do not hit an under-provisioned MIG:\n   ```sh\n   gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n       --mode=on --scale-in-control=max-scaled-in-replicas-percent=10,time-window=600\n   ```\n\n### Branch 4: Scaling Metric Availability & Service Agent IAM Issues\n\n1. **Repair Google-Managed Service Agent IAM Roles**: Look up `{project_number}`\n   first, then obtain explicit user approval before restoring bindings:\n   ```sh\n   # Step 1: Retrieve {project_number} for {project_id}:\n   gcloud projects describe {project_id} --format=\"value(projectNumber)\"\n\n   # Step 2a: Restore Compute Engine Service Agent (reads Cloud Monitoring scaling metrics):\n   gcloud projects add-iam-policy-binding {project_id} \\\n       --member=\"serviceAccount:service-{project_number}@compute-system.iam.gserviceaccount.com\" \\\n       --role=\"roles\/compute.serviceAgent\"\n\n   # Step 2b: Restore Google APIs Service Agent (creates and deletes MIG member VMs):\n   gcloud projects add-iam-policy-binding {project_id} \\\n       --member=\"serviceAccount:{project_number}@cloudservices.gserviceaccount.com\" \\\n       --role=\"roles\/compute.instanceGroupManagerServiceAgent\"\n   ```\n2. **Verify Custom Cloud Monitoring Metric Resource & Label Contract**:\n   - **Per-Instance Metrics**: Must be written to monitored resource\n     `gce_instance` with the **numeric VM `instance_id`** and **`zone`** labels\n     (**`instance_name` is NOT a valid `gce_instance` monitored resource\n     label**).\n   - **Data Type, Kind & Frequency**: Export `INT64` or `DOUBLE` values with\n     `GAUGE` or `DELTA` metric kind (**`CUMULATIVE` metrics are unsupported**)\n     at least every **60 seconds**. See\n     [Scaling based on Cloud Monitoring metrics](https:\/\/docs.cloud.google.com\/compute\/docs\/autoscaler\/scaling-cloud-monitoring-metrics.md.txt).\n\n---\n\n## Proactive Hardening, Safe Rollback & Cleanup\n\n1. **Predictive Autoscaling (CPU Workloads)**: For workloads with recurring\n   daily or weekly cycles, enable Predictive Autoscaling (note that\n   `update-autoscaling` accepts `--cpu-utilization-predictive-method` only when\n   CPU utilization scaling is already configured; otherwise configure both via\n   `set-autoscaling`). See\n   [Predictive autoscaling](https:\/\/docs.cloud.google.com\/compute\/docs\/autoscaler\/predictive-autoscaling.md.txt):\n   ```sh\n   # On a MIG that already scales on CPU utilization:\n   gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n       --cpu-utilization-predictive-method=optimize-availability\n\n   # Or configure CPU target + Predictive Autoscaling together (replaces policy):\n   gcloud compute instance-groups managed set-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n       --min-num-replicas={min_replicas} --max-num-replicas={max_replicas} \\\n       --target-cpu-utilization=0.6 --cpu-utilization-predictive-method=optimize-availability\n   ```\n2. **Safe Rollback of Scale-In Controls**:\n   ```sh\n   gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \\\n       --mode=on --scale-in-control=max-scaled-in-replicas-percent=10,time-window=600\n   ```\n3. **Teardown Temporary Test MIGs & Templates**: Delete temporary test resources\n   when finished (omitting `--quiet` on manual commands so interactive\n   confirmation prevents accidental deletion):\n   ```sh\n   gcloud compute instance-groups managed delete {mig_name} --project={project_id} --zone={zone}\n   gcloud compute instance-templates delete {template_name} --project={project_id}\n   ```\n4. **Pricing Reference**: Autoscaling policies incur no extra fee beyond member\n   VM instances, disks, and Cloud Monitoring custom metric ingestion. Consult\n   [Google Cloud pricing](https:\/\/cloud.google.com\/pricing) and\n   [Compute Engine pricing](https:\/\/cloud.google.com\/compute\/all-pricing) for\n   current regional rates rather than quoting hardcoded dollar figures.\n","use_cases":["When a MIG fails to add or remove VM instances during load changes","When MIG hits quota or zonal stockout limits","When MIG reaches maxNumReplicas (CAPPED_AT_MAX_NUM_REPLICAS)","When MIG fails to scale in to zero instances"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/c413c1fdc1714f2e4ae44a449b9744348197119c\/skills\/cloud\/compute-mig-autoscaling-troubleshooting\/SKILL.md","source_commit":"c413c1fdc1714f2e4ae44a449b9744348197119c","license":null,"version":null,"listing_approved_at":"2026-11-27","created_at":"2026-11-26T10:55:19.000000Z","updated_at":"2026-11-27T07:43:08.000000Z","seo_title":"Compute Engine MIG Autoscaling Troubleshooting","seo_description":"Diagnose and resolve Compute Engine MIG autoscaling issues including scale-out blocks and scale-in stalls.","seo_keywords":["Compute Engine MIG troubleshooting","MIG autoscaling issues","Google Cloud autoscaling problems","Compute Engine scaling failures","MIG scale-out block","MIG scale-in stall"]}}