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 | # check which node has pods secondary IP range: |
Found VM attached with specified subnet:
1 | gcloud compute instances list \ |
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 | gcloud compute networks subnets expand-ip-range <subnet 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.