0
0
GCPcloud~5 mins

GCP global infrastructure (regions, zones) - Commands & Configuration

Choose your learning style9 modes available
Introduction
Cloud services run on computers in many places worldwide. GCP organizes these places into regions and zones to keep your apps fast and reliable.
When you want your app to be close to your users to reduce delay.
When you need to keep your app running even if one data center has a problem.
When you want to spread your app across different locations for safety.
When you want to choose where your data is stored for legal reasons.
When you want to balance traffic between different places automatically.
Commands
This command shows all the regions where GCP has data centers. Regions are big areas like countries or parts of countries.
Terminal
gcloud compute regions list
Expected OutputExpected
NAME DESCRIPTION us-central1 Iowa us-east1 South Carolina europe-west1 Belgium asia-east1 Taiwan asia-southeast1 Singapore
This command lists all zones inside regions. Zones are smaller parts inside regions, like different buildings in a city.
Terminal
gcloud compute zones list
Expected OutputExpected
NAME REGION STATUS us-central1-a us-central1 UP us-central1-b us-central1 UP us-central1-c us-central1 UP europe-west1-b europe-west1 UP asia-east1-a asia-east1 UP
This command creates a virtual machine in the us-central1-a zone. You pick a zone to decide where your machine runs.
Terminal
gcloud compute instances create example-instance --zone=us-central1-a
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-instance]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-instance us-central1-a e2-medium 10.128.0.2 34.68.194.64 RUNNING
--zone - Specifies the zone where the instance will be created
This command checks that your virtual machine is running in the zone you chose.
Terminal
gcloud compute instances list --filter="name=example-instance"
Expected OutputExpected
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-instance us-central1-a e2-medium 10.128.0.2 34.68.194.64 RUNNING
--filter - Filters the list to show only the instance named example-instance
Key Concept

If you remember nothing else from this pattern, remember: regions are big areas and zones are smaller parts inside them where your resources run.

Common Mistakes
Trying to create resources without specifying a zone.
GCP needs a zone to know exactly where to place your resource; without it, the command fails.
Always include the --zone flag with a valid zone when creating resources.
Choosing a zone far from your users without thinking about latency.
Your app will be slower for users if the zone is far away.
Pick zones close to your users to reduce delay.
Summary
Use 'gcloud compute regions list' to see all available regions.
Use 'gcloud compute zones list' to see zones inside regions.
Specify a zone when creating resources to control their location.
Check your resources with 'gcloud compute instances list' filtered by name.