This chapter follows Continuous delivery with Cloud Build. On Google Cloud, a Virtual Private Cloud (VPC) network is a global logical network with regional subnets. Resources such as Compute Engine VMs, GKE nodes, and (with configuration) Cloud Run use RFC1918 addresses and firewall rules to control traffic.
For CIDR notation and routing theory, see IP addressing and IP routing. This page stays GCP-specific.
Global VPC and regional subnets
Unlike some clouds that scope a VPC to one region, a Google Cloud VPC network spans all regions. Subnets are regional slices of the VPC CIDR:
VPC: file-api-network (custom mode) subnet-run: 10.20.0.0/24 (europe-west1) subnet-data: 10.20.1.0/24 (europe-west1)Create a custom VPC and subnet:
gcloud compute networks create file-api-network --subnet-mode=custom
gcloud compute networks subnets create subnet-run \ --network=file-api-network \ --region=europe-west1 \ --range=10.20.0.0/24Auto mode creates one subnet per region automatically; custom mode (shown above) gives explicit control—preferred for production.
Firewall rules and hierarchical policies
VPC firewall rules filter traffic by source/destination tags, service accounts, or IP ranges. Default rules allow internal communication and SSH from certain paths; tighten them for least privilege.
Example: allow internal HTTP to tagged backends:
gcloud compute firewall-rules create allow-internal-http \ --network=file-api-network \ --allow=tcp:8080 \ --source-ranges=10.20.0.0/24 \ --target-tags=http-serverFirewall policies (organization/folder level) centralize rules across projects. Use them when security teams own baseline deny/allow sets.
Even when routing permits a path, firewalls may block it—the same separation as on-premises networks.
Routes, internet egress, and Cloud NAT
Routes send traffic to the internet, peered networks, or VPN tunnels. A subnet whose default route points to the internet gateway allows instances with public IPs to reach the internet directly.
Private VMs without public IPs use Cloud NAT for egress-only internet access:
gcloud compute routers create nat-router \ --network=file-api-network \ --region=europe-west1
gcloud compute routers nats create nat-config \ --router=nat-router \ --region=europe-west1 \ --auto-allocate-nat-external-ips \ --nat-all-subnet-ip-rangesNAT translates private sources to a public IP so return traffic succeeds.
Private Google Access
Private Google Access lets VMs without public IPs reach Google APIs (Cloud Storage, BigQuery, etc.) over Google’s network instead of the public internet. Enable on the subnet:
gcloud compute networks subnets update subnet-run \ --region=europe-west1 \ --enable-private-ip-google-accessCloud Run accessing GCS often uses Google’s managed paths; Direct VPC egress changes which IP ranges apply.
Peering and Shared VPC
VPC Network Peering connects two VPCs privately. CIDR ranges must not overlap. Peering is non-transitive: if A peers with B and B with C, A does not reach C through B.
Shared VPC lets a host project share subnets with service projects—common for platform teams that own networking and app teams that deploy into shared subnets.
Choose peering for two-team connectivity; Shared VPC for centralized network governance.
Cloud Run and Direct VPC egress
By default Cloud Run uses a Google-managed network path. Direct VPC egress sends outbound traffic from Cloud Run through your VPC so it can reach private IP resources (on-prem via VPN, Memorystore, internal load balancers):
gcloud run services update file-api \ --region=europe-west1 \ --network=file-api-network \ --subnet=subnet-run \ --vpc-egress=private-ranges-onlyprivate-ranges-only sends RFC1918 and select private destinations through the VPC; public internet may still use the default path depending on settings. Use all-traffic when all egress must traverse NAT in your VPC.
Pair egress rules with firewall allow lists so the runtime service account’s traffic is expected and logged.
Next: Protecting services with Cloud Armor puts a global load balancer and WAF in front of Cloud Run.
Check your understanding
Question 1 of 6
0 of 6 checked