Arcade Simulator: DevOps Engineer
Solution for Arcade Simulator: DevOps Engineer. 1 lab: GSP216. Fast copy-paste commands for Google Cloud.
GSP216 — Enhance Application Reliability and Scalability with Internal Load Balancing
Estimated time: 15 minutes
# 🚀 Google Cloud Essential Skills: Internal Load Balancing > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created for educational purposes, hands-on practice, and Google Cloud certification preparation. This guide is designed to help learners understand Google Cloud networking, managed instance groups, and internal load balancing through practical exercises. Always attempt the lab yourself first and follow Google Cloud Skills Boost / Qwiklabs Terms of Service. This wal
#!/bin/bash
clear
# ==============================================================================
# ORBIT OF OPS COMMAND CENTER: GSP216 FLAWLESS MASTER SCRIPT (V6)
# ==============================================================================
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
CYAN=$(tput setaf 6)
MAGENTA=$(tput setaf 5)
WHITE=$(tput setaf 7)
BLUE=$(tput setaf 4)
BOLD=$(tput bold)
RESET=$(tput sgr0)
echo "${CYAN}${BOLD}"
echo " ____ _ _ _ __ ___ "
echo " / __ \ | | (_) | / _| / _ \ "
echo " | | | |_ __| |__ _| |_ ___ | |_ | | | |_ __ ___ "
echo " | | | | '__| '_ \| | __| / _ \ | _|| | | | '_ \/ __| "
echo " | |__| | | | |_) | | |_ | (_) || | | |_| | |_) \__ \ "
echo " \____/|_| |_.__/|_|\__| \___/ |_| \___/| .__/|___/ "
echo " | | "
echo " |_| "
echo "${RESET}"
echo "${MAGENTA}${BOLD}>>> INITIATING GSP216 AUTOMATION: PART 1 <<<${RESET}"
echo ""
echo "${YELLOW}${BOLD}[*] Step 1: Auto-fetching Region and Zones...${RESET}"
export REGION=$(gcloud compute project-info describe --format="value(commonInstanceMetadata.items[google-compute-default-region])")
export ZONE_1=$(gcloud compute project-info describe --format="value(commonInstanceMetadata.items[google-compute-default-zone])")
# Dynamically find a second zone in the same region for high availability
export ZONE_2=$(gcloud compute zones list --filter="region:$REGION AND name!=$ZONE_1" --format="value(name)" | head -n 1)
# Securely save variables for Command 2
echo "export REGION=$REGION" > ~/.orbit_env
echo "export ZONE_1=$ZONE_1" >> ~/.orbit_env
echo "export ZONE_2=$ZONE_2" >> ~/.orbit_env
echo -e "✅ Region: ${GREEN}$REGION${RESET}"
echo -e "✅ Zone 1: ${GREEN}$ZONE_1${RESET}"
echo -e "✅ Zone 2: ${GREEN}$ZONE_2${RESET}\n"
echo "${CYAN}${BOLD}[*] Step 2: Creating HTTP & Health Check Firewall Rules...${RESET}"
gcloud compute firewall-rules create app-allow-http \
--direction=INGRESS --priority=1000 --network=my-internal-app \
--action=ALLOW --rules=tcp:80 --source-ranges=10.10.0.0/16 \
--target-tags=lb-backend --quiet
gcloud compute firewall-rules create app-allow-health-check \
--direction=INGRESS --priority=1000 --network=my-internal-app \
--action=ALLOW --rules=tcp:80 --source-ranges=130.211.0.0/22,35.191.0.0/16 \
--target-tags=lb-backend --quiet
echo -e "\n${MAGENTA}${BOLD}[*] Step 3: Compiling Instance Templates for Subnets A & B...${RESET}"
gcloud compute instance-templates create instance-template-1 \
--machine-type=e2-micro --network=my-internal-app --subnet=subnet-a \
--tags=lb-backend --region=$REGION \
--metadata=startup-script-url=gs://cloud-training/gcpnet/ilb/startup.sh --quiet
gcloud compute instance-templates create instance-template-2 \
--machine-type=e2-micro --network=my-internal-app --subnet=subnet-b \
--tags=lb-backend --region=$REGION \
--metadata=startup-script-url=gs://cloud-training/gcpnet/ilb/startup.sh --quiet
echo -e "\n${GREEN}${BOLD}🎉 PART 1 COMPLETE! You can safely check your progress for Task 1. Then proceed to Command 2.${RESET}"# ==============================================================================
# ORBIT OF OPS COMMAND CENTER: GSP216 FLAWLESS MASTER SCRIPT (V6)
# ==============================================================================
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
CYAN=$(tput setaf 6)
MAGENTA=$(tput setaf 5)
WHITE=$(tput setaf 7)
BLUE=$(tput setaf 4)
BOLD=$(tput bold)
RESET=$(tput sgr0)
# Load saved variables
source ~/.orbit_env
echo -e "\n${MAGENTA}${BOLD}>>> INITIATING GSP216 AUTOMATION: PART 2 <<<${RESET}\n"
echo "${YELLOW}${BOLD}[*] Step 4: Creating Managed Instance Groups (MIGs) & Autoscalers...${RESET}"
gcloud compute instance-groups managed create instance-group-1 \
--base-instance-name=instance-group-1 --size=1 \
--template=instance-template-1 --zone=$ZONE_1 --quiet
gcloud compute instance-groups managed set-autoscaling instance-group-1 \
--zone=$ZONE_1 --cool-down-period=45 --max-num-replicas=1 \
--min-num-replicas=1 --target-cpu-utilization=0.8 --quiet
gcloud compute instance-groups managed create instance-group-2 \
--base-instance-name=instance-group-2 --size=1 \
--template=instance-template-2 --zone=$ZONE_2 --quiet
gcloud compute instance-groups managed set-autoscaling instance-group-2 \
--zone=$ZONE_2 --cool-down-period=45 --max-num-replicas=1 \
--min-num-replicas=1 --target-cpu-utilization=0.8 --quiet
echo -e "\n${CYAN}${BOLD}[*] Step 5: Provisioning Utility VM...${RESET}"
gcloud compute instances create utility-vm \
--zone=$ZONE_1 --machine-type=e2-micro --network=my-internal-app \
--subnet=subnet-a --private-network-ip=10.10.20.50 --quiet
echo -e "\n${BLUE}${BOLD}[*] Step 6: Building Internal Load Balancer (ILB) Architecture...${RESET}"
# 1. Health Check
gcloud compute health-checks create tcp my-ilb-health-check \
--region=$REGION --port=80 --quiet
# 2. Backend Service
gcloud compute backend-services create my-ilb \
--load-balancing-scheme=INTERNAL --protocol=TCP \
--region=$REGION --health-checks=my-ilb-health-check \
--health-checks-region=$REGION --quiet
# 3. Attach MIGs to Backend Service
gcloud compute backend-services add-backend my-ilb \
--region=$REGION --instance-group=instance-group-1 \
--instance-group-zone=$ZONE_1 --quiet
gcloud compute backend-services add-backend my-ilb \
--region=$REGION --instance-group=instance-group-2 \
--instance-group-zone=$ZONE_2 --quiet
# 4. Forwarding Rule (Frontend)
gcloud compute forwarding-rules create my-ilb-forwarding-rule \
--region=$REGION --load-balancing-scheme=INTERNAL \
--network=my-internal-app --subnet=subnet-b \
--address=10.10.30.5 --ip-protocol=TCP --ports=80 \
--backend-service=my-ilb --backend-service-region=$REGION --quiet
echo -e "\n"
echo "${GREEN}${BOLD}╔═════════════════════════════════════════════════════════════════════════╗${RESET}"
echo "${GREEN}${BOLD}║ 🚀 SUPERB PERFORMANCE! YOU HAVE MASTERED INTERNAL LOAD BALANCING! 🚀 ║${RESET}"
echo "${GREEN}${BOLD}║ ║${RESET}"
echo "${GREEN}${BOLD}║ All MIGs, Health Checks, and Forwarding Rules are actively deployed. ║${RESET}"
echo "${GREEN}${BOLD}║ Click 'Check my progress' on the remaining tasks to claim your 100%. ║${RESET}"
echo "${GREEN}${BOLD}╚═════════════════════════════════════════════════════════════════════════╝${RESET}"