Google Cloud Tutorial · Networking · Lesson 15 of 27
VPC Networks and Subnets
Google Cloud's global VPC networks, regional subnets, IP ranges for GKE, Shared VPC and connecting networks.
A global network with regional subnets
A VPC network in Google Cloud is global: it isn't tied to a region. You add subnets in the regions you
use, each with an IP range. VMs in europe-west1 and us-central1 subnets of the same network talk over internal
IPs on Google's backbone, with no peering or VPN.
Use custom mode networks (you choose every subnet) for production; auto mode creates a subnet in every region with fixed ranges that often clash with other networks.
gcloud compute networks create acme-vpc --subnet-mode=custom
gcloud compute networks subnets create orders-euw1 --network=acme-vpc --region=europe-west1 \
--range=10.10.0.0/20 --secondary-range=pods=10.20.0.0/14,services=10.24.0.0/20 \
--enable-private-ip-google-access
Planning IP ranges
GKE clusters need secondary ranges for Pods and Services. Pod ranges are consumed quickly (by default each node gets a /24 for up to 110 Pods), so plan them generously and make sure no range overlaps networks you'll connect to.
import ipaddress
subnet = ipaddress.ip_network("10.10.0.0/20")
pods = ipaddress.ip_network("10.20.0.0/14")
services = ipaddress.ip_network("10.24.0.0/20")
print(f"Node subnet {subnet}: {subnet.num_addresses - 4} usable VM addresses")
per_node = 256 # a /24 per node by default
print(f"Pod range {pods}: room for {pods.num_addresses // per_node} nodes")
print(f"Service range {services}: {services.num_addresses} Service IPs")
office = ipaddress.ip_network("10.24.8.0/22")
print("Overlaps the office network?", services.overlaps(office))
Output
Node subnet 10.10.0.0/20: 4092 usable VM addresses Pod range 10.20.0.0/14: room for 1024 nodes Service range 10.24.0.0/20: 4096 Service IPs Overlaps the office network? True
Sharing and connecting networks
- Shared VPC: a central host project owns the network; app teams deploy into its subnets from their own service projects.
- VPC Network Peering: private connectivity between two networks (not transitive).
- Network Connectivity Center: a hub for connecting many networks and on-premises sites.
- Cloud VPN and Cloud Interconnect connect on-premises networks.
Test yourself
In Google Cloud, what is regional: the VPC network or its subnets?
The VPC networkIts subnetsBothNeither
Show answer
Answer: Its subnets
The network is global; each subnet lives in one region.