Skip to main content

Command Palette

Search for a command to run...

Configure Load Balancer for High Availability

Set up a load balancer to distribute traffic across multiple VM instances.

Published
3 min read
  1. Login to your google account.

  2. Go to Compute Engine and create few virtual machines with default settings.

  3. From left hand-side panel, select Instance Groups

    • Click on “CREATE INSTANCE GROUPS”
  • Name the instance group

  • Create a new Instance Template

  • Name the instance template and leave the default settings

  • Click on save and continue

  • Leave the default settings and Click on create

    Successfully created an instance group

  1. Now search for load balancer

    Click on Load Balancing

  2. Now, select “CREATE LOAD BALANCER”

    • For now, go with “Application Load Balancer”

    • Click on Next

    • Select Public facing (it will routes requests from clients over the internet to targets)

    • Select Global Workloads (used when we want to deploy backends in multiple regions)

    • Select Global external Application Load Balancer (Load balancer with EXTERNAL_MANAGED load balancing scheme")

    • Click on CONFIGURE

  3. Name your Load Balancer

  4. For Frontend Configuration

    • Name your Frontend configuration

    • Leave the default settings

    • Click on Done and move to next part i.e. Backend Configuration

  5. In Backend Configuration, we can either create a backend service or a backend bucket

    • For now, I’m creating a backend service

  • Name the backend service

  • For instance group, select your previously created instance group

  • For port numbers, choose an unregistered port no.

  • For health check, create a new one

  • Name the health check

  • Leave the default settings

    Click on save

  • Click on create

  • Click ok

    Your backend part is done

  • Now move to Routing Rules

  1. Here, our backend service is already attached so leave it as it is

    Click on create

  2. Your load balancer is ready

    Try It Yourself: Go Beyond the Basics

    Now that you've successfully set up a load balancer, here are a few extra steps you can try to deepen your learning:

    1. Use Instance Templates: Instead of manually creating each virtual machine, try using an instance template to automate the creation of VMs. It saves time and ensures consistency across your instances.

    2. Automate with Scripts: When creating virtual machines, add an automation script that prints a message like "Hello from this server!". This way, after setting up the load balancer, you can refresh the frontend IP and see which specific instance is handling the traffic based on the message displayed. It's a fun way to visualize traffic distribution!

    3. Monitor Traffic Distribution: After setting up your load balancer, copy the frontend IP, open it in your browser, and see how traffic is routed. As you refresh, you'll notice different instances handling the traffic, showing the message you scripted earlier.

"Great work setting up your load balancer! Now, your VMs are primed to handle traffic like a pro. You’ve just boosted your cloud performance—stay tuned for even more ways to optimize and scale your GCP environment!"

GCP VM Series: From Zero to Compute

Part 12 of 14

Get ready for an exciting ride in Google Cloud! Our series takes you through every method of creating virtual machines in GCP, complete with engaging tutorials and practical labs. Elevate your cloud game and become a VM virtuoso!

Up next

Automate VM Management with Google Cloud SDK

Automate VM Management with Google Cloud SDK