Setup Http(s) Load balancing with Managed Instance Groups on GCP Using the Windows Powershell or Command Prompt

  1. Google cloud sdk installed and activated, and
  2. Windows admin access rights
  3. For powershell (non-gcp installed version) and command prompt run both as “admin user”.
Image source:
  1. The global forwarding rule, along with target proxy are the “frontend” in this setup,
  2. The “url map” is the load balancer itself and maps a given “url” to a backend service (and this can be many),
  3. The global backend service is the backend service that receives traffic from the “url-map” service and sends it to the backend vm instances. It uses the health check to determine the current state of the vm instances and from this determines who gets traffic,
  4. Global health check send probes to the vm instances and reports their state to both the instance groups and the backend service,
  5. Instance groups are used to manage a group of vm instances and autoscale using the autoscaling policies and perform autohealing using the health check information provided by the health check service, and
  6. Internet is just the internet :-).
  • We create the instance that will be used for creating the template
gcloud compute instances create instance-template-base --machine-type=f1-micro --zone=us-central1-a --tags=”http-server,https-server” --no-boot-disk-auto-delete
  • Then delete the instance, but the boot disk is left as we required this with the command option “ — no-boot-disk-auto-delete”
gcloud compute instances delete instance-template-base --zone=us-central1-a
  • We now create an image from the disk for use with instance template creation
gcloud compute images create instance-template-image --source-disk=instance-template-base
  • Finally we add the “http-tag” for use by the firewall rule that we will be creating. This allows the health check probe access to the vm instances, and the “http-server” and “https-server” tags will enable “http” traffic on the created vms.
gcloud compute instance-templates create instance-template --machine-type=f1-micro --image=instance-template-image --image-project=egusi-new-soup --boot-disk-size=10GB --boot-disk-type=pd-standard --tags=”http-server,https-server,http-tag”
gcloud compute health-checks create http instance-health-check  --check-interval=10s --port=80 --timeout=5s --unhealthy-threshold=3 --project egusi-new-soup
gcloud compute instance-groups managed create us-webserver-instancegroup --size=1 --template=instance-template--initial-delay=60 --health-check=instance-health-check --region=us-central1
  • contd…
gcloud compute instance-groups managed set-autoscaling us-webserver-instancegroup --max-num-replicas=6 --min-num-replicas=3 --scale-based-on-cpu --target-cpu-utilization=0.6 --cool-down-period=60  --region=us-central1
gcloud compute backend-services create webserver-backend  --protocol=http --port-name=http --timeout=30s --health-checks=instance-health-check --global
  • Contd…
gcloud compute backend-services add-backend webserver-backend --instance-group=us-webserver-instancegroup --instance-group-region=us-central1 --balancing-mode=utilization --capacity-scaler=1  --max-utilization=0.8 --global
  • Contd…
gcloud compute backend-services add-backend webserver-backend --instance-group=west-webserver-instancegroup --instance-group-region=us-west1 --balancing-mode=utilization --capacity-scaler=1 --max-utilization=0.8 --global
gcloud compute url-maps create egusi-url-map --default-service webserver-backend
gcloud compute addresses create instance-global-static-ip --ip-version=ipv4 --global
gcloud compute target-http-proxies create webserver-proxy --url-map egusi-url-map
gcloud compute forwarding-rules create instance-webserver-frontend --ip-protocol=tcp --ports=80 --global --target-http-proxy webserver-proxy --address=instance-global-static-ip
gcloud compute firewall-rules create health-check-rule --action=ALLOW --rules=tcp:80 --source-ranges="," --destination=INGRESS --target-tags=http-tag



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
george udosen

george udosen


DevOps | FullStack developer | Python::Flask | GCP Cloud Certified | AWS & AZURE Cloud Savy | Linux Sysadmin | Google IT Support