Create and Manage Cloud Resources: Challenge Lab

61 views
Skip to first unread message

謝環宇

unread,
Feb 3, 2022, 11:10:47 PM2/3/22
to 2022 TWHK Cloud Study Jam
In Create and Manage Cloud Resources: Challenge Lab
Task 3. Set up an HTTP load balancer

I already built the managed instance group with 2 nginx web-server.

Kazam_screenshot_00000.pngKazam_screenshot_00001.pngKazam_screenshot_00002.png

But I still can't pass the task

Here is my code

gcloud config set compute/zone us-central1-a
gcloud config set compute/region us-central1

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 nginx-template \
   --region=us-central1 \
   --network=default \
   --subnet=default \
   --tags=allow-health-check \
   --image-family=debian-9 \
   --image-project=debian-cloud \
   --metadata-from-file startup-script=startup.sh

gcloud compute target-pools create nginx-pool

gcloud compute instance-groups managed create nginx-group \
--size=2 \
--template=nginx-template \
--target-pool=nginx-pool \
--zone=us-central1-a

gcloud compute instances list

gcloud compute firewall-rules create allow-tcp-rule-849 \
    --network=default \
    --action=allow \
    --direction=ingress \
    --source-ranges=130.211.0.0/22,35.191.0.0/16 \
    --target-tags=allow-health-check \
    --rules=tcp:80

gcloud compute addresses create lb-ipv4-1 \
    --ip-version=IPV4 \
    --global

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

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

gcloud compute backend-services add-backend web-backend-service \
    --instance-group=nginx-group \
    --instance-group-zone=us-central1-a \
    --global

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

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

gcloud compute forwarding-rules create http-content-rule \
    --address=lb-ipv4-1\
    --global \
    --target-http-proxy=http-lb-proxy \
    --ports=80

Please tell me where is wrong?
Reply all
Reply to author
Forward
0 new messages