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

Google Cloud Load Balancing Challenge Lab

Uploaded by

salemlumumba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Google Cloud Load Balancing Challenge Lab

Uploaded by

salemlumumba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Implement Load Balancing on Compute

Engine: Challenge Lab


Task 2. Set up an HTTP load balancer
You need to:

● Export the given attributes from Lab setup

export ZONE=us-east1-b
export REGION=us-east1
export PORT=8080
export FIREWALL_NAME=accept-tcp-rule-609

Use the following code to configure the web servers to run nginx. Create a startup.sh
script and include it in the Compute Instance Instance Template.

cat << EOF > startup.sh


#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i 's/listen 80;/listen 8080;/'
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/'
/var/www/html/index.nginx-debian.html
EOF

sudo chmod +x ./startup.sh


sudo ./startup.sh

● Create an instance template. Don't use the default machine type. Make sure you
specify e2-medium as the machine type.

gcloud compute instance-templates create web-server-template \


--metadata-from-file startup-script=startup.sh \
--network default \
--machine-type e2-medium \
--region $REGION

● Add a target pool in the same region as your instances. Run the following to
create the target pool and use the health check, which is required for the service
to function:

gcloud compute target-pools create nginx-pool --region=$REGION

● Create a managed instance group based on the template.

gcloud compute instance-groups managed create web-server-group


\
--base-instance-name web-server \
--size 2 \
--template web-server-template \
--region $REGION

*Note: Please check for the Region and Zone assigned in your Lab, because Check
My Progress will look for your resources in specific regions.

● Create a firewall rule named as accept-tcp-rule-609 to allow traffic (80/tcp).

gcloud compute firewall-rules create accept-tcp-rule-609\


--allow tcp:80 \
--network default

● Create a health check.

gcloud compute http-health-checks create http-basic-check

● Set up a global static external IP address that your customers use to reach your
load balancer (Part of LB Configuration) [OPTIONAL]

gcloud compute addresses create lb-ipv4-1 \


--ip-version=IPV4 \
--global

Note the IPv4 address that was reserved: [OPTIONAL]

gcloud compute addresses describe lb-ipv4-1 \


--format="get(address)" \
--global

● Create a backend service and add your instance group as the backend to the
backend service group with the named port (http:80).

gcloud compute instance-groups managed \


set-named-ports web-server-group \
--named-ports http:80 \
--region $REGION

gcloud compute backend-services create web-server-backend \


--protocol HTTP \
--http-health-checks http-basic-check \
--global
gcloud compute backend-services add-backend web-server-backend \
--instance-group web-server-group \
--instance-group-region us-east1 \
--global

● Create a URL map, and target the HTTP proxy to route the incoming requests to
the default backend service.

gcloud compute url-maps create web-server-map \


--default-service web-server-backend

Verify URL Map Existence: gcloud compute url-maps list

● Create a target HTTP proxy to route requests to your URL map

gcloud compute target-http-proxies create http-lb-proxy \


--url-map web-server-map

● Create a forwarding rule.

gcloud compute forwarding-rules create http-content-rule \


--global \
--target-http-proxy http-lb-proxy \
--ports 80

gcloud compute forwarding-rules list

Note: You may need to wait for 10 to 15 minutes to get the score for this task.

Please let us know if we can be of any further help. We will be happy to help you.

You might also like