DEV Community

Cover image for Getting Started: Create and Manage Cloud Resources: Challenge Lab
Ashutosh Pipriye
Ashutosh Pipriye

Posted on

Getting Started: Create and Manage Cloud Resources: Challenge Lab

The steps to solve Create and Manage Cloud Resources: Challenge Lab on the Google Cloud Platform (Qwiklabs)
Alt Text

Click here to see My Public Profile of Qwicklabs

Click here to see My Gists

Topics tested:

  • Create an instance.
  • Create a 3 node Kubernetes cluster and run a simple service.
  • Create an HTTP(s) Load Balancer in front of two web servers.

Setup

Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

What you need
To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Pixelbook, open an Incognito window to run this lab.

Challenge scenario

You have started a new role as a Junior Cloud Engineer for Jooli Inc. You are expected to help manage the infrastructure at Jooli. Common tasks include provisioning resources for projects.

You are expected to have the skills and knowledge for these tasks, so don't expect step-by-step guides to be provided.

Some Jooli Inc. standards you should follow:

  • Create all resources in the default region or zone, unless otherwise directed.
  • Naming is normally team-resource, e.g. an instance could be named nucleus-webserver1
  • Allocate cost effective resource sizes. Projects are monitored and excessive resource use will result in the containing project's termination (and possibly yours), so beware. This is the guidance the monitoring team is willing to share; unless directed use f1-micro for small Linux VMs and n1-standard-1 for Windows or other applications such as Kubernetes nodes.

Task 1: Create a project jumphost instance

Make sure you:

  • name the instance nucleus-jumphost
  • use the machine type f1-micro
  • use the default image type (Debian Linux)

In the Cloud Console, on the top left of the screen, select Navigation menu > Compute Engine > VM Instances:

Alt Text

Alt Text

  • Name for the VM instance : nucleus-jumphost

  • Region : leave Default Region

  • Zone : leave Default Zone

  • Machine Type : f1-micro (Series - N1)

  • Boot Disk : use the default image type (Debian Linux)

  • Create.

Click Check my progress to verify the objective.
Task Completed...

Task 2: Create a Kubernetes service cluster

The team is building an application that will use a service. This service will run on Kubernetes.

You need to:

  • Create a cluster (in the us-east1 region) to host the service
  • Use the Docker container hello-app (gcr.io/google-samples/hello-app:2.0) as a place holder, the team will replace the container with their own work later
  • Expose the app on port 8080

Activate Cloud Shell

Alt Text

Alt Text

Alt Text

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

Click Check my progress to verify the objective.
Task Completed...

Task 3: Setup an HTTP load balancer

We will serve the site via nginx web servers, but we want to ensure we have a fault tolerant environment, so please create an HTTP load balancer with a managed instance group of two nginx web servers. Use the following to configure the web servers, the team will replace this with their own configuration later.

You need to:

  • Create an instance template
  • Create a target pool
  • Create a managed instance group
  • Create a firewall rule to allow traffic (80/tcp)
  • Create a health check
  • Create a backend service and attach the manged instance group
  • Create a URL map and target HTTP proxy to route requests to your URL map
  • Create a forwarding rule

Do the following commands in cloud shell to Setup an HTTP load balancer

Create 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
Enter fullscreen mode Exit fullscreen mode

1 .Create an instance template :

gcloud compute instance-templates create nginx-template \
--metadata-from-file startup-script=startup.sh
Enter fullscreen mode Exit fullscreen mode

2 .Create a target pool :

gcloud compute target-pools create nginx-pool
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

8 .Create a forwarding rule :

gcloud compute forwarding-rules create http-content-rule \
--global \
--target-http-proxy http-lb-proxy \
--ports 80
Enter fullscreen mode Exit fullscreen mode

gcloud compute forwarding-rules list

Wait for for extra 10 mins to Create the website behind the HTTP load balancer and to get 100 points in lab !!!

Click Check my progress to verify the objective.
Task Completed...

Quest Complete!

Congrats! You completed this quest and earned a badge. Become a cloud expert and start another.

Top comments (7)

Collapse
 
nakshee_kalolia profile image
Nakshee Kalolia • Edited

On doing Third task 3rd step , it shows an error that:-

(gcloud.compute.instance-groups.managed.create) Could not fetch resource:

Can you please help out for this

Collapse
 
mingjun1120 profile image
mingjun1120 • Edited

Way to solve this error:

When creating a target pool with the command gcloud compute target-pools create nginx-pool in Task 3. You will be prompted after the command, press "n" and select the same region that was used to create the VM instance in Task 1. For example, if you have created your VM instance in Task 1 with "us-west4", then please select "us-west4" after pressing "n".

Collapse
 
erwaseem profile image
Waseem Ud Din

Change the instance region to us-east1-b. Your problemwill be resolved

Collapse
 
hot9cups profile image
Ayush Modi • Edited

Would you mind explaining, in task 3 step 5, why do we need to add the following code?

gcloud compute instance-groups managed \ 
set-named-ports nginx-group \
--named-ports http:80
Enter fullscreen mode Exit fullscreen mode

Didn't they ask us to just create the health check?
I really think I'm missing some theory and it'd be great if someone could explain

Collapse
 
resonates7 profile image
resonates7

Hi Ayush, that bit is required in the instructions, although it isn't associated with a the health check. The instructions indicate 'Create a backend service, and attach the managed instance group with named port (http:80).'

Named ports are used by load balancers. Check out this documentation for more info:

cloud.google.com/sdk/gcloud/refere...

Collapse
 
skshamagarwal profile image
Saksham Agarwal

stuck with error - "Please verify the web servers are serving on frontend of HTTP(s) Load Balancer."

Collapse
 
ababaka profile image
Alexey

run the command on both VM's via SSH:

sudo su
sed -i -- 's/nginx/Google Cloud Platform - '"$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
Enter fullscreen mode Exit fullscreen mode