You can list the active account name:
gcloud auth listTo set the active account, run:
gcloud config list projectYou can list the project ID with this command:
gcloud config list projectSet your region and zone:
gcloud config set compute/zone "ZONE"
export ZONE=$(gcloud config get compute/zone)
gcloud config set compute/region "REGION"
export REGION=$(gcloud config get compute/region)Enable the Compute Engine API by executing the following:
gcloud services enable compute.googleapis.comCreate Cloud Storage bucket
NOTE
Use of the
$DEVSHELL_PROJECT_IDenvironment variable within Cloud Shell is to help ensure the names of objects are unique. Since all Project IDs within Google Cloud must be unique, appending the Project ID should make other names unique as well.
gsutil mb gs://fancy-store-$DEVSHELL_PROJECT_IDCopy data from bucket to local dir
gsutil -m cp -r gs://fancy-store-[DEVSHELL_PROJECT_ID]/dir/* ./dirCreate a vm with starting script from bucket
export VMNAME=backend
export VMTYPE=e2-standard-2
export VMTAG=backend
gcloud compute instances create $VMNMAE \
--zone=$ZONE \
--machine-type=$VMTYPE \
--tags=backend \
--metadata=startup-script-url=https://storage.googleapis.com/fancy-store-$DEVSHELL_PROJECT_ID/startup-script.shlist instances of vm in the project
gcloud compute instances listCreate firewall rules to allow access to port 8080
gcloud compute firewall-rules create fw-fe \
--allow tcp:8080 \
--target-tags=$VMTAGstop vm
gcloud compute instances stop $VMNAME --zone=$ZONECreate managed instance groups
export INSGROUP=fancy-vm
gcloud compute instance-templates create INSGROUP \
--source-instance-zone=$ZONE \
--source-instance=$VMNAMElist template instances
gcloud compute instance-templates listdelete vm that we made template from
gcloud compute instances delete $VMNAME --zone=$ZONECreate managed instance group
export $MINSGROUP=fancy-be-mig
gcloud compute instance-groups managed create $MINSGROUP \
--zone=$ZONE \
--base-instance-name $INSGROUP \
--size 2 \
--template $INSGROUPSince these are non-standard ports, you specify named ports to identify these. Named ports are key:value pair metadata representing the service name and the port that it’s running on. Named ports can be assigned to an instance group, which indicates that the service is available on all instances in the group. This information is used by the HTTP Load Balancing service that will be configured later.
gcloud compute instance-groups set-named-ports $MINSGROUP \
--zone=$ZONE \
--named-ports orders:8081,products:8082Create a health check that repairs the instance if it returns “unhealthy” 3 consecutive times:
gcloud compute health-checks create http fancy-fe-hc \
--port 8080 \
--check-interval 30s \
--healthy-threshold 1 \
--timeout 10s \
--unhealthy-threshold 3