Configuring stateful MIGs

You can improve the uptime and resiliency of yourstateful applicationswithstateful managed instance groups(stateful MIGs).

By creating astateful configuration,you can preserve the unique state of each of your MIG's Virtual Machine (VM)instances—including name, persistent disks, and metadata—on machinerestart, recreation, auto-healing, or update events.

This page describes ways you can configure stateful MIGs, along with links tothe guides for each task:

After you create or update a stateful configuration, you canapplyit to make it effective,viewthe configuration as well as the effective preserved state of each VM, orremoveit if you no longer need it.

If you have an existing stateful application on standalone (unmanaged)Compute Engine VMs, also see the guide toMigrate an existing workload to a stateful MIG.

Before you begin

Limitations

A MIG withstateful configuration—astateful MIG—has the following limitations:

  • You cannot use autoscaling if your MIG has stateful configuration.
  • If you want to use automated rolling updates, you must set thereplacement methodtoRECREATE.
  • For stateful regional MIGs, you mustdisable proactive redistribution (set the redistribution type toNONE) to prevent deletion of statefulinstances by automatic cross-zone redistribution.
  • If you use anall-instances configurationto override instance template properties, you cannot specify those propertiesin any per-instance configuration and at the same time in the group'sall-instances configuration.

  • A stateful regional MIG does not automatically orchestrate cross-zonefailover. When using a regional MIG, you can make your stateful applicationresilient to zonal failure by deploying redundant replicas tomultiple zones and relying on your application's data replicationfunctionality.

  • When you permanentlydeletean instance (either manually or by resizing), the MIG does not preservethe instance's stateful metadata.

Setting and preserving instance names

A MIG always preserves the names of its VM instances, unlessyou permanentlydeletethe instances by decreasing the group size or by performing a rolling updatethat substitutes existing instances with new ones.

If you want to preserve instance names during updates, set thereplacement methodfor the update toRECREATE in the group's update policy.

You can specify custom names bycreating instances manually or you can let the MIG autogenerate names for its VMs.

Setting custom VM names is useful for:

  • Migrating existing standalone VMs to a stateful MIG to benefit fromautohealing and auto-updating, while preserving their names.
  • Deploying architectures where external dependencies rely on specificVM names, for example, a primary VM that keeps a registry of workingnodes based on pre-configured names or using a special naming pattern.
  • Deploying legacy configurations that require specific VM names,for example, because the names are hardcoded.

In all other cases, you can let the MIG autogenerate VM names using thebase instance name plus a random suffix.

Configuring and managing stateful persistent disks

Configuring persistent disks to be stateful lets you benefit from VMautohealing andcontrolled updates while preserving the state of the disks. For more information, see theuse cases for stateful MIGs.

For instructions, seeConfiguring stateful persistent disks.

Configuring stateful metadata

You can use instancemetadata to set properties for and communicate with your applications through themetadata server. For example, you can use metadata to configure theidentity of the VM, environment variables, information about clusterarchitecture, or data range this VM is responsible for.

By using stateful metadata you ensure that instance-specific metadata ispreserved on instance autohealing, update, and recreate events.

For instructions, seeConfiguring stateful metadata.

Configuring and managing stateful IP addresses

You can configure a managed instance group (MIG) to preserveIPaddresses on instance autohealing, update, andrecreation events by declaring them stateful. Both internal and external IPaddresses can be preserved. You can configure IP addresses to be assignedautomatically or assign specific IP addresses to each VM instance in a MIG.

For instructions, seeConfiguring stateful IP addresses.

Applying, viewing, and removing stateful configuration

After you configure a MIG to be stateful, you can:

  • Apply the stateful configuration for it to take effect.
  • View the stateful configuration as well as the effectivepreserved stateof your managed instances.
  • Remove the stateful configuration.

For instructions, seeApplying, viewing, and removing stateful configuration.

Feedback

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

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.