Getting Started: Create and Manage Cloud Resources: Challenge Lab
Tags: googlecloud, gcp, challenge, cloud
Published: 2022-04-07 09:56:37

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bi556njvwebhbrf0uxm8.jpg)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4g91rp1ciiov86dv343o.jpg)


- 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k1ynpmcvdvbvuib6j9sz.jpg)

 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      
```

**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
```

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
```

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
      
```

**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
      
```


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

```
gcloud compute firewall-rules create web-server-firewall \
          --allow tcp:80 \
          --network nucleus-vpc
```
 

**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
```
      


**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
      
```

**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
      
```

**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
```

Congratulations! Done with the challenge lab.