Skip to content

Google Cloud Managed Instance Groups Stateful

Step-01: Introduction

  1. Instance Group: An instance group is a collection of virtual machine (VM) instances that you can manage as a single entity.
  2. Instance Groups Types
    1. Unmanaged Instance Group
    2. Load Balancing
    3. Managed Instance Group (Stateless)
    4. Autoscaling
    5. Autohealing
    6. Auto-updating
    7. Multi-Zone Deployment
    8. Load Balancing
    9. Managed Instance Group (Stateful)
    10. Autohealing and updating
    11. Disk and Metadata Preservation
    12. Multi-Zone Deployment
    13. Load Balancing
  3. In this demo, we are going to focus on Managed Instance Groups - Stateful

Step-02: Create Health Check

  • What is Health Check?
    1. A health check determines whether a VM instance is healthy by sending requests to the instance.
    2. An instance is considered healthy if it returns consecutive responses within a specified time.
    3. Health checks are used for load balancing and autoscaling managed instance groups
  • Go to Compute Engine -> Instance Groups -> Health Checks -> CREATE HEALTH CHECK
  • Name: app1-health-check
  • Description:
  • Scope: Regional
  • Region: us-central-1 (IOWA)
  • Protocol: HTTP
  • Port: 80
  • Proxy Protocol: None
  • Request Path: /app1/status.html
  • Response: App1
  • Host HTTP Header: leave empty (leave to defaults)
  • Logs: Off (leave to defaults) If enabled Cloud Logging cost is going to be high
  • Health Criteria: Leave to defaults
    # Create Health Check
    gcloud compute health-checks create http app1-health-check \
       --project=gcplearn9 \
       --port=80 \
       --request-path=/index.html \
       --proxy-header=NONE \
       --response=App1 \
       --region=us-central1 \
       --no-enable-logging \
       --check-interval=10 \
       --timeout=5 \
       --unhealthy-threshold=3 \
       --healthy-threshold=2
    
  • Click on CREATE

Step-03: Create a firewall rule to allow health check probes to connect to your app

  • Health check probes come from addresses in the ranges 130.211.0.0/22 and 35.191.0.0/16, so make sure your firewall rules allow the health check to connect. For this example, the MIG uses the default network, and its VMs listen on port 80. If port 80 isn't already open on the default network, create a firewall rule.
    # Create Firewall rule
    gcloud compute firewall-rules create allow-health-check \
        --allow tcp:80 \
        --source-ranges 130.211.0.0/22,35.191.0.0/16 \
        --network default
    

Step-04: Create Instance Template with additional persistent disk

  • Go to Compute Enginer -> Virtual Machines -> Instance Templates -> Create Instance Template
  • Name: mig-it-stateful
  • Location: Regional
  • Region: us-central1
  • Machine Configuration:
  • Series: E2
  • Machine Type: e2-micro
  • Availability Policies:
  • VM Provisioning Model: Standard
  • Display Device: unchecked (leave to default)
  • Confidential VM Service: unchecked (leave to default)
  • Container: unchecked (leave to default)
  • Boot Disk: Leave to defaults
  • Identity and API Access:
  • Service Account: Compute Engine default Service Account
  • Access Scopes: Allow default Access
  • Firewall
  • Allow HTTP Traffic
  • Advanced Options
  • Management:
    • Description: demo4-vm-startupscript
    • Reservations: Automatically use created reservation (leave to default)
    • Automation:
    • Startup Script: Copy paste content from webserver-install.sh file
  • CLick on disks
  • Additional disks: Click on Add new disk
  • Name: autogenerated
  • Description: persistent-disk-1
  • Type: Balanced persistent disk
  • Source type: Blank disk
  • Mode: Read/Write
  • Deletion rule: Keep disk / Delete disk (Even if we put delete disk also when we create stateful MIG, this setting will be override)
  • Size(GB): 12
  • Device name: Custom
  • name: persistent-disk-1
  • Click on Done
  • Click on CREATE

Step-05: Create Managed Instance Group Stateful Single Zone

Persistent Disks

  • Disk will be preserved during VM lifetime. It will be reattached on instance recreation, autohealing, and update events, and deleted on permanent instance deletion.

Persistent Internal and External IPs

  • IP will be preserved during VM lifetime. It will be reattached on instance recreation, autohealing, and update events, and deleted on permanent instance deletion.

Create Managed Instance Group - Stateful

  • Name: mig-stateful
  • Description: mig-stateful
  • Location: Single Zone
  • Region: us-central1
  • Zone: us-central1-a
  • Instance Template: mig-it-stateful
  • Number of Instances: 2
  • Stateful configuration:
  • Persistent-disk-1:
  • DEVICE NAME: persistent-disk-1
  • Stateful: YES
  • On permanent instance deletion: Detach disk
  • Yes: Disk will be preserved during VM lifetime. It will be reattached on instance recreation, autohealing, and update events, and deleted on permanent instance deletion.
  • No: Disk will be detached on instance deletion.
  • *Note: The disk disk_persistent-disk-1 will be preserved beyond the VM’s lifetime. It will be reattached on instance recreation, autohealing, and update events, and detached on instance deletion.
  • External IP address:
  • Stateful: YES
  • NOTE: IP will be preserved during VM lifetime. It will be reattached on instance recreation, autohealing, and update events, and deleted on permanent instance deletion.
  • On permanent instance deletion: DETACH IP
  • Note: IP from default network will be preserved beyond the VM’s lifetime. It will be reattached on instance recreation, autohealing, and update events, and detached on instance deletion.
  • Internal IP address:
  • Stateful: YES
  • NOTE: IP will be preserved during VM lifetime. It will be reattached on instance recreation, autohealing, and update events, and deleted on permanent instance deletion.
  • On permanent instance deletion: DETACH IP
  • Note: IP from default network will be preserved beyond the VM’s lifetime. It will be reattached on instance recreation, autohealing, and update events, and detached on instance deletion.
  • VM Instance lifecycle: leave to defaults
  • Action on failure: Repair instance
  • Autohealing:
  • Health check: app1-health-check
  • Initial Delay: 300 seconds
  • Updates during VM instance repair: Keep the same instance configuration
  • Specify Port Name Mapping:
  • Port Name: webserver-port
  • Port Numbers: 80
  • Advanced creation options: leave to defaults and discuss
  • Click on CREATE

Step-06: Review Managed Instance Group Properties

  • Go to Compute Engine -> Instance Groups -> Verify Group Type Stateful
  • Go to Compute Engine -> Instance Groups -> Click on mig-stateful
  • Review the following Tabs
  • Overview
  • Details
  • Monitoring
  • Errors (Not applicable for Unmanaged Instance Groups)
  • Go to Compute Engine -> VM Instances -> Verify VM created by Instance Group
  • Go to Compute Engine -> Disks -> Verify Disks created for Stateful Instance Group.

Step-07: Delete Stateful Managed Instance Group Stateful

  • Go to Compute Engine -> Instance Groups -> Click on mig-stateful
  • Click on DELETE GROUP
  • Go to Compute Engine -> Disks -> Verify Disks created for Stateful Instance Group.
    # Sample disk name format
    mig-stateful-wgh6-1
    
  • Even after deleting the Stateful Instance Group, we can see disks are still present because they got detached and persisted

Step-08: Clean-Up - Delete Disk

  • Delete the disk whatever created as per this demo.
  • Go to Compute Engine -> Disks -> mig-stateful-wgh6-1 -> Actions -> Delete
    # Sample disk name format
    managed-instance-group-stateful-wgh6-1
    

Step-09: Delete External and Internal IP

  • Go to VPC Network -> IP Addresses
  • Release External and Internal IP addresses

References

🎉 New Course
Ultimate DevOps Real-World Project Implementation on AWS
$15.99 $84.99 81% OFF
DEVOPS2026FEB
Enroll Now on Udemy
🎉 Offer