Configuring stateful MIGs


You can improve the uptime and resiliency of your stateful applications with stateful managed instance groups (stateful MIGs).

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

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

After you create or update a stateful configuration, you can apply it to make it effective, view the configuration as well as the effective preserved state of each VM, or remove it if you no longer need it.

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

Before you begin

  • Review When to use stateful MIGs
  • Review What makes a MIG stateful
  • For more information, see How stateful MIGs work
  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    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

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. 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, then initialize it by running the following command:

      gcloud init

Limitations

A MIG with stateful configuration—a stateful 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 the replacement method to RECREATE.
  • For stateful regional MIGs, you must disable proactive redistribution (set the redistribution type to NONE) to prevent deletion of stateful instances by automatic cross-zone redistribution.
  • If you use an all-instances configuration to override instance template properties, you cannot specify those properties in any per-instance configuration and at the same time in the group's all-instances configuration.

  • A stateful regional MIG does not automatically orchestrate cross-zone failover. When using a regional MIG, you can make your stateful application resilient to zonal failure by deploying redundant replicas to multiple zones and relying on your application's data replication functionality.

  • When you permanently delete an instance (either manually or by resizing), the MIG does not preserve the instance's stateful metadata.

Setting and preserving instance names

A MIG always preserves the names of its VM instances, unless you permanently delete the instances by decreasing the group size or by performing a rolling update that substitutes existing instances with new ones.

If you want to preserve instance names during updates, set the replacement method for the update to RECREATE in the group's update policy.

You can specify custom names by creating 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 from autohealing and auto-updating, while preserving their names.
  • Deploying architectures where external dependencies rely on specific VM names, for example, a primary VM that keeps a registry of working nodes 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 the base instance name plus a random suffix.

Configuring and managing stateful persistent disks

Configuring persistent disks to be stateful lets you benefit from VM autohealing and controlled updates while preserving the state of the disks. For more information, see the use cases for stateful MIGs.

For instructions, see Configuring stateful persistent disks.

Configuring stateful metadata

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

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

For instructions, see Configuring stateful metadata.

Configuring and managing stateful IP addresses

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

For instructions, see Configuring 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 effective preserved state of your managed instances.
  • Remove the stateful configuration.

For instructions, see Applying, viewing, and removing stateful configuration.

Feedback

We want to learn about your use cases, challenges, and feedback about stateful MIGs. Please share your feedback with our team at mig-discuss@google.com.

What's next