Skip to main content

GSP313 Create and Manage Cloud Resources: Challenge Lab

Challenge Lab: https://google.qwiklabs.com/focuses/10258?parent=catalog

Lab Video#

Setup#

Set Default Compute Zone and Region

gcloud config set compute/zone us-east1-bgcloud config set compute/region us-east1

Task 1: Create a project jumphost instance#

Create an instance with command line

gcloud compute instances create nucleus-jumphost \  --machine-type f1-micro

Task 2: Create a Kubernetes service cluster#

Create a GKE cluster#

gcloud container clusters create my-cluster

Get authentication credentials for the cluster#

gcloud container clusters get-credentials my-cluster

Deploy an application to the cluster#

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

Expose your application to external traffic#

kubectl expose deployment hello-server --type LoadBalancer --port 8080

Check if service is up and running#

kubectl get service

Task 3: Set up an HTTP load balancer#

Create Startup Script#

cat << EOF > startup.sh#! /bin/bashapt-get updateapt-get install -y nginxservice nginx startsed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.htmlEOF

Create Instance Template#

gcloud compute instance-templates create nginx-server-template \  --metadata-from-file startup-script=startup.sh \  --network nucleus-vpc \  --machine-type f1-micro

Create Managed Instance Group#

gcloud compute instance-groups managed create nginx-server-group \  --base-instance-name nginx-server \  --size 2 \  --template nginx-server-template

Firewall rule#

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

Create a health check#

gcloud compute http-health-checks create http-basic-check

Set Named Port#

gcloud compute instance-groups managed \  set-named-ports nginx-server-group \  --named-ports http:80

Create a backend service#

gcloud compute backend-services create nginx-server-backend \  --protocol HTTP \  --http-health-checks http-basic-check \  --global

Attach the managed instance group to a backend service#

gcloud compute backend-services add-backend nginx-server-backend \  --instance-group nginx-server-group \  --global

Create a URL map#

gcloud compute url-maps create nginx-server-map \  --default-service nginx-server-backend

Target the HTTP proxy to route requests to your URL map#

gcloud compute target-http-proxies create http-lb-proxy \  --url-map nginx-server-map

Forwarding Rule#

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

Get a list of Forwarding Rules#

gcloud compute forwarding-rules list