Google Cloud Subnet Expansion

If the VPC subnet address space in a region ran out, the simplest way is to create a new subnet with the same mask in the same region(depends on your needs). Or you can expand the original subnet IP range.

VPC Overview Highlight

https://cloud.google.com/vpc/docs/vpc

  • VPC is global resource
  • resource within a VPC(regardless subnet) can communicate to each other, subject to firewall rules
  • shared VPC, keep a VPC in a common host project

Subnet Overview Highlight

https://cloud.google.com/vpc/docs/subnets

  • subnet is regional resource
  • subnet creation mode: auto and custom
  • you can create more than one subnet per region(for example to extend subnet capacity).
  • subnet IPV4 valid range: primary and secondary

Note, there is no need to create secondary subnet IP range for Alias IP. From observation, the subnet will have seconard IP ranges auto created if GKE is used in that network: it will create pods and services secondary IP ranges.

For example:

1
2
3
4
5
# check which node has pods secondary IP range:
gcloud compute instances list \
# the attribute path can be found through --format flattened
--filter="networkInterfaces[0].aliasIpRanges[0].subnetworkRangeName~'pods'" \
--project <project name>

Found VM attached with specified subnet:

1
2
3
gcloud compute instances list \
--filter="networkInterfaces[].subnetwork~'regions/us-east4/subnetworks/us-east4'" \
--project <project name>

Create and Modify Network

The primary IPv4 range for the subnet can be expanded, but not replaced or shrunk, after the subnet has been created. For example, the original primary IP range is 192.168.2.0/24(in private address space defined in gcloud), now set the prefix length to 21:

1
2
3
4
gcloud compute networks subnets expand-ip-range <subnet name> \
--region us-east4 \
--prefix-length=21 \
--project <project name>

Then the new IP range will be 192.168.0.0/21(bit set exceeds mask length is removed as it does not make sense), the expansion will fail if the new IP range conflicts with others.

0%