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 Engine (GKE) Horizontal Pod Autoscaler (HPA), GKE Cluster Autoscaler, standalone single-VM creation
Try your first task
A source-grounded starter task has not been verified for this skill yet.
SKILL.md
name: compute-mig-autoscaling-troubleshootingdescription: >- 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: ComputeCompute 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 requiresroles/mcp.toolUser. - Critical Routing Rule:
get_instance_group_manager_basic_inforequires a singlezone(no regional MIG RPCs exist in Compute Engine MCP) and returnsInstanceGroupManagerBasicInfo(name,id,instance_template,target_size,status), which omitsautoscaler.status,autoscaler.statusDetails,autoscaler.recommendedSize, andautoscaler.autoscalingPolicy. Compute Engine MCP also lackslist-errors, Cloud Logging/Monitoring queries, andupdate-autoscaling/set-autoscalingmutations. Always route regional MIG inspection,autoscaler.*diagnostics,list-errors, Cloud Logging/Monitoring queries, and autoscaling mutations togcloud(or Compute Engine / Monitoring / Logging REST APIs).
- The Compute Engine MCP server
(Use the Compute Engine MCP server)
exposes read-only zonal MIG and template discovery tools
(
- 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:
Note: An active billing account attachment is required (even when using Free Tier eligible resources). Default to a well-supported region such asgcloud 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.comus-central1if 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(plusroles/logging.viewAccessorfor Log Analytics, androles/bigquery.jobUser+roles/bigquery.dataViewerfor linked BigQuery datasets), androles/monitoring.viewerfor read-only diagnostics;roles/compute.instanceAdmin.v1(plusroles/iam.serviceAccountUserwhen updating templates with a VM service account,roles/compute.loadBalancerAdminfor Backend Service updates, androles/resourcemanager.projectIamAdminto repair project IAM bindings) for remediation; androles/mcp.toolUserfor Compute Engine MCP calls. - Google-Managed Service Agents (Project-Level):
- Compute Engine Service Agent
(
service-{project_number}@compute-system.iam.gserviceaccount.com): requiresroles/compute.serviceAgent(includes Cloud Monitoring metric read permissions). - Google APIs Service Agent
(
{project_number}@cloudservices.gserviceaccount.com): requiresroles/compute.instanceGroupManagerServiceAgent(creates and deletes MIG member VMs).
- Compute Engine Service Agent
(
- Human Caller / Agent Roles:
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=25
Authoritative 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 themaxNumReplicas. The autoscaler cannot add more instances."): Current target size has hit the configuredautoscalingPolicy.maxNumReplicasceiling while demand warrants more VMs.NOT_ENOUGH_QUOTA_AVAILABLE/QUOTA_EXCEEDED("Quota for someresources is exceeded. Increase the quota or delete resources to free upmore quota.", paired withQUOTA_EXCEEDEDinlist-errorsand 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 withZONE_RESOURCE_POOL_EXHAUSTEDorZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILSinlist-errorsand 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 wasspecified does not exist or does not have the required labels. Check themetric."): The autoscaler cannot read valid 60-second data points from the configured Cloud Monitoring metric, orservice-{project_number}@compute-system.iam.gserviceaccount.comlacksroles/compute.serviceAgent.UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION("Autoscaling doesnot work with an HTTP/S load balancer configured for maxRate."),BACKEND_SERVICE_DOES_NOT_EXIST,MORE_THAN_ONE_BACKEND_SERVICE, orMISSING_LOAD_BALANCING_DATA_POINTS: Load-balancing autoscaling conflicts with a Backend Service configured inRATE(maxRate) balancing mode instead ofUTILIZATION, references a deleted/multiple backend services, or receives no traffic.ALL_INSTANCES_UNHEALTHY("All instances in the instance group areunhealthy (not in RUNNING state). If this is an error, check theinstances."): All MIG instances are not inRUNNINGstate, 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"): RecordsprotoPayload.metadata.oldSize,protoPayload.metadata.newSize,protoPayload.metadata.autoscalingMode,protoPayload.metadata.autoscalingReason.summary,protoPayload.metadata.autoscalingReason.scalingSignal(name,calculatedSize,calculationDetails.servingSize,calculationDetails.signalTarget,calculationDetails.signalValue), andprotoPayload.metadata.autoscalingReason.scalingLimit(name,limitSize,limitPolicy, e.g.,MAX_REPLICAS_LIMITorSCALE_IN_LIMIT). - Status transitions (
compute.autoscalers.changeStatus,@type: "type.googleapis.com/autoscaler.AutoscalerStatusChange"): Records human-readable status message transitions inprotoPayload.metadata.oldStatus.detailsandprotoPayload.metadata.newStatus.details(for example, transitioning from"OK"to"Quota for some resources is exceeded. Increase the quota ordelete resources to free up more quota.";statusDetails[].typeenum codes live on the RESTAutoscalerresource rather than insidechangeStatuslog entries).
- Resize decisions (
# 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={project_id} --freshness=7d --limit=25 \
--format="table(timestamp, resource.type, protoPayload.methodName, protoPayload.status.message, protoPayload.response.error.errors[0].code, protoPayload.response.error.errors[0].message)"
# 2. Query autoscaler system_event resize decisions and status change explanations:
gcloud 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)"' \
--project={project_id} --freshness=7d --limit=25 \
--format="yaml(timestamp, protoPayload.methodName, protoPayload.metadata.oldSize, protoPayload.metadata.newSize, protoPayload.metadata.autoscalingReason, protoPayload.metadata.oldStatus.details, protoPayload.metadata.newStatus.details)"
Distinguishing QUOTA_EXCEEDED vs. ZONE_RESOURCE_POOL_EXHAUSTED:
QUOTA_EXCEEDED: A project or regional quota limit was reached (e.g.,Quota 'CPUS' exceeded. Limit: 24.0 in region us-central1). Resolve by requesting a quota increase, deleting idle resources, or switching to a machine family with separate regional quota headroom.ZONE_RESOURCE_POOL_EXHAUSTED(orZONE_RESOURCE_POOL_EXHAUSTED_WITH_DETAILS): A physical zonal hardware stockout (requesting a project quota increase will not fix this). Resolve by migrating to a Regional MIG spanning multiple zones withANYtarget distribution shape, or switching zones/machine series.
C. Compare Autoscaler Recommended Size vs. Actual MIG Size in Cloud Monitoring
Required IAM Roles: roles/monitoring.viewer and roles/compute.viewer.
Query these two GA Cloud Monitoring metrics to compare autoscaler intent against actual group size:
compute.googleapis.com/instance_group/size(resource.type="instance_group", filtered byresource.labels.instance_group_name="{mig_name}"): Actual number of VM instances currently in the group.autoscaler.googleapis.com/recommended_size(resource.type="autoscaler", filtered byresource.labels.instance_group_manager_name="{mig_name}"): Instance count calculated and recommended by the autoscaler from active scaling signals.
How to Interpret Metric Divergence:
- If
autoscaler.googleapis.com/recommended_size >compute.googleapis.com/instance_group/size(Scale-Out Blocked): The autoscaler wants more VMs, but actuation is blocked by:maxNumReplicasceiling (CAPPED_AT_MAX_NUM_REPLICAS),- Project/regional
QUOTA_EXCEEDED(NOT_ENOUGH_QUOTA_AVAILABLE), or - Physical stockout (
ZONE_RESOURCE_POOL_EXHAUSTED/ZONE_RESOURCE_STOCKOUT).
- If
autoscaler.googleapis.com/recommended_size <compute.googleapis.com/instance_group/size(Scale-In Delayed or Blocked): Load dropped and the autoscaler recommends fewer VMs, but scale-in is held by:- The built-in 10-minute stabilization period (
stabilizationPeriodSec, default600seconds of sustained lower demand to prevent flapping), - Scale-in controls (
scaleInControl), wheremaxScaledInReplicas(maxScaledInReplicas.fixed,maxScaledInReplicas.percent, andmaxScaledInReplicas.calculated) caps VM deletions per trailingtimeWindowSec, or - Autoscaler
modeset toONLY_SCALE_OUT(--mode=only-scale-out).
- The built-in 10-minute stabilization period (
D. Log Analytics SQL Query: Rank MIGs & VM Insertions by Failure Volume
Failed activity audit logs (severity_number >= 500, ERROR and above) route
to _Default._AllLogs (whereas system_event autoscaler status events route to
_Required._AllLogs). Upgrade _Default if needed (with user approval):
gcloud logging buckets update _Default --project={project_id} --location=global --enable-analytics
In _AllLogs, resource.labels has BigQuery type JSON (always extract
labels via JSON_VALUE(...)), and include 'gce_instance' and 'autoscaler'
in resource.type IN (...) so failed instances.insert and autoscalers.*
operations are captured alongside instanceGroupManagers.resize:
SELECT
TIMESTAMP_TRUNC(timestamp, HOUR) AS hour_bucket,
resource.type AS resource_type,
COALESCE(JSON_VALUE(resource.labels.location), JSON_VALUE(resource.labels.zone)) AS location,
REGEXP_EXTRACT(proto_payload.audit_log.resource_name, r'[^/]+$') AS target_resource,
proto_payload.audit_log.method_name AS method_name,
proto_payload.audit_log.status.message AS status_message,
COUNT(*) AS error_count
FROM `{project_id}.global._Default._AllLogs`
WHERE
timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND resource.type IN ('autoscaler', 'gce_autoscaler', 'gce_instance_group_manager', 'gce_instance_group', 'gce_instance')
AND severity_number >= 500
AND REGEXP_CONTAINS(
proto_payload.audit_log.method_name,
r'compute\.(regionInstanceGroupManagers|instanceGroupManagers|instanceGroups|autoscalers|regionAutoscalers|instances)\.(resize|addInstances|removeInstances|insert|update|patch|changeStatus)$'
)
GROUP BY hour_bucket, resource_type, location, target_resource, method_name, status_message
ORDER BY hour_bucket DESC, error_count DESC;
Step 2: Diagnose & Remediate via 4-Branch Decision Tree
Branch 1: Resource Quota Constraints (QUOTA_EXCEEDED / NOT_ENOUGH_QUOTA_AVAILABLE)
When QUOTA_EXCEEDED blocks scaling (e.g., CPUS, IN_USE_ADDRESSES,
SSD_TOTAL_GB, or GPUs), always include all 4 steps below:
- Verify Project &
compute.googleapis.comAPI Configuration (Always Include):gcloud config set project {project_id} gcloud services enable compute.googleapis.com - Inspect Regional Quota Usage and Limits:
gcloud compute regions describe {region} --project={project_id} \ --format="table(quotas:format='table(metric,limit,usage)')" - Request a Quota Increase: Submit a quota increase request in the Google
Cloud Console under IAM & Admin > Quotas & System Limits (
IAM & Admin > Quotas). - Immediate Workarounds to Unblock Scaling:
- Switch Machine Family: Update the MIG's Instance Template to a machine
family governed by a separate regional CPU quota pool with headroom (e.g.,
switching between
e2,n2,n2d, orc3). - Spread Load Across Another Region: Add a sibling MIG in another region behind a global Backend Service.
- Delete Unused Resources: Remove idle VMs, unattached static IPs, or orphaned disks in the region.
- Switch Machine Family: Update the MIG's Instance Template to a machine
family governed by a separate regional CPU quota pool with headroom (e.g.,
switching between
Branch 2: Scale-Out Configuration & Thrashing (CAPPED_AT_MAX_NUM_REPLICAS, Load Balancer maxRate, --cool-down-period)
- Ceiling Reached (
CAPPED_AT_MAX_NUM_REPLICAS): Raise--max-num-replicasviaupdate-autoscaling(use--region={region}for regional MIGs):gcloud compute instance-groups managed update-autoscaling {mig_name} \ --project={project_id} --zone={zone} --max-num-replicas={new_max_replicas} - HTTP(S) Load Balancer
RATEvs.UTILIZATIONConflict (UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION): Switch the Backend Service backend fromRATEtoUTILIZATION(or switch the MIG autoscaler signal to CPU or a Cloud Monitoring metric). Pass--instance-group-zone={zone}for a Zonal MIG or--instance-group-region={region}for a Regional MIG (and replace--globalwith--region={backend_service_region}if the Backend Service is regional):# Zonal MIG attached to a global Backend Service: gcloud compute backend-services update-backend {backend_service} --project={project_id} --global \ --instance-group={mig_name} --instance-group-zone={zone} --balancing-mode=UTILIZATION --max-utilization=0.8 # Regional MIG attached to a global Backend Service: gcloud compute backend-services update-backend {backend_service} --project={project_id} --global \ --instance-group={mig_name} --instance-group-region={region} --balancing-mode=UTILIZATION --max-utilization=0.8 - Boot Disk / Missing Image Errors: Inspect
gcloud compute instance-groups managed list-errors {mig_name} --project={project_id} --zone={zone}and verify the template's boot image exists viagcloud compute instance-templates describe {template_name} --project={project_id}. - Initialization Period (
--cool-down-period) vs. Stabilization Period (--stabilization-period):- Critical CLI Rule:
--cool-down-period(VM startup initialization window, default60s) does not exist onupdate-autoscaling—it is accepted only onset-autoscaling. Becauseset-autoscalingreplaces the entireautoscalingPolicy, always inspect existing policy signals viadescribefirst and pass--max-num-replicasplus active scaling targets (such as--target-cpu-utilization) together:gcloud compute instance-groups managed set-autoscaling {mig_name} --project={project_id} --zone={zone} \ --min-num-replicas={min_replicas} --max-num-replicas={max_replicas} \ --target-cpu-utilization={target_cpu} --cool-down-period=120 - To tune the scale-in stabilization window (default
600s) without replacing the policy,--stabilization-periodis supported directly onupdate-autoscaling:gcloud compute instance-groups managed update-autoscaling {mig_name} \ --project={project_id} --zone={zone} --stabilization-period=600
- Critical CLI Rule:
Branch 3: Scale-Down Blocked or Delayed (scaleInControl, ONLY_SCALE_OUT, or minNumReplicas: 0)
If traffic dropped hours ago and autoscaler.googleapis.com/recommended_size is
far below compute.googleapis.com/instance_group/size (or the MIG refuses to
scale in to 0 instances):
- Inspect
autoscaler.autoscalingPolicy.mode,scaleInControl, andminNumReplicas:gcloud compute instance-groups managed describe {mig_name} --project={project_id} --zone={zone} \ --format="yaml(autoscaler.autoscalingPolicy.mode, autoscaler.autoscalingPolicy.minNumReplicas, autoscaler.autoscalingPolicy.scaleInControl, autoscaler.autoscalingPolicy.coolDownPeriodSec)"scaleInControlcontainstimeWindowSecand the nested objectmaxScaledInReplicas(maxScaledInReplicas.fixed,maxScaledInReplicas.percent, andmaxScaledInReplicas.calculated).- (Note: REST/
describeoutputs uppercaseON/ONLY_SCALE_OUT/OFF, whereasgcloudCLI--moderequires lowercase--mode=on,--mode=only-scale-out, or--mode=off.)
- Scaling In to Zero / Scaling Out from Zero (
minNumReplicas: 0):- Per Understanding autoscaler decisions,
a MIG with
minNumReplicas: 0cannot scale in to0instances if its autoscaling policy includes any per-instance signal (CPU utilization, HTTP load balancing serving capacity, or a per-instance Cloud Monitoring metric), and cannot scale out from0if its only signal is a per-instance metric (because0running VMs emit no per-instance metrics). - To scale in to
0and back out from0, configure only scaling schedules (scalingSchedules) or a group-level Cloud Monitoring metric using--stackdriver-metric-single-instance-assignment(singleInstanceAssignment, such as a Pub/Sub subscription backlog).
- Per Understanding autoscaler decisions,
a MIG with
- Remediate
modeorscaleInControl:# Enable full scaling (--mode=on) and relax scale-in throttling: gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \ --mode=on --scale-in-control=max-scaled-in-replicas-percent=50,time-window=600 # Or clear scale-in controls completely for immediate scale-down after stabilization: gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \ --mode=on --clear-scale-in-control - Safe Rollback to Conservative Scale-In Limits (Always Include):
Whenever modifying
scaleInControl, always provide rollback commands to restore conservative scale-in limits after recovery so sudden traffic rebounds do not hit an under-provisioned MIG:gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \ --mode=on --scale-in-control=max-scaled-in-replicas-percent=10,time-window=600
Branch 4: Scaling Metric Availability & Service Agent IAM Issues
- Repair Google-Managed Service Agent IAM Roles: Look up
{project_number}first, then obtain explicit user approval before restoring bindings:# Step 1: Retrieve {project_number} for {project_id}: gcloud projects describe {project_id} --format="value(projectNumber)" # Step 2a: Restore Compute Engine Service Agent (reads Cloud Monitoring scaling metrics): gcloud projects add-iam-policy-binding {project_id} \ --member="serviceAccount:service-{project_number}@compute-system.iam.gserviceaccount.com" \ --role="roles/compute.serviceAgent" # Step 2b: Restore Google APIs Service Agent (creates and deletes MIG member VMs): gcloud projects add-iam-policy-binding {project_id} \ --member="serviceAccount:{project_number}@cloudservices.gserviceaccount.com" \ --role="roles/compute.instanceGroupManagerServiceAgent" - Verify Custom Cloud Monitoring Metric Resource & Label Contract:
- Per-Instance Metrics: Must be written to monitored resource
gce_instancewith the numeric VMinstance_idandzonelabels (instance_nameis NOT a validgce_instancemonitored resource label). - Data Type, Kind & Frequency: Export
INT64orDOUBLEvalues withGAUGEorDELTAmetric kind (CUMULATIVEmetrics are unsupported) at least every 60 seconds. See Scaling based on Cloud Monitoring metrics.
- Per-Instance Metrics: Must be written to monitored resource
Proactive Hardening, Safe Rollback & Cleanup
- Predictive Autoscaling (CPU Workloads): For workloads with recurring
daily or weekly cycles, enable Predictive Autoscaling (note that
update-autoscalingaccepts--cpu-utilization-predictive-methodonly when CPU utilization scaling is already configured; otherwise configure both viaset-autoscaling). See Predictive autoscaling:# On a MIG that already scales on CPU utilization: gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \ --cpu-utilization-predictive-method=optimize-availability # Or configure CPU target + Predictive Autoscaling together (replaces policy): gcloud compute instance-groups managed set-autoscaling {mig_name} --project={project_id} --zone={zone} \ --min-num-replicas={min_replicas} --max-num-replicas={max_replicas} \ --target-cpu-utilization=0.6 --cpu-utilization-predictive-method=optimize-availability - Safe Rollback of Scale-In Controls:
gcloud compute instance-groups managed update-autoscaling {mig_name} --project={project_id} --zone={zone} \ --mode=on --scale-in-control=max-scaled-in-replicas-percent=10,time-window=600 - Teardown Temporary Test MIGs & Templates: Delete temporary test resources
when finished (omitting
--quieton manual commands so interactive confirmation prevents accidental deletion):gcloud compute instance-groups managed delete {mig_name} --project={project_id} --zone={zone} gcloud compute instance-templates delete {template_name} --project={project_id} - Pricing Reference: Autoscaling policies incur no extra fee beyond member VM instances, disks, and Cloud Monitoring custom metric ingestion. Consult Google Cloud pricing and Compute Engine pricing for current regional rates rather than quoting hardcoded dollar figures.