GKE CIDR Allocations

Because GCP's documentation continues to be terrible, here's some info if you need to calculate CIDR ranges for VPC peering. For example, let's say you need all your pod IPs to be on specifically /16.

If you set --cluster-ipv4-cidr="/16" on the cluster creation, you'll get a message warning you about how you'll have a limit of around 200 nodes in your cluster. This is because GCP pre-allocates all the ranges, even when the nodes aren't up. If you check the documentation on https://cloud.google.com/kubernetes-engine/docs/how-to/flexible-pod-cidr, you'll see that it calculates the ranges with \(2^{A-B}\), where \(B\) is the range you set before (maybe /16).

To find \(A\), scroll to the bottom of the page where it has the various pod CIDR ranges. You'll need to tweak the maximum number of pods per node. For example, if you have 8, use /28 for \(A\) in the calculation:


Posted: 2023-03-17
Filed Under: GCP, computer