DEV Community

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

Posted on

Getting Started: Create and Manage Cloud Resources: Challenge Lab

In this article, we will go through the lab Getting Started: Create and Manage Cloud Resources.

Image description

The challenge contains 3 required tasks

  1. Creating a Project Jumphost instance.
  2. Creating a Kubernetes Service Cluster.
  3. Creating the Web Server Frontend.
  • 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.

1.Create a project Jumphost instance

The first step is to create a Jumphost instance

  • In the GCP Console go to Navigation Menu >Compute Engine > VM Instance.

Image description

  • Write the below parameters, check machine type, and Image type.
  • The name of instance be nucleus-jumphost
  • Region be Default Region
  • Zone be Default Zone
  • The machine type be f1-micro.
  • Using the default image type (Debian Linux)
  • Click Create

Image description

or use This command in shell to create the nucleus-jumphost

gcloud compute instances create nucleus-jumphost \
  --network nucleus-vpc \
  --zone us-east1-b  \
  --machine-type f1-micro  \
  --image-family debian-9  \
  --image-project debian-cloud      
Enter fullscreen mode Exit fullscreen mode

2.Create a Kubernetes service cluster

In this step, you have to create a Kubernetes Service Cluster

  • Create the cluster in the us-east1-b region.
  • Using the Docker container hello-app (gcr.io/google-samples/hello-app:2.0) as a place holder.
  • Open the app on port 8080
  • Activate Cloud Shell and write the following commands
gcloud container clusters create nucleus-backend \
          --num-nodes 1 \
          --network nucleus-vpc \
          --region us-east1


gcloud container clusters get-credentials nucleus-backend \
          --region us-east1

kubectl create deployment hello-server \
          --image=gcr.io/google-samples/hello-app:2.0


kubectl expose deployment hello-server \
          --type=LoadBalancer \
          --port 8080
Enter fullscreen mode Exit fullscreen mode

It will create a Kubernetes cluster.

3.Setup an HTTP load balancer

In this step, you have to create a serve the site via Nginx web servers

  • Activate the cloud shell and Copy and Paste the following commands
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

Now you have to perform the steps to HTTP(s) Load Balancer in front of two web servers

-** Creating an instance template**:

gcloud compute instance-templates create web-server-template \
          --metadata-from-file startup-script=startup.sh \
          --network nucleus-vpc \
          --machine-type g1-small \
          --region us-east1

Enter fullscreen mode Exit fullscreen mode

3. Creating a managed instance group:

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

Enter fullscreen mode Exit fullscreen mode

4. Creating a firewall rule to allow traffic (80/tcp)

gcloud compute firewall-rules create web-server-firewall \
          --allow tcp:80 \
          --network nucleus-vpc
Enter fullscreen mode Exit fullscreen mode

5. Creating a health check:

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

6. Creating a backend service and attach the managed instance group:

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 us-east1 \
          --global

Enter fullscreen mode Exit fullscreen mode

7. Creating a URL map and target HTTP proxy to route requests to your URL map:

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

Enter fullscreen mode Exit fullscreen mode

8. Creating forwarding rule:

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

Congratulations! Done with the challenge lab.

Top comments (1)

Collapse
 
fabioarvelo profile image
Fabio Andres

Ufff, I'm just completing the course and you were a great help for me. God bless you! Thank you!