Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 94 You must be signed in to star a gist
  • Fork 47 You must be signed in to fork a gist
  • Save Tambunan26/9063521fdf406645aad4527ccd069149 to your computer and use it in GitHub Desktop.
Save Tambunan26/9063521fdf406645aad4527ccd069149 to your computer and use it in GitHub Desktop.
Task 1: Create a project jumphost instance
Navigation menu > Compute engine > VM Instance
Task 2: Create a Kubernetes service cluster
gcloud config set compute/zone us-east1-b
gcloud container clusters create nucleus-webserver1
gcloud container clusters get-credentials nucleus-webserver1
kubectl create deployment hello-app --image=gcr.io/google-samples/hello-app:2.0
kubectl expose deployment hello-app --type=LoadBalancer --port 8080
kubectl get service
Task 3: Setup 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
1 .Create an instance template :
gcloud compute instance-templates create nginx-template \
--metadata-from-file startup-script=startup.sh
2 .Create a target pool :
gcloud compute target-pools create nginx-pool
3 .Create a managed instance group :
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
4 .Create a firewall rule to allow traffic (80/tcp) :
gcloud compute firewall-rules create www-firewall --allow tcp:80
gcloud compute forwarding-rules create nginx-lb \
--region us-east1 \
--ports=80 \
--target-pool nginx-pool
gcloud compute forwarding-rules list
5 .Create a health check :
gcloud compute http-health-checks create http-basic-check
gcloud compute instance-groups managed \
set-named-ports nginx-group \
--named-ports http:80
6 .Create a backend service and attach the manged instance group :
gcloud compute backend-services create nginx-backend \
--protocol HTTP --http-health-checks http-basic-check --global
gcloud compute backend-services add-backend nginx-backend \
--instance-group nginx-group \
--instance-group-zone us-east1-b \
--global
7 .Create a URL map and target HTTP proxy to route requests to your URL map :
gcloud compute url-maps create web-map \
--default-service nginx-backend
gcloud compute target-http-proxies create http-lb-proxy \
--url-map web-map
8 .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
@ankitg4
Copy link

ankitg4 commented Aug 9, 2023

I was able complete 3rd task with
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
service nginx start
EOF
gcloud compute instance-templates create nginx-template --metadata-from-file startup-script=startup.sh
gcloud compute target-pools create nginx-poolgcloud compute instance-groups managed create nginx-group --base-instance-name nginx --size 2 --template nginx-template --target-pool nginx-pool
gcloud compute firewall-rules create permit-tcp-rule-733 --allow tcp:80
gcloud compute forwarding-rules create nginx-lb --region us-east1 --ports=80 --target-pool nginx-pool
gcloud compute http-health-checks create http-basic-checkgcloud compute target-pools add-health-checks nginx-pool --http-health-checks http-basic-check --region us-east1
gcloud compute instance-groups managed set-named-ports nginx-group --named-ports http:80 --zone=us-east1-c
gcloud compute backend-services create nginx-backend --protocol HTTP --http-health-checks http-basic-check --global
gcloud compute backend-services add-backend nginx-backend --instance-group nginx-group --instance-group-zone us-east1-c --global
gcloud compute url-maps create web-map --default-service nginx-backend
gcloud compute target-http-proxies create http-lb-proxy --url-map web-map
gcloud compute forwarding-rules create http-content-rule --global --target-http-proxy http-lb-proxy --ports 80

@therealdhrxv
Copy link

"Please verify the web servers are serving on frontend of HTTP(s) Load Balancer"

For this specific error if you have steps right, I think its in the Progress checker the issue is, beside creating the FW Rule with the dynamic name generated in Description, add identically rule:

gcloud compute firewall-rules create web-server-firewall --allow tcp:80 --network VPC_NAME

Fixed it immediatly for me, so its the name that is the issue

thank you so much 🙏🥂

@bcastro14
Copy link

I was getting the error "Please create the managed instance group with 2 nginx web server" after doing everything, and using the command gcloud compute instance-groups managed set-named-ports YOUR_MANAGED_INSTANCE_GROUP_NAME --named-ports http:80 --zone=YOUR_ZONE solved it for me and I could get the final check in the lab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment