Sunday, November 21, 2021

Loadbalancer challenge lab

 

Your challenge

As soon as you sit down at your desk and open your new laptop, you receive several requests from the Nucleus team. Read through each description, and then create the resources.

Task 1: Create a project jumphost instance

You will use this instance to perform maintenance for the project.

Requirements:

  • Name the instance nucleus-jumphost-598 .
  • Use an f1-micro machine type.
  • Use the default image type (Debian Linux).

Click Check my progress to verify the objective.


gcloud compute instances create nucleus-jumphost-598 --machine-type=f1-micro



ask 2: Create a Kubernetes service cluster

The team is building an application that will use a service running on Kubernetes. You need to:

  • Create a cluster (in the us-east1-b zone) 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 .

Click Check my progress to verify the objective.

gcloud container clusters create my-cluster1

student_01_45ca4c80250a@cloudshell:~ (qwiklabs-gcp-04-30f2c219d6ce)$ gcloud container clusters get-credentials my-cluster1Fetching cluster endpoint and auth data.

kubeconfig entry generated for my-cluster1.

student_01_45ca4c80250a@cloudshell:~ (qwiklabs-gcp-04-30f2c219d6ce)$ kubectl create deployment hello-app --image=gcr.io/google-samples/hello-app:2.0

deployment.apps/hello-app created

student_01_45ca4c80250a@cloudshell:~ (qwiklabs-gcp-04-30f2c219d6ce)$ kubectl expose deployment hell0app --type=LoadBalancer --port 8080

Error from server (NotFound): deployments.apps "hell0app" not found

student_01_45ca4c80250a@cloudshell:~ (qwiklabs-gcp-04-30f2c219d6ce)$ kubectl expose deployment hello-app --type=LoadBalancer --port 8080

service/hello-app exposed

student_01_45ca4c80250a@cloudshell:~ (qwiklabs-gcp-04-30f2c219d6ce)$



Task 3: Set up an HTTP load balancer

You will serve the site via nginx web servers, but you want to ensure that the environment is fault-tolerant. Create an HTTP load balancer with a managed instance group of 2 nginx web servers. Use the following code to configure the web servers; the team will replace this with their own configuration later.

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
Copied!

You need to:

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




udent_01_21094d6b9493@cloudshell:~ (qwiklabs-gcp-03-6db14b791dde)$ history
    1  gcloud compute create instances nucleus-jumphost-937 --machine-type=f1-micro
    2  gcloud compute  instances create  nucleus-jumphost-937 --machine-type=f1-micro
    3  gcloud config set compute/zone us-east1-b
    4  gcloud config list
    5  gcloud container clusters create nucleus-cluster
    6  gcloud container clusters get-credentials nucleus-cluster
    7  kubectl create deployment hello-app --image=gcr.io/google-samples/hello-app:2.0
    8  kubectl expose deployment hello-app --type=loadbalancer port 8081
    9  kubectl expose deployment hello-app --type=Loadbalancer port 8081
   10  kubectl get pods
   11  kubectl get service
   12  kubectl get deployment
   13  kubectl expose deployment hello-app --type=LoadBalancer --port 8081
   14  kubectl get service
   15  gcloud compute instance-template crate lb-backend-template --region=us-east1 --network=default --subnet=default --tags=allow-health-check --machine-type=f1-micro --metadata=startup-script='#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
echo "nginx google cloud platform - $HOSTNAME" | \
tee /var/www/html/index.nginx-debian.html'
   16  gcloud compute instance-templates crate lb-backend-template --region=us-east1 --network=default --subnet=default --tags=allow-health-check --machine-type=f1-micro --metadata=startup-script='#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
echo "nginx google cloud platform - $HOSTNAME" | \
tee /var/www/html/index.nginx-debian.html'
   17  gcloud compute instance-templates create lb-backend-template --region=us-east1 --network=default --subnet=default --tags=allow-health-check --machine-type=f1-micro --metadata=startup-script='#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
echo "nginx google cloud platform - $HOSTNAME" | \
tee /var/www/html/index.nginx-debian.html'
   18  gcloud describe instance-templates lb-backend-template
   19  gcloud compute instance-templates describe lb-backend-template
   20  gcloud compute target-pools create www-pool --region us-east1 -http-check-check basic-check
   21  gcloud compute target-pools create www-pool --region us-east1 --http-check-check basic-check
   22  gcloud compute target-pools create www-pool --region us-east1 --http-health-check basic-check
   23  gcloud compute http-health-checks create basic-check
   24  gcloud compute target-pools create www-pool --region us-east1 --http-health-check basic-check
   25  gcloud compute instance-groups managed create lb-backend-group --template=lb-backend-template --size=2 --zone=us-east1-b
   26  kubectl get pods
   27  gcloud compute firewall-rules create grant-tcp-rule-935 --network=default --action=allow --direction=ingress --source-ranges=130.211.0.0/22,35.191.0.0/16 --target-tags=allow-health-check --rules=tcp:80
   28  gcloud compute instances list
   29  gcloud compute addresses create lb-ipv1-1 --ip-version=IPV4
   30  gcloud compute addresses create lb-ipv1-1 --ip-version=IPV4 --global
   31  gcloud compute addresses describe lb-ipv1-1 --format="get(address)" --global
   32  gcloud compute backend-services create web-backend-service --port=HTTP --port-name=http --health-checks=basic-check --global
   33  gcloud compute backend-services create web-backend-service --protocol=HTTP --port-name=http --health-checks=basic-check --global
   34  history
   35  gcloud compute health-checks create http basic-check --port 80
   36  gcloud compute backend-services create web-backend-service --protocol=HTTP --port-name=http --health-checks=basic-check --global
   37  gcloud compute backend-services add-backend web-backed-service --instance-group=lb-backend-group --instance-group-zone=us-east1-b --global
   38  gcloud compute backend-services add-backend web-backend-service --instance-group=lb-backend-group --instance-group-zone=us-east1-b --global
   39  gcloud compute url-maps create web-map-http --default-service web-backend-service
   40  gcloud compute forwarding-rules create http-content-rule --address=lb-ipv1-1 --global --target-http-proxy=http-lb-proxy --ports=80
   41  gcloud compute target-http-proxies create http-lb-proxy --url-map web-map-http
   42  gcloud compute forwarding-rules create http-content-rule --address=lb-ipv1-1 --global --target-http-proxy=http-lb-proxy --ports=80
   43  history
   44  gcloud compute instance-templates create lb-backend-template --region=us-east1 --network=default --subnet=default --tags=allow-health-check --machine-type=f1-micro --metadata=startup-script='#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
echo "nginx google cloud platform - $HOSTNAME" | \
   45  history | grep instance-groups
   46  echo $HOSTNAME
   47  history











No comments:

Post a Comment