Configuring stateful MIGs Stay organized with collections Save and categorize content based on your preferences.
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:
- Setting and preservinginstance names
- Configuring and managing statefulpersistent disks
- Configuring and managing statefulmetadata
- Configuring and managing statefulIP addresses
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
- ReviewWhen to use stateful MIGs
- ReviewWhat makes a MIG stateful
- For more information, seeHow stateful MIGs work
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
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 methodto
RECREATE. - For stateful regional MIGs, you mustdisable proactive redistribution (set the redistribution type to
NONE) 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
- Create VMs with specific namesin a MIG.
- Configure stateful persistent disksfor all VMs or for specific VMs in a MIG.
- Configure stateful metadatafor VMs in a MIG.
- Configuring stateful IP addressesfor all VMs or for specific VMs in a MIG.
- Apply, view, or removeyour stateful configuration.
- Learn more aboutMIGsandworking with managed instances.
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.