You can build highly available deployments of stateful workloads on VM instances using stateful managed instance groups (stateful MIGs). Stateful workloads include applications with stateful data or configurations such as databases, legacy monolith applications, and long-running batch computations with checkpointing.
With stateful MIGs, you can improve the uptime and resiliency of such stateful applications with autohealing (automatic recovery of failed workloads), multi-zone deployments, and automated rolling updates.
A stateful managed instance group preserves the unique state of each instance (including instance name, attached persistent disks, IP addresses, and metadata) on VM restart, recreation, autohealing, or update.
This page describes when to use stateful MIGs and provides a high-level overview of how they work. For more information, see How stateful MIGs work.
To learn how to set up a stateful MIG, see Configuring stateful MIGs.
How stateful workloads are different from stateless workloadsYou can use managed instance groups to support both stateful and stateless workloads. The key difference between stateful and stateless workloads is that stateful workloads preserve individual VM state (for example, a database shard, or app configuration) on the VM's disks, while stateless workloads, like a web frontend, don't retain any state on the individual VMs.
You treat VMs with stateful workloads like custom-built machinery: you care about VM identity (name), IP address, metadata, and data on each individual machine. You cannot easily scale stateful workloads horizontally because scaling could require data replication, creation or deletion of data shards, or changing the overall application configuration. When recreating or updating a machine with a stateful workload, you must preserve the VM's unique state. Examples of stateful applications include Cassandra, ElasticSearch, mongoDB, MySQL, PostgreSQL, and Kafka.
You treat VMs with stateless workloads as interchangeable and only care about the number of serving VMs that you have. No one VM is treated any differently than another. You can quickly scale stateless workloads horizontally by adding or removing VMs. When updating your application, you can delete machines and replace them with new ones with different names, IP addresses, metadata, and disks. When a stateless VM is deleted or recreated, all data on the machine is lost: the disks are deleted or recreated from scratch. A web frontend is an example of a stateless application.
Stateful MIG Stateless MIG Workload Stateful workloads where disks, IP addresses, and/or metadata are preserved on VM recreate operations. Highly available and scalable stateless workloads, where disks and IP addresses are recreated from scratch on horizontal scaling, autohealing, auto-updating, and VM recreation. MIG featuresAll MIGs support custom and preservable instance names.
When to use stateful MIGsConsider using stateful managed instance groups (stateful MIGs) whenever you deploy a stateful application or cluster to Compute Engine and would like to improve its availability with autohealing and multi-zone deployments, or you want to simplify updates of stateful instances by orchestrating update rollouts and controlling the allowed level of disruption to the instances.
Stateful MIGs are intended for applications with stateful data or configuration, such as:
To achieve resilience against zonal failure, your application must replicate data across multiple instances at the application level. For example, ElasticSearch and Cassandra support such functionality. You can use a regional MIG to make such an application resilient to zonal failure by deploying redundant replicas to multiple zones and relying on your application's data replication functionality. In the event of a zonal failure, your data is served from available replicas in the remaining zones.
Review the limitations to verify if a stateful MIG fully meets your requirements.
Note: Your workload must start automatically on VM boot so that it can continue serving or computing after autohealing, auto-updating, and instance recreation events. What makes a MIG statefulA MIG is considered stateful if you have created a stateful configuration.
You can create a stateful configuration when you create your MIG, or you can convert a group from stateless to stateful after its creation by adding a configuration.
You create a stateful configuration by setting a non-empty stateful policy or one or more non-empty per-instance configurations:
The configuration is effective after you or the MIG applies it:
After the stateful configuration (stateful policy or per-instance configurations) is applied, you can verify it by inspecting the preserved state of each managed instance.
Subsequent changes to your MIG's stateful configuration or size (for example, decreasing the MIG's size, or deleting or abandoning instances from the MIG) can affect the preserved states of the instances.
Stateful configurationA stateful managed instance group (MIG) takes its instance configuration from a combination of the instance template, optional all-instances configuration, optional stateful policy, and optional per-instance configurations that you set. After you set the configuration for your group, the MIG uses that configuration when creating VMs. To apply an updated configuration to existing VMs, see Apply new VM configurations in a MIG.
Note: If you only need to preserve VM instance names, you don't need to configure a stateful policy or per-instance configurations:RECREATE
.A stateful policy defines common stateful items for all instances in a managed instance group. Each item that you include in the stateful policy must be defined in the MIG's instance template.
You can make the following changes to a stateful policy:
A per-instance configuration defines stateful items that are unique for a specific managed instance, such as instance-specific disks, metadata key-value pairs, and IP addresses. Instance-specific metadata and disks don't need to be defined in the MIG's instance template; however, network interfaces for stateful IPs must be defined in the MIG's instance template.
You can make the following changes to a per-instance configuration for a specific instance in a MIG:
Here is an example of a stateful configuration:
In this chart:
data-disk
, which are defined by the instance template, and which are created and attached individually to each VM instance in the MIG.node-1
. It specifies to attach an existing disk, my-legacy-1
, to the node-1
instance and treat it as stateful. It also specifies one metadata key value to preserve individuality for the node-1
instance: node-id:xyz273
.When creating the node-1
VM, the MIG does the following:
n2-standard-2
machine type, according to the instance template.boot-node-1
, and device name boot-disk
, using a Debian GNU/Linux image, according to the instance template. The MIG treats the boot-node-1
boot disk as stateless because it isn't configured in the stateful policy or in the per-instance configuration.data-disk-1
, and device name, data-disk
, using a custom image, according to the instance template. The MIG treats the data-disk-1
additional disk as stateful because its device name is specified in the stateful policy.my-legacy-1
, and uses device name, legacy-disk
, according to the per-instance configuration. The MIG treats the my-legacy-1
additional disk as stateful because its device name is specified in the per-instance configuration.app:example-stateful-app
, version:1.0
) and one from the per-instance config (node-id:xyz273
). The MIG treats the node-id:xyz273
key-value pair as stateful because it is specified in the per-instance configuration.When recreating the node-1
VM, assuming the same config is still effective, the MIG recreates the stateless items and preserves the stateful items:
Recreates the boot disk from the original image:
First, it deletes the boot-node-1
boot disk, and then it recreates it from the Debian GNU/Linux image, as specified in the instance template.
Preserves additional disks, data-disk-1
and my-legacy-1
:
Detaches the additional disks before deleting the VM, and then attaches them to the VM after it has been recreated.
Preserves the individual metadata key-value pair, node-id:xyz273
:
Sets the metadata after the VM has been recreated. Also sets the common key-value pairs from the instance template (app:example-stateful-app
and version:1.0
).
We want to learn about your use cases, challenges, and feedback about stateful MIGs. We invite you to share your feedback with our team at mig-discuss@google.com.
What's nextRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4