Task 2. Set up an HTTP load balancer

I used those command line but the backend service still unhealthy 

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.html
EOF

 

gcloud compute instance-templates create nucleus-webserver-template \
--machine-type=e2-medium \
--metadata=startup-script='#! /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.html' \
--image-family=debian-11 \
--image-project=debian-cloud \
--tags=http-server

 

gcloud compute instance-groups managed create nucleus-webserver-group \
--base-instance-name=nucleus-webserver \
--template=nucleus-webserver-template \
--size=2 \
--zone=us-central1-b

gcloud compute firewall-rules create accept-tcp-rule-261 \
--allow=tcp:80 \
--target-tags=http-server \
--description="Allow port 80 traffic"

gcloud compute health-checks create http http-basic-check \
--port 80

gcloud compute backend-services create nucleus-backend-service \
--protocol=HTTP \
--health-checks=http-basic-check \
--port-name=http \
--global

gcloud compute backend-services add-backend nucleus-backend-service \
--instance-group=nucleus-webserver-group \
--instance-group-zone=us-central1-b \
--global

gcloud compute url-maps create nucleus-url-map \
--default-service=nucleus-backend-service

gcloud compute target-http-proxies create nucleus-http-proxy \
--url-map=nucleus-url-map

gcloud compute forwarding-rules create http-content-rule \
--global \
--target-http-proxy=nucleus-http-proxy \
--ports=80

gcloud compute forwarding-rules list --global

but I didn't get the score and get this message 

Please create the managed instance group with 2 nginx web-server.

 

0 1 2,174
1 REPLY 1

Hi @reham_ashraf104,

Did you check that the command executed to create the managed instance group was successful and in the correct region?
I am sharing with you the steps I followed in my Lab:

 

First; I defined variables to make the commands easier: (please, review data in your Lab assigned!)
 
export INSTANCE_NAME=nucleus-jumphost-634 
export ZONE=us-west3-a
export REGION=us-west3
export PORT=8081
export FIREWAL_NAME=grant-tcp-rule-831
export NETWORK=default
 
I used the default network because it is the only one I had created in my project
 
# Task 1. Create a project jumpiest instance

gcloud compute instances create $INSTANCE_NAME \
    --network $NETWORK \
    --zone $ZONE \
    --machine-type e2-micro \
    --image-family debian-10 \
    --image-project debian-cloud
 
# Task 2. Set up an HTTP load balancer

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.html
EOF

gcloud compute instance-templates create web-server-template \
    --metadata-from-file startup-script=startup.sh \
    --network $NETWORK \
    --machine-type e2-medium \
    --region $REGION

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

gcloud compute instance-groups managed create web-server-group \
    --base-instance-name web-server \
    --size 2 \
    --template web-server-template \
    --region $REGION

gcloud compute firewall-rules create $FIREWAL_NAME \
    --allow tcp:80 \
    --network $NETWORK

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

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 $REGION \
    --global

gcloud compute url-maps create web-server-map \
    --default-service web-server-backend

gcloud compute target-http-proxies create http-lb-proxy \
    --url-map web-server-map

gcloud compute forwarding-rules create $FIREWAL_NAME \
    --global \
    --target-http-proxy http-lb-proxy \
    --ports 80
 
Good luck!
 
Top Labels in this Space