0
0
GCPcloud~10 mins

High availability configuration in GCP - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - High availability configuration
Start: User requests service
Load Balancer receives request
Check: Are multiple instances available?
NoCreate more instances
Yes
Distribute request to healthy instance
Instance processes request
Monitor instance health
If instance fails, redirect traffic to healthy instances
Continue serving requests without downtime
The flow shows how a load balancer directs user requests to multiple instances, monitors their health, and ensures traffic is only sent to healthy instances to maintain service availability.
Execution Sample
GCP
resource "google_compute_instance_template" "template" {
  name = "my-instance-template"
  machine_type = "e2-medium"
  disk {
    boot = true
    auto_delete = true
    initialize_params {
      image = "debian-cloud/debian-10"
    }
  }
  network_interface {
    network = "default"
    access_config {}
  }
}

resource "google_compute_instance_group_manager" "igm" {
  name = "my-instance-group"
  base_instance_name = "my-instance"
  instance_template = google_compute_instance_template.template.self_link
  target_size = 2
}

resource "google_compute_health_check" "hc" {
  name = "my-health-check"
  tcp_health_check {
    port = 80
  }
}

resource "google_compute_region_backend_service" "backend" {
  name = "my-backend-service"
  backends {
    group = google_compute_instance_group_manager.igm.instance_group
  }
  health_checks = [google_compute_health_check.hc.self_link]
}
This Terraform code creates an instance template, a managed instance group with two instances, a health check to monitor instance health, and a backend service linked to the group for high availability.
Process Table
StepActionResource StateResult
1Create instance templateTemplate createdReady for instances
2Create instance group manager with target_size=22 instances createdInstances running
3Create health check on port 80Health check activeMonitors instance health
4Create backend service linked to instance groupBackend service activeLoad balancer can route traffic
5Load balancer receives requestInstances healthyRequest routed to instance 1
6Instance 1 fails health checkInstance 1 marked unhealthyTraffic rerouted to instance 2
7Instance 1 recoversInstance 1 healthy againTraffic balanced between instances
8Scale instance group to 33 instances runningMore capacity for requests
9Load balancer distributes requestsAll instances healthyRequests balanced across 3 instances
10TerminateAll systems healthyHigh availability maintained
💡 Execution stops as system maintains high availability with healthy instances serving requests.
Status Tracker
VariableStartAfter Step 2After Step 6After Step 7After Step 8Final
instance_count022233
instance_1_healthunknownhealthyunhealthyhealthyhealthyhealthy
instance_2_healthunknownhealthyhealthyhealthyhealthyhealthy
instance_3_healthunknownn/an/an/ahealthyhealthy
traffic_distributionnonebalanced between 2all to instance 2balanced between 2balanced between 3balanced between 3
Key Moments - 3 Insights
Why does traffic stop going to instance 1 at step 6?
At step 6, instance 1 fails the health check and is marked unhealthy, so the load balancer stops sending traffic to it to avoid downtime, as shown in the execution_table row 6.
What happens when the instance group scales from 2 to 3 instances at step 8?
At step 8, the instance group increases to 3 instances, adding capacity. The load balancer then distributes traffic across all healthy instances, as seen in rows 8 and 9.
How does the health check affect high availability?
The health check monitors instance health continuously. If an instance is unhealthy, traffic is rerouted to healthy instances, ensuring no downtime, demonstrated in steps 3, 6, and 7.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 6. What is the health status of instance 1?
AHealthy
BUnhealthy
CUnknown
DTerminated
💡 Hint
Check the 'Resource State' column in row 6 of the execution_table.
At which step does the instance group scale to 3 instances?
AStep 4
BStep 7
CStep 8
DStep 9
💡 Hint
Look for the step mentioning scaling in the 'Action' column of the execution_table.
If instance 2 became unhealthy at step 9, what would happen to traffic distribution?
ATraffic would be routed only to instance 1 and 3
BTraffic would stop completely
CTraffic would be routed only to instance 3
DTraffic would be routed to instance 2 anyway
💡 Hint
Refer to how traffic is rerouted when an instance is unhealthy in the execution_table steps 6 and 7.
Concept Snapshot
High availability uses multiple instances behind a load balancer.
Health checks monitor instance status.
Unhealthy instances are removed from traffic rotation.
Scaling adds more instances for capacity.
This setup ensures continuous service without downtime.
Full Transcript
High availability configuration in cloud infrastructure means setting up multiple instances of a service so that if one fails, others can take over. A load balancer receives user requests and sends them to healthy instances only. Health checks continuously monitor each instance's status. If an instance becomes unhealthy, the load balancer stops sending traffic to it and redirects to healthy ones. Scaling the instance group adds more instances to handle more requests. This process ensures the service stays available without interruption.