0% found this document useful (0 votes)
225 views

GSP007

This document provides instructions for setting up two types of load balancers on Google Cloud Platform: a network load balancer and an HTTP(S) load balancer. It first has the reader create a cluster of Nginx web server instances. It then walks through creating a network load balancer targeting this cluster to balance traffic based on IP, port and protocol. Next, it covers setting up an HTTP(S) load balancer which routes traffic based on URL and can send requests to instances closest to the user. The goal is to demonstrate the differences between these two load balancing approaches and provide hands-on experience setting them up.

Uploaded by

Ivan Ega Pratama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
225 views

GSP007

This document provides instructions for setting up two types of load balancers on Google Cloud Platform: a network load balancer and an HTTP(S) load balancer. It first has the reader create a cluster of Nginx web server instances. It then walks through creating a network load balancer targeting this cluster to balance traffic based on IP, port and protocol. Next, it covers setting up an HTTP(S) load balancer which routes traffic based on URL and can send requests to instances closest to the user. The goal is to demonstrate the differences between these two load balancing approaches and provide hands-on experience setting them up.

Uploaded by

Ivan Ega Pratama
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Set Up Network and HTTP Load Balancers

(GSP007)

Overview
In this hands-on lab, you’ll learn the differences between a network load balancer
and a HTTP load balancer, and how to set them up for your applications running
on Google Compute Engine virtual machines.
There are several ways you can load balance in Google Cloud Platform. This
lab takes you through the setup of the following load balancers:
• L3 Network Load Balancer
• L7 HTTP(S) Load Balancer

What you’ll do
• Setup a network load balancer.
• Setup a HTTP(s) load balancer.
• Get hands-on experience learning the differences between network load
balancers and HTTP load balancers.

Set the default region and zone for all resources


gcloud config set compute/zone us-central1-a

Create multiple web server instances


To simulate serving from a cluster of machines, create a simple cluster of Nginx
web servers to serve static content using Instance Templates and Managed
Instance Groups. Instance Templates define the look of every virtual machine in
the cluster (disk, CPUs, memory, etc). Managed Instance Groups instantiate a
number of virtual machine instances using the Instance Template.
To create the Nginx web server clusters, create the following: - A startup script
to be used by every virtual machine instance to setup Nginx server upon startup

1
- An instance template to use the startup script - A target pool - A managed
instance group using the instance template
cat << EOF > startup.sh
#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian
EOF
gcloud compute instance-templates create nginx-template \
--metadata-from-file startup-script=startup.sh
gcloud compute target-pools create nginx-pool
gcloud compute instance-groups managed create nginx-group \
--base-instance-name nginx \
--size 2 \
--template nginx-template \
--target-pool nginx-pool
gcloud compute instances list
Now configure a firewall so that you can connect to the machines on port 80 via
EXTERNAL_IP addresses.

Create a Network Load Balancer


Network load balancing allows you to balance the load of your systems based
on incoming IP protocol data, such as address, port, and protocol type. You
also get some options that are not available, with HTTP(S) load balancing. For
example, you can load balance additional TCP/UDP-based protocols such as
SMTP traffic. And if your application is interested in TCP-connection-related
characteristics, network load balancing allows your app to inspect the packets,
where HTTP(S) load balancing does not.
Create an L3 network load balancer targeting your instance group:
gcloud compute forwarding-rules create nginx-lb \
--region us-central1 \
--ports=80 \
--target-pool nginx-pool
List all Google Compute Engine forwarding rules in your project.
gcloud compute forwarding-rules list

2
Create a HTTP(s) Load Balancer
HTTP(S) load balancing provides global load balancing for HTTP(S) requests
destined for your instances. You can configure URL rules that route some URLs
to one set of instances and route other URLs to other instances. Requests are
always routed to the instance group that is closest to the user, provided that
group has enough capaicty and is appropriate for the request. If the closest
group dosen not have enough capacity, the request is sent to the closest group
that does have capacity.
Health check:
gcloud compute http-health-checks create http-basic-check
Define an HTTP service and map a port name to the relevant port for the
instance group.
gcloud compute instance-groups managed \
set-named-ports nginx-group \
--named-ports http:80
Create a backend service:
gcloud compute backend-services create nginx-backend \
--protocol HTTP --http-health-checks http-basic-check --global
Add the instance group into the backend service:
gcloud compute backend-services add-backend nginx-backend \
--instance-group nginx-group \
--instance-group-zone us-central1-a \
--global
Create a default URL map that directs all incoming requests to all your instances:
gcloud compute url-maps create web-map \
--default-service nginx-backend
Create a target HTTP proxy to route requests to your URL map:
gcloud compute target-http-proxies create http-lb-proxy \
--url-map web-map
Create a global forwarding rule to handle and route incoming requests.
gcloud compute forwarding-rules create http-content-rule \
--global \
--target-http-proxy http-lb-proxy \
--ports 80
After creating the global forwarding rule, it can take several minutes for your
configuration to propagate.
gcloud compute forwarding-rules list

You might also like