You must have a valid Google account and log in to Google Cloud Console. https://console.cloud.google.com/
gcloud auth list
gcloud config list project
gcloud config set compute/zone asia-east1-a
gcloud config set compute/region asia-east1
gcloud compute instances create www1 \
--zone=asia-east1-a \
--tags=network-lb-tag \
--machine-type=e2-medium \
--image-family=debian-11 \
--image-project=debian-cloud \
--metadata=startup-script='#!/bin/bash
apt-get update
apt-get install apache2 -y
service apache2 restart
echo "
<h3>Web Server: www1</h3>" | tee /var/www/html/index.html'
gcloud compute instances create www2 \
--zone=asia-east1-a \
--tags=network-lb-tag \
--machine-type=e2-medium \
--image-family=debian-11 \
--image-project=debian-cloud \
--metadata=startup-script='#!/bin/bash
apt-get update
apt-get install apache2 -y
service apache2 restart
echo "
<h3>Web Server: www2</h3>" | tee /var/www/html/index.html'
gcloud compute firewall-rules create www-firewall-network-lb \
--target-tags network-lb-tag --allow tcp:80
gcloud compute instances list
gcloud compute addresses create network-lb-ip-1 \
--region asia-east1
gcloud compute http-health-checks create basic-check
gcloud compute target-pools create www-pool \
--region asia-east1 --http-health-check basic-check
gcloud compute target-pools add-instances www-pool \
--instances www1,www2
gcloud compute forwarding-rules create www-rule \
--region asia-east1 \
--ports 80 \
--address network-lb-ip-1 \
--target-pool www-pool
gcloud compute forwarding-rules describe www-rule --region asia-east1
IPADDRESS=$(gcloud compute forwarding-rules describe www-rule --region asia-east1 --format="json" | jq -r .IPAddress)
echo $IPADDRESS
curl http://$IPADDRESS
You will see the result from www1 and www2 when you curl the IPADDRESS more times