Create and Manage Cloud Resources: Challenge Lab

Create and Manage Cloud Resources: Challenge Lab

Create and Manage Cloud Resources: Challenge Lab

This is a challenge lab and after completing it you earn a Skill Badge.

Task 1. Create a project jumphost instance

Screenshot at 2022-05-03 12-55-21.png

Solution

  • Go To Navigation Menu -> Compute Engines -> VM Instance
  • They click Create Instance
  • Name the instance as it is mentioned in your task, dont copy mine.
  • Make sure Zone is us-east1-b
  • Change Machine Type to f1-micro

Screenshot at 2022-05-03 13-40-21.png

  • Check if the default image is debian , if not change it to debian
  • Then Press Create (Takes 2-3 min time to create).
  • Then Check Progress it will be completed.

Task 2. Create a Kubernetes service cluster

Screenshot at 2022-05-03 12-55-33.png

Solution

  • Create a cluster (in the us-east1-b zone) to host the service : -
gcloud config set compute/zone us-east1-b
gcloud container clusters create nucleus-jumphost-webserver
gcloud container clusters get-credentials nucleus-jumphost-webserver
kubectl create deployment hello-app --image=gcr.io/google-samples/hello-app:2.0
  • Expose the app on port App port number : -

Please Note in my case port is mentioned as 8080 , it might be different for you, please change it if not same.

kubectl expose deployment hello-app --type=LoadBalancer --port 8080
kubectl get service

Task 3. Set up an HTTP load balancer

Screenshot at 2022-05-03 16-51-25.png

Solution

First open cloud shell and type this command to create a new startup.sh file

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
  • Create an instance template : -
gcloud compute instance-templates create nginx-template \
--metadata-from-file startup-script=startup.sh
  • Create a target pool : -
    gcloud compute target-pools create nginx-pool
    

Screenshot at 2022-05-03 13-30-50.png

You need to select n and choose us-east1 form the options in my case it was on option 26.

  • 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
  • Create a firewall rule named as Firewall rule to allow traffic (80/tcp) : -

Please dont forget to replace {YOUR-FIREWALL-NAME} with firewall rule name provided to you from the below code.

gcloud compute firewall-rules create {YOUR-FIREWALL-NAME} --allow tcp:80
gcloud compute forwarding-rules create nginx-lb \
--region us-east1 \
--ports=80 \
--target-pool nginx-pool
gcloud compute forwarding-rules list
  • 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
    
  • Create a backend service, and attach the managed instance group with named port (http:80) : -
    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
    
  • Create a URL map, and target the 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
    
  • 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
    

Now wait for 4-5 mins

And then click on Check my Progress

Screenshot at 2022-05-03 13-37-42.png

Congratulations

You have completed the challenge

And Earned A New Skill Badge

Screenshot at 2022-05-03 15-16-24.png