Skip to content

Instantly share code, notes, and snippets.

@philipz
Last active May 20, 2021 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipz/c9da0720536260bee1d73e64546dff10 to your computer and use it in GitHub Desktop.
Save philipz/c9da0720536260bee1d73e64546dff10 to your computer and use it in GitHub Desktop.
Create and Manage Cloud Resources: Challenge Lab

Task1

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

Task2

gcloud config set compute/zone us-east1-b

gcloud container clusters create cluster1

gcloud container clusters get-credentials cluster1

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

Task3

Create startup.sh

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
  1. Create an instance template
gcloud compute instance-templates create nginx-template \
--tags=allow-http-tag --metadata-from-file startup-script=startup.sh
  1. Create a target pool
gcloud compute target-pools create nginx-pool --region us-east1
  1. 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
  1. Create a firewall rule to allow traffic (80/tcp)
gcloud compute firewall-rules create www-firewall --target-tags allow-http-tag --allow tcp:80

gcloud compute forwarding-rules create nginx-lb \
--region us-east1 \
--ports=80 \
--target-pool nginx-pool

gcloud compute forwarding-rules list
  1. 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
  1. 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
  1. 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
  1. Create a forwarding rule
gcloud compute forwarding-rules create http-content-rule \
--global \
--target-http-proxy http-lb-proxy \
--ports 80

gcloud compute forwarding-rules list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment