A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://cloud.google.com/compute/docs/instance-groups/configuring-stateful-ip-addresses-in-migs below:

Configuring stateful IP addresses in MIGs | Compute Engine Documentation

Skip to main content Configuring stateful IP addresses in MIGs

Stay organized with collections Save and categorize content based on your preferences.

By configuring stateful IP addresses in a managed instance group (MIG), you ensure that IP addresses are preserved when VM instances in the group are autohealed, updated, and recreated.

You can preserve internal and external IPv4 addresses. You can configure IP addresses to be assigned automatically or assign specific IP addresses to each VM instance in a MIG.

Before you begin Limitations

A MIG with stateful IP addresses has the following limitations:

A MIG with stateful configuration—a stateful MIG—has the following limitations:

Pricing

You are charged for external IP addresses according to networking pricing.

Caution: Unused reserved external static IP addresses incur charges, so make sure to delete them if you don't intend to keep them for future use. When configuring stateful IPs, you can use the auto-delete rule to automatically delete a static IP address when its instance is permanently deleted. When to use stateful IP addresses

Preserving instances' IP addresses is useful in the following scenarios:

Configuring stateful IP addresses for all VMs in a group

Configuring stateful IP addresses for all VMs in a MIG is useful in the following scenarios:

To maintain static internal or external IP addresses for existing and future VM instances in the group, configure that in the stateful policy.

When you add stateful IP address configuration to the group's stateful policy, the MIG applies the configuration in the following way:

To reserve a static IP address, the MIG creates an Address resource.

Note: All VM instances have a network interface with the name nic0 and this network interface is used by default when you configure a stateful IP.

You have the option to create instances that have multiple network interfaces by setting multiple network interfaces in your group's instance template. In this case, separately specify each internal or external IP that you want to make stateful for each network interface.

Configuring stateful IP addresses on MIG creation

Use the Google Cloud console, gcloud CLI, Terraform, or REST.

Permissions required for this task

To perform this task, you must have the following permissions:

A MIG uses the Google APIs Service Agent service account to manage its instances. This service account has Editor role by default, which includes all necessary permissions for managing stateful IP addresses.

If you need to create a custom role, the following permissions are required for managing stateful network interfaces:

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Select your project and click Continue.

  3. Click Create instance group.

  4. Select New managed instance group (stateful).

  5. Specify a Name for the instance group.

  6. Select an Instance template.

  7. Under Number of instances, specify the number of instances that you want to include in the managed instance group.

  8. Under Stateful configuration, expand the External IP and the Internal IP sections to configure those IP address types as stateful.

    1. For Stateful, select Yes.
    2. In the On permanent instance deletion list, select the action to perform on the stateful IP address when the VM instance is deleted. The available options are:
      • Detach IP: (Default.) Unassign the address on instance deletion and keep the address reserved.
      • Delete IP: Delete the static IP address reservation when an instance is permanently deleted from the instance group—for example, when you delete an instance manually or decrease the group's size.
    3. After you finish the stateful configuration, click Done.
  9. Click Create.

gcloud

When creating a MIG, to specify which IP addresses in network interfaces from the instance template should be stateful, use one or multiple of the following flags with the gcloud compute instance-groups managed create command:

gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
    --template INSTANCE_TEMPLATE \
    --size SIZE \
    --instance-redistribution-type NONE \
    --stateful-internal-ip [enabled | interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    --stateful-external-ip [enabled | interface-name=NI_NAME][,auto-delete=DELETE_RULE]

Replace the following:

Example

You need to create a regional group of VM instances with static internal IP addresses for the default and custom networks and static external IP addresses only for the default network. You want the addresses to be assigned automatically, but need them to be preserved through instance autohealing, updates, and recreation events. You store instance configuration in an instance template named node-template.

To create the group, run the following command:

gcloud compute instance-groups managed create example-group \
    --region us-east1 \
    --template node-template \
    --base-instance-name node \
    --instance-redistribution-type NONE \
    --size 3 \
    --stateful-internal-ip interface-name=nic0,auto-delete=on-permanent-instance-deletion
    --stateful-internal-ip interface-name=nic1,auto-delete=on-permanent-instance-deletion
    --stateful-external-ip enabled,auto-delete=on-permanent-instance-deletion

The internal IPs within the nic0 and nic1 network interfaces and the external IP within the nic0 network interface are configured as stateful for all instances in the group. The group automatically reserves static internal and external IP addresses for each instance. Because the auto-delete flag is set to on-permanent-instance-deletion, the group will automatically delete the static IP address reservations when you delete the associated instances or the whole group.

To verify that the internal IPs within the nic0 and nic1 network interfaces and the external IP within the nic0 network interface are configured as stateful, run the following command:

gcloud compute instance-groups managed describe example-group \
    --zone us-east1-c

The output resembles the following:

baseInstanceName: node
...
name: example-group
...
statefulPolicy:
  preservedState:
    internalIPs:
      nic0:
        autoDelete: ON_PERMANENT_INSTANCE_DELETION
      nic1:
        autoDelete: ON_PERMANENT_INSTANCE_DELETION
    externalIPs:
      nic0:
        autoDelete: ON_PERMANENT_INSTANCE_DELETION
...

You can see that the group's stateful policy declares internal IPs within the nic0 and nic1 network interfaces and external IPs within the nic0 network interface as stateful with the rule to delete static IP reservations on permanent instance deletion.

Terraform

If you haven't already created an instance template, which specifies the machine type, boot disk image, network, and other VM properties that you want for each VM in your MIG, create an instance template.

When creating a MIG, to specify which IP addresses within network interfaces from the instance template should be stateful, use one or multiple of the following blocks:

The following sample configures stateful IP addresses when creating a regional MIG. For more information about the resource used in the sample, see google_compute_region_instance_group_manager resource.

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.

REST

When creating a MIG, to specify which IP addresses within network interfaces from the instance template should be stateful, include them in the statefulPolicy field in the request body of the instanceGroupManagers.insert or regionInstanceGroupManagers.insert method:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/instanceGroupManagers

{
  "name": "INSTANCE_GROUP_NAME",
  "versions": [
    {
      "instanceTemplate": "global/instanceTemplates/INSTANCE_TEMPLATE"
    }
  ],
  "targetSize": SIZE,
  "statefulPolicy": {
    "preservedState": {
      "internalIPs": {
        "NI_NAME": {"autoDelete": "DELETE_RULE" }
      },
      "externalIPs": {
        "NI_NAME": {"autoDelete": "DELETE_RULE" }
      }
    }
  },
  "updatePolicy": {
    "instanceRedistributionType": "NONE"
  }
}

Replace the following:

Example

You need to create a regional group of VM instances with static internal IP addresses for the default and custom networks and static external IP addresses only for the default network. You want the addresses to be assigned automatically, but need them to be preserved through instance autohealing, updates, and recreation events. You store instance configuration in an instance template named node-template.

To create the group, use the regionInstanceGroupManagers.insert method:

POST https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers

{
  "name": "example-group",
  "baseInstanceName": "node",
  "versions": [
    {
      "instanceTemplate": "global/instanceTemplates/node-template"
    }
  ],
  "targetSize": 3,
  "statefulPolicy": {
    "preservedState": {
      "internalIPs": {
        "nic0": {"autoDelete": "ON_PERMANENT_INSTANCE_DELETION" },
        "nic1": {"autoDelete": "ON_PERMANENT_INSTANCE_DELETION" }
      }
      "externalIPs": {
        "nic0": {"autoDelete": "ON_PERMANENT_INSTANCE_DELETION" }
      }
    }
  },
  "updatePolicy": {
    "instanceRedistributionType": "NONE"
  }
}

The internal IPs within the nic0 and nic1 network interfaces and the external IPs within the nic0 network interface are configured as stateful for all instances in the group. The group automatically reserves static internal and external IP addresses for each instance. Because the auto-delete field is set to ON_PERMANENT_INSTANCE_DELETION, the group will automatically delete the static IP address reservations when you delete associated instances or the whole group.

Use the regionInstanceGroupManagers.get method to verify that the internal IPs within the nic0 and nic1 network interfaces and external IPs within the nic0 network interface are configured in the stateful policy of the new regionInstanceGroupManagers resource:

GET https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/example-group

The response contains the configured stateful policy:

{
  "name": "example-group",
  "baseInstanceName": "node",
  ...
  "statefulPolicy": {
    "preservedState": {
      "internalIPs": {
        "nic0": {"autoDelete": "ON_PERMANENT_INSTANCE_DELETION" },
        "nic1": {"autoDelete": "ON_PERMANENT_INSTANCE_DELETION" }
      }
      "externalIPs": {
        "nic0": {"autoDelete": "ON_PERMANENT_INSTANCE_DELETION" }
      }
    }
  }
  ...
}

You can see that the group's stateful policy declares internal IPs within the nic0 and nic1 network interfaces and external IPs within the nic0 network interface as stateful with the rule to delete the associated static IP address reservations on permanent instance deletion.

Setting and updating stateful configuration for IP addresses in existing MIG

If you run a workload on a stateless MIG (a MIG without any stateful configuration) and the workload requires static IP addresses, you can configure IP addresses already assigned to the managed VM instances to become stateful. This ensures that the IP addresses of your existing VMs are preserved on instance autohealing, updates, and recreation events. You can optionally keep the static IP address reservations after the instances have been deleted.

By configuring a stateful policy for IP addresses in an existing MIG, you can do the following:

The MIG applies the updated configuration in the stateful policy automatically and asynchronously to all instances. Updates to IP address configurations in a stateful policy don't disrupt running VM instances. To learn more, read about applying stateful policy updates.

Permissions required for this task

To perform this task, you must have the following permissions:

A MIG uses the Google APIs Service Agent service account to manage its instances. This service account has Editor role by default, which includes all necessary permissions for managing stateful IP addresses.

If you need to create a custom role, the following permissions are required for managing stateful network interfaces:

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of the instance group for which you want to specify stateful IP addresses.

  3. Click Edit to modify the managed instance group.

  4. Click Stateful & per-instance configuration to expand the section.

  5. In the Group config section, click the External IP and the Internal IP that you want to make stateful.

    1. For Stateful, select Yes.
    2. In the On permanent instance deletion list, select the action to perform on the stateful IP address when the VM instance is deleted. The available options are:
      • Detach IP: (Default.) Unassign the address on instance deletion and keep the address reserved.
      • Delete IP: Delete the static IP address reservation when an instance is permanently deleted from the instance group— for example, when you delete an instance manually or decrease the group's size.
    3. After you update the stateful configuration, click Done.
    4. Click Save to complete the update.
gcloud

To specify which IP addresses should be stateful or to update the stateful IP configuration for an existing MIG, use one or multiple --stateful-internal-ip or --stateful-external-ip flags with the gcloud compute instance-groups managed update command.

gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \
    --stateful-internal-ip [enabled | interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    --stateful-external-ip [enabled | interface-name=NI_NAME][,auto-delete=DELETE_RULE]

Replace the following:

If a specified IP address is already configured in the stateful policy for a given network interface, the command updates the configuration.

Example

You need to expose a file server, running on a stateful MIG named example-fs-group, to external users through static external IP addresses. The instances in the group have ephemeral external IP addresses. You must make sure that the IP addresses are preserved on instance autohealing and updates so that external users have continuous access to the servers through the published IP addresses. You also need to keep the IP addresses reserved for continuity in the event of unintended group deletion.

Update the MIG to define the external IP addresses as stateful by using the following command:

gcloud compute instance-groups managed update example-fs-group \
    --stateful-external-ip enabled

As a result, the group promotes ephemeral external IP addresses within the nic0 network interface to static IP addresses for all managed instances asynchronously.

The external IP addresses are now preserved on instance autohealing, update, and recreation events. The associated static IP address reservations are unassigned and preserved on instance deletion because the unspecified auto-delete rule is set to never by default.

You can verify that the stateful external IP is configured in the stateful policy by running the gcloud compute instance-groups managed describe example-fs-group command.

REST

To specify which IP addresses should be stateful or to update the stateful IP configuration for an existing MIG, use the instanceGroupManagers.patch or regionInstanceGroupManagers.patch method:

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME

{
  "statefulPolicy": {
    "preservedState": {
      "internalIPs": {
        "NI_NAME": {"autoDelete": "DELETE_RULE" }
      },
      "externalIPs": {
        "NI_NAME": {"autoDelete": "DELETE_RULE" }
      }
    }
  }
}

Replace the following:

If a specified IP address is already configured in the stateful policy, the method patches the configuration.

Example

You need to expose a file server, running on a stateful MIG named example-fs-group, to external users through static external IP addresses. The instances in the group have ephemeral external IP addresses. You must make sure that the IP addresses are preserved on instance autohealing and updates so that external users have continuous access to the servers through the published network interface. You also need to keep the IP addresses reserved for continuity in the event of unintended group deletion.

Patch the MIG to define the external IP addresses as stateful:

PATCH https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/example-fs-group

{
  "statefulPolicy": {
    "preservedState": {
      "externalIPs": {
        "nic0": {"autoDelete": "NEVER" }
      }
    }
  }
}

As a result, the group promotes ephemeral external IP addresses within the nic0 network interface to static IP addresses for all managed instances asynchronously.

The external IP addresses are now preserved on instance autohealing, update, and recreation events. The associated static IP address reservations will be unassigned and preserved on instance deletion because the autoDelete rule is set to NEVER.

Verify that the external IP address is configured in the stateful policy by viewing the regionInstanceGroupManagers resource, returned by the regionInstanceGroupManagers.get method.

Declaring previously stateful IP addresses as stateless

You might need to configure a stateful IP address to become ephemeral–for example, for the following reasons:

You can remove stateful IP configuration from the group's stateful policy to declare an IP address within a given network interface as ephemeral for all managed instances.

Note: If stateful IP configuration for the same network interface is present in a per-instance configuration, the IP address remain stateful for an associated instance even if you remove its configuration from the stateful policy. In such case, to make the IP ephemeral, you must also remove the IP addresses configuration from the per-instance configuration.

When you remove stateful IP configuration from the stateful policy, the MIG removes the IP addresses automatically and asynchronously from the preserved state of all instances in the group. This operation does not disrupt running VM instances. The IP addresses remain active on the instances, but are no longer stateful. When you recreate or update the instances, or when the instances are autohealed, the MIG unassigns the associated static IP addresses and auto-assigns ephemeral addresses. If you no longer need to keep the static external IP address reservations, you can now release them.

Note: Static IP addresses remain reserved after you remove stateful IP configuration from a MIG's stateful policy. Because the stateful configuration has been removed, the group no longer manages the static IP addresses. If you don't need to keep the static IP addresses, make sure to release the reservations to avoid unnecessary charges.

To learn more, read the following documents:

Permissions required for this task

To perform this task, you must have the following permissions:

A MIG uses the Google APIs Service Agent service account to manage its instances. This service account has Editor role by default, which includes all necessary permissions for managing stateful IP addresses.

If you need to create a custom role, the following permissions are required for managing stateful network interfaces:

Console
  1. In the Google Cloud console, go to the Instance groups page.

    Go to Instance groups

  2. Click the name of the instance group from which you want to remove the stateful configuration for IP addresses.

  3. Click Edit to modify the managed instance group.

  4. Click Stateful & per-instance configuration to expand the section.

  5. In the Group config section, expand the External IP and the Internal IP that you want to make stateless.

    1. Change the Stateful option to No.
    2. Click Done.
  6. After you make the changes, click Save.

gcloud

To specify which IP addresses from a MIG's stateful policy to make ephemeral, use the --remove-stateful-internal-ips or --remove-stateful-external-ips flag with the gcloud compute instance-groups managed update command:

gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \
    --remove-stateful-internal-ips NI_NAME[,NI_NAME,...] \
    --remove-stateful-external-ips NI_NAME[,NI_NAME,...]

Replace the following:

Note: You can see the network interface names of IP addresses that are configured in a MIG's stateful policy by running the gcloud compute instance-group managed describe command.

If you need to turn a stateful IP address from the default primary network interface named nic0 into an ephemeral IP address, you can also use the following command:

gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \
    --stateful-internal-ip disabled \
    --stateful-external-ip disabled

Example

Your application has been exposed to users through published static external IP addresses of the VM instances in a MIG called example-group. You have rearchitected your service by deploying a load balancer in front of the MIG and routing the traffic to the managed VMs through it. You no longer need to maintain the static external IP addresses and would like to make the external IP addresses of the VMs ephemeral.

To make the stateful external IP addresses of the VMs in a MIG ephemeral, run the following command:

gcloud compute instance-groups managed update example-group \
    --remove-stateful-external-ips nic0

The MIG removes the static external IP addresses of the nic0 network interface automatically and asynchronously from the preserved state of all instances in the group. The external IP addresses remain active on the instances, but are no longer stateful. When you recreate or update the instances, or when the instances are autohealed, the MIG unassigns the associated static IP addresses and auto-assigns ephemeral addresses. If you no longer need to keep the static external IP address reservations, you can now release them.

REST

To specify which IP addresses from a MIG's stateful policy to make ephemeral, remove each IP's configuration from the MIG's stateful policy using the instanceGroupManagers.patch or regionInstanceGroupManagers.patch method:

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME

{
  "statefulPolicy": {
    "preservedState": {
      "internalIPs": {
        "NI_NAME": null
      },
      "externalIPs": {
        "NI_NAME": null
      }
    }
  }
}

Replace the following:

Note: You can see the network interface names of IP addresses that are configured in a MIG's stateful policy by calling the instanceGroupManagers.get or regionInstanceGroupManagers.get method.

Example

Your application has been exposed to users through published static external IP addresses of the VM instances in a MIG called example-group. You have rearchitected your service by deploying a load balancer in front of the MIG and routing the traffic to the managed VMs through it. You no longer need to maintain the static external IP addresses and would like to make the external IP addresses of the VMs ephemeral.

To make the stateful external IP addresses of the VMs in a MIG ephemeral, patch the MIG:

PATCH https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/example-group

{
  "statefulPolicy": {
    "preservedState": {
      "externalIPs": {
        "nic0": null
      }
    }
  }
}

The MIG removes the static external IP addresses of the nic0 network interface automatically and asynchronously from the preserved state of all instances in the group. The external IP addresses remain active on the instances, but are no longer stateful. When you recreate or update the instances, or when the instances are autohealed, the MIG unassigns the associated static IP addresses and auto-assigns ephemeral addresses. If you no longer need to keep the static external IP address reservations, you can now release them.

Configuring stateful IP addresses individually for VMs in a MIG

Configuring stateful IP addresses individually for VMs in a MIG is useful in the following scenarios:

Pro Tip: Where feasible, consider configuring and auto-assigning stateful IP addresses for all VM instances in a MIG, instead of assigning specific IP addresses individually to each instance. Maintaining a group's stateful policy is less work compared to maintaining a set of individual per-instance configurations.

Note: All VM instances have a network interface with the name nic0 and this network interface is used by default when you configure a stateful IP.

You have the option to create instances that have multiple network interfaces by setting multiple network interfaces in your group's instance template. In this case, separately specify each network interface that you need to make stateful.

Configuring static IP addresses on VM creation in a MIG

You can reserve and assign static IP addresses to specific instances when individually creating those instances in a MIG. This is useful for migrating a stateful application from existing standalone VMs to a stateful MIG in a situation when architecture, configuration, or users rely on specific static IP addresses.

When you manually create an instance in a MIG and supply a static IP address, the MIG performs the following actions:

  1. Creates a static internal or external IP address reservation for the supplied IP addresses if they don't exist yet.
  2. Creates an instance from the instance template using the provided instance name and IP addresses.
  3. Creates a per-instance configuration with the provided stateful configuration for the IP addresses.
Permissions required for this task

To perform this task, you must have the following permissions:

A MIG uses the Google APIs Service Agent service account to manage its instances. This service account has Editor role by default, which includes all necessary permissions for managing stateful IP addresses.

If you need to create a custom role, the following permissions are required for managing stateful network interfaces:

gcloud

To create an instance with a predefined static IP address, use the gcloud compute instance-groups managed create-instance command with one or multiple of the following flags:

gcloud compute instance-groups managed create-instance INSTANCE_GROUP_NAME \
    --instance INSTANCE_NAME \
    --stateful-internal-ip address=ADDRESS[,interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    --stateful-external-ip address=ADDRESS[,interface-name=NI_NAME][,auto-delete=DELETE_RULE]

Replace the following:

Example

You need to add one more VM instance to your proxy server cluster, running on a MIG named proxy-cluster. You have created a static internal IP address reservation named proxy-node-03-ip and need to assign it to the new node. You want to keep the IP address reservation even if you decide to delete the node in the future.

Run the following command to create the node:

gcloud compute instance-groups managed create-instance proxy-cluster \
    --instance proxy-node-03 \
    --stateful-internal-ip address="projects/example-project/regions/us-east1/addresses/proxy-node-03-ip",auto-delete=never

The command creates an instance named proxy-node-03, assigns the provided static internal IP address named proxy-node-03-ip to the instance, and stores stateful configuration for the IP in the corresponding per-instance configuration. Because the auto-delete flag is set to never, the IP remains reserved if you delete the instance later.

Terraform

To create a VM with a predefined static IP address, use one or multiple of the following blocks:

The following sample configures static IP addresses on VM creation in a regional MIG. For more information about the resource used in the sample, see google_compute_region_per_instance_config resource. For a zonal MIG, use the google_compute_per_instance_config resource.

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.

REST

To create one or multiple instances in a MIG, set custom instance names, and assign predefined static IP addresses to these instances, use the instanceGroupManagers.createInstances or regionInstanceGroupManagers.createInstances method.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/createInstances

{
  "instances": [
    {
      "name": "INSTANCE_NAME",
      "preservedState" : {
        "internalIPs": {
          "NI_NAME" : {
            "ipAddress": {
              "address": "ADDRESS",
              "literal": "LITERAL"
            },
            "autoDelete": "DELETE_RULE"
          },
          ...
        },
        "externalIPs": {
          "NI_NAME" : {
            "ipAddress": {
              "address": "ADDRESS",
              "literal": "LITERAL"
            },
            "autoDelete": "DELETE_RULE"
          },
          ...
        },
        ...
      }
    },
    ...
  ]
}

Replace the following:

Example

You need to add one more VM instance to your proxy server cluster, running on a MIG named proxy-cluster. You have created a static internal IP address reservation named proxy-node-03-ip and need to assign it to the new node. You want to keep the IP address reservation even if you decide to delete the node in the future.

Call the regionInstanceGroupManagers.createInstances method to create an additional instance:

POST https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/proxy-cluster/createInstances

{
  "instances": [
    {
      "name": "proxy-node-03",
      "preservedState" : {
        "internalIPs": {
          "nic0" : {
            "ipAddress": {
              "address": "projects/example-project/regions/us-east1/addresses/proxy-node-03-ip"
            },
            "autoDelete": "NEVER"
          }
        }
      }
    }
  ]
}

The method creates an instance named proxy-node-03, assigns the provided static internal IP address named proxy-node-03-ip to the instance, and stores stateful configuration for the IP in the corresponding per-instance configuration. Because the autoDelete field is set to NEVER, the IP remains reserved if you delete the instance later.

Configuring static IP addresses for an existing VM in a MIG

You can set a predefined static IP address or update the stateful IP configuration for a managed instance individually–for example:

For an existing instance without an external IP address, for which you configure an external stateful IP, the MIG adds access configuration to the corresponding network interface with the following default values:

"accessConfigs": [
  {
    "kind": "compute#accessConfig",
    "name": "External Nat",
    "natIP": "XX.XX.XX.XX",
    "networkTier": "PREMIUM",
    "type": "ONE_TO_ONE_NAT"
  }
]
Note: If you need to promote ephemeral IP addresses to static IP addresses for all instances in an existing MIG, configure the corresponding IP addresses to be stateful for the entire MIG in a stateful policy. The group will then promote the ephemeral IP addresses to static for all instances.

If you need to promote the ephemeral IP address of an individual instance in an existing MIG, specify the literal value of the ephemeral IP address (e.g. "130.211.181.55").

Permissions required for this task

To perform this task, you must have the following permissions:

A MIG uses the Google APIs Service Agent service account to manage its instances. This service account has Editor role by default, which includes all necessary permissions for managing stateful IP addresses.

If you need to create a custom role, the following permissions are required for managing stateful network interfaces:

gcloud

To configure a stateful IP address individually for a VM instance in a MIG, add or update stateful IP configuration in the associated per-instance configuration.

If a per-instance configuration doesn't yet exist for the instance, use the gcloud compute instance-groups managed instance-configs create command with one or multiple of the following flags:

gcloud compute instance-groups managed instance-configs create INSTANCE_GROUP_NAME \
    --instance INSTANCE_NAME \
    --stateful-internal-ip address=ADDRESS[,interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    --stateful-external-ip address=ADDRESS[,interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    [--no-update-instance | --update-instance]
    [--instance-update-minimal-action MINIMAL_ACTION]

If a per-instance configuration already exists for the instance, use the gcloud compute instance-groups managed instance-configs update command with one or multiple --stateful-internal-ip or --stateful-external-ip flags:

gcloud compute instance-groups managed instance-configs update INSTANCE_GROUP_NAME \
    --instance INSTANCE_NAME \
    --stateful-internal-ip address=ADDRESS[,interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    --stateful-external-ip address=ADDRESS[,interface-name=NI_NAME][,auto-delete=DELETE_RULE] \
    [--no-update-instance | --update-instance]
    [--instance-update-minimal-action MINIMAL_ACTION]

Replace the following:

If omitted, the least disruptive action required by the update is used.

Example

You have a file server instance called file-server, which is a single instance in a stateful MIG called fs-group. The group has a corresponding per-instance configuration, where a stateful data disk is configured. The file server has only been accessible internally, but now you have users who need to access it externally through a static IP address. You have reserved the static external IP by creating file-server-ip address reservation. Now you need to assign this IP to the file server instance.

Run the following command to configure the stateful external IP for the file server instance:

gcloud compute instance-groups managed instance-configs update fs-group \
    --instance file-server \
    --stateful-external-ip interface-name=nic0,address="projects/example-project/regions/us-east1/addresses/file-server-ip",auto-delete=never \
    --update-instance

The command does the following:

  1. Updates the per-instance configuration for the file-server instance:
    1. Adds stateful external IP configuration, pointing to the file-server-ip address reservation.
    2. Keeps the existing stateful data disk configuration unchanged.
  2. Applies the per-instance configuration update to the file-server instance immediately because the --update-instance flag is included: refreshes the instance and assigns the static external IP address from file-server-ip reservation.
REST

To configure stateful IPs individually for VM instances in a MIG, add or update the stateful IP configuration in the associated per-instance configurations.

If per-instance configurations don't yet exist for the given instances, use the instanceGroupManagers.updatePerInstanceConfigs method or regionInstanceGroupManagers.updatePerInstanceConfigs method with stateful configuration for one or multiple IP addresses:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/updatePerInstanceConfigs

{
  "perInstanceConfigs": [
    {
      "name": "INSTANCE_NAME",
      "preservedState" : {
        "internalIPs": {
          "NI_NAME" : {
            "ipAddress": {
              "address": "ADDRESS",
              "literal": "LITERAL"
            },
            "autoDelete": "DELETE_RULE"
          },
          ...
        },
        "externalIPs": {
          "NI_NAME" : {
            "ipAddress": {
              "address": "ADDRESS",
              "literal": "LITERAL"
            },
            "autoDelete": "DELETE_RULE"
          },
          ...
        },
        ...
      },
      "fingerprint: "FINGERPRINT"
    },
    ...
  ]
}
Note: While you can use the updatePerInstanceConfigs method for updating existing per-instance configurations, this method fully replaces the specified per-instance configurations with new values. We recommend you use the patchPerInstanceConfigs method to update existing per-instance configurations, as patching keeps the omitted configuration unchanged and prevents the risk of accidental deletion of stateful items or reset of any values to defaults.

If per-instance configurations already exist for the given instances, use the instanceGroupManagers.patchPerInstanceConfigs method or regionInstanceGroupManagers.patchPerInstanceConfigs method with stateful configuration for one or multiple IP addresses:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/patchPerInstanceConfigs

{
  "perInstanceConfigs": [
    {
      "name": "INSTANCE_NAME",
      "preservedState" : {
        "internalIPs": {
          "NI_NAME" : {
            "ipAddress": {
              "address": "ADDRESS",
              "literal": "LITERAL"
            },
            "autoDelete": "DELETE_RULE"
          },
          ...
        },
        "externalIPs": {
          "NI_NAME" : {
            "ipAddress": {
              "address": "ADDRESS",
              "literal": "LITERAL"
            },
            "autoDelete": "DELETE_RULE"
          },
          ...
        },
        ...
      },
      "fingerprint: "FINGERPRINT"
    },
    ...
  ]
}

Replace the following:

The updatePerInstanceConfigs and patchPerInstanceConfigs methods update the specified per-instance configurations but don't apply the configuration updates to the associated managed instances. The changes are applied to an instance when the MIG is instructed to recreate or update the instance. You can apply the update manually to apply the changes to an instance.

Example

You have a file server instance called file-server, which is a single instance in a stateful MIG called fs-group. The group has a corresponding per-instance configuration, where a stateful data disk is configured. The file server has only been accessible internally, but now you have users who need to access it externally through a static IP address. You have reserved the static external IP by creating file-server-ip address reservation. Now you need to assign this IP to the file server instance.

To update the per-instance configuration for file-server with the new stateful external IP, call the patchPerInstanceConfigs method:

POST https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/fs-group/patchPerInstanceConfigs

{
  "perInstanceConfigs": [
    {
      "name": "file-server",
      "preservedState" : {
        "externalIPs": {
          "nic0" : {
            "ipAddress": {
              "address": "projects/example-project/regions/us-east1/addresses/file-server-ip"
            },
            "autoDelete": "NEVER"
          }
        }
      }
    }
  ]
}

The method patches the per-instance configuration for file-server instance:

  1. Adds stateful external IP configuration, pointing to the file-server-ip address reservation.
  2. Keeps the existing stateful data disk configuration unchanged.

The configuration update is not yet applied to the file-server VM instance. The MIG will apply the configuration update when you recreate or apply the update to the instance later.

To apply the per-instance configuration update to file-server VM instance, call the regionInstanceGroupManagers.applyUpdatesToInstances method for the instance:

POST https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/gs-group/applyUpdatesToInstances

{
  "instances": ["/zones/us-east1-b/instances/file-server"]
}

The method assigns the configured static external IP address from file-server-ip reservation to the managed instance. The method refreshes the file-server instance to assign an external IP address.

Because autoDelete is set to NEVER in the stateful IP configuration, the IP will remain reserved if you delete the instance later.

Disassociating static IP addresses from an existing VM in a MIG

You might need to disassociate a static IP address from an existing VM, making the network interface ephemeral for the VM. This is useful in the following scenarios:

You can disassociate a static IP address from an existing VM in MIG and make the IP address ephemeral for an individual VM by removing the IP's stateful configuration from the associated per-instance configuration or deleting the entire per-instance configuration if it doesn't contain any other state. Applying the change has the following effects:

Note: If stateful IP configuration for the same network interface is present in the group's stateful policy, the IP address remains stateful for the instance even if you remove its configuration from the per-instance configuration. In such a case, you should also remove the IP addresses configuration from the stateful policy to make the IP ephemeral.

Removing a stateful IP configuration from a per-instance configuration does not disrupt running VM instances, unless you explicitly choose to do so.

To learn more, see the following documents:

Permissions required for this task

To perform this task, you must have the following permissions:

A MIG uses the Google APIs Service Agent service account to manage its instances. This service account has Editor role by default, which includes all necessary permissions for managing stateful IP addresses.

If you need to create a custom role, the following permissions are required for managing stateful network interfaces:

gcloud

To remove a stateful IP configuration from the associated per-instance configuration, use the gcloud compute instance-groups managed instance-configs update command with the --remove-stateful-internal-ips or --remove-stateful-external-ips flags:

gcloud compute instance-groups managed instance-configs update INSTANCE_GROUP_NAME \
    --instance INSTANCE_NAME \
    --remove-stateful-internal-ips NI_NAME[,NI_NAME,...] \
    --remove-stateful-external-ips NI_NAME[,NI_NAME,...]
    [--no-update-instance | --update-instance] \
    [--instance-update-minimal-action MINIMAL_ACTION]

Replace the following:

Example

Your application has been exposed to users through specific published static external IP addresses of the VM instances in a MIG called example-group. You have rearchitected your service by deploying a load balancer in front of the MIG and routing the traffic to the managed VMs through it. You no longer need to maintain the static external IP addresses and would like to make the external IP addresses of the VMs ephemeral.

To make the stateful external IP addresses of the VMs in a MIG ephemeral, run the following command for each instance, for example, for node-1:

gcloud compute instance-groups managed instance-configs update example-group \
    --instance node-1 \
    --remove-stateful-external-ips nic0 \
    --update-instance

The command does the following:

  1. Removes stateful configuration for the external IP address within the nic0 network interface from the per-instance configuration for node-1.
  2. Applies the per-instance configuration update to node-1 VM instance immediately because the --update-instance flag is included. The VM instance is not disrupted and keeps serving from the same IP, which is no longer stateful. The MIG removes the reference to static IP reservation from the managed instance's preservedStateFromConfig and treats the external IP address as ephemeral. The MIG will auto-assign an external IP on subsequent instance recreation, update, or autohealing events.
  3. After having been unassigned, the original static IP remains reserved. You can release the IP if you no longer need it.
REST

To remove a stateful IP configuration from the associated per-instance configuration, use the instanceGroupManagers.patchPerInstanceConfigs method or regionInstanceGroupManagers.patchPerInstanceConfigs method:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/patchPerInstanceConfigs

{
  "perInstanceConfigs": [
    {
      "name": "INSTANCE_NAME",
      "preservedState" : {
        "internalIPs": {
          "NI_NAME" : null
        },
        "externalIPs": {
          "NI_NAME" : null
        }
      },
      "fingerprint: "FINGERPRINT"
    },
    ...
  ]
}

Replace the following:

The patchPerInstanceConfigs method updates the specified per-instance configurations but does not apply the configuration updates to the associated managed instances. The changes are applied to an instance when the MIG is instructed to recreate or update the instance. You can apply the update manually to apply the changes to an instance.

Example

Your application has been exposed to users through specific published static external IP addresses of the VM instances in a MIG called example-group. You have rearchitected your service by deploying a load balancer in front of the MIG and routing the traffic to the managed VMs through it. You no longer need to maintain the static external IP addresses and would like to make the external IP addresses of the VMs ephemeral.

To make the stateful external IP addresses of the VMs in a MIG ephemeral, run the following method for each instance, for example, for node-1, and provide null value to the network interface's stateful configuration:

POST https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/example-group/patchPerInstanceConfigs

{
  "perInstanceConfigs": [
    {
      "name": "node-1",
      "preservedState" : {
        "externalIPs": {
          "nic0" : null
        }
      }
    }
  ]
}

The method removes configuration for the stateful IP address within nic0 network interface from the per-instance configuration for node-1. The configuration update is not yet applied to the node-1 VM instance. The MIG applies the configuration update on the next instance recreation or update.

To apply the per-instance configuration update to the node-1 VM instance, run the regionInstanceGroupManagers.applyUpdatesToInstances method for the instance:

POST https://compute.googleapis.com/compute/v1/projects/example-project/regions/us-east1/instanceGroupManagers/example-group/applyUpdatesToInstances

{
  "instances": ["/zones/us-east1-c/instances/node-1"]
}

The MIG removes the reference to static IP reservation from the preservedStateFromConfig field for the node-1 instance and treats the IP address as ephemeral. The MIG will auto-assign an external IP on subsequent instance recreation, update, or autohealing events.

After having been unassigned, the original static IP remains reserved. You can release the IP if you no longer need it.

Removing stateful configuration

To remove configuration from a stateful policy for all VMs in a MIG, see the following documents:

To remove configuration from a per-instance configuration for a specific VM in a MIG, see the following documents:

Cleaning up unused static IP addresses

When configuring stateful IP address for managed instances in a group, you can choose whether to release the associated static IP address reservations manually or automatically when an instance is permanently deleted:

If you have instructed the MIG to never delete the associated IP reservations, the static IP addresses remain reserved after the corresponding instances or the MIG ceases to exist.

Feedback

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

What's next

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

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Stateful IP addresses in managed instance groups (MIGs) ensure that both internal and external IPv4 addresses are preserved during VM autohealing, updates, and recreation, either automatically or specifically assigned."],["Stateful configurations can be applied to all VMs in a group, where the MIG manages static IP assignments, or individually to specific VMs, allowing for the assignment of specific static IPs."],["Several configuration methods are available, including the Google Cloud Console, `gcloud` CLI, Terraform, and REST API, each with specific commands and parameters to manage stateful IP settings for new and existing MIGs and VMs."],["Stateful IP configurations can be removed to make IPs ephemeral, but the previously assigned static IPs remain reserved and require manual release unless an auto-delete policy is configured."],["Proper permissions are crucial for managing stateful IP addresses, whether using default or custom roles, and include permissions for creating, using, and deleting addresses, as well as managing subnetworks and network users."]]],[]]


RetroSearch 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