How do you find the cluster & service CIDR of a Kubernetes cluster?

kubectl describe cm kubeadm-config -n kube-system |grep Subnet


Did you check if the following command contains the info you need?

kubectl cluster-info dump


I spent hours searching for a generic way to do this. I gave up searching and wrote my own. As of Kubernetes 1.18, this method works across cloud providers, beyond just GKE.

SVCRANGE=$(echo '{"apiVersion":"v1","kind":"Service","metadata":{"name":"tst"},"spec":{"clusterIP":"1.1.1.1","ports":[{"port":443}]}}' | kubectl apply -f - 2>&1 | sed 's/.*valid IPs is //')
echo $SVCRANGE
172.21.0.0/16

This one liner works by feeding an invalid service cluster IP into kubectl apply and parsing the error output, which provides the service CIDR information.


Get Services IPs range

kubectl cluster-info dump | grep -m 1 service-cluster-ip-range

You will see something like e.g. --service-cluster-ip-range=xxx.yy.0.0/13

Get Pods IPs range

kubectl cluster-info dump | grep -m 1 cluster-cidr

You will see something like e.g. --cluster-cidr=xxx.yy.0.0/11