<p>The <code>--cluster-cidr</code> / <code>--pod-network-cidr</code> is fed to <code>kube-controller-manager</code> config.</p>

<p>You can simply do <code>ps -ef | grep "cluster-cidr"</code> to get what you want.</p>

CC BY-SA 4.0
2019-07-01T11:03:02.550Z
2019-07-01T11:03:02.550Z
Vignesh SP
<p>It's in file <code>/etc/kubernetes/manifests/kube-controller-manager.yaml</code></p>

<pre><code># sudo grep cidr /etc/kubernetes/manifests/kube-*
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --allocate-node-cidrs=true
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --cluster-cidr=192.168.0.0/16
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --node-cidr-mask-size=24
</code></pre>

CC BY-SA 4.0
2019-05-22T10:47:55.483Z
2019-05-22T10:47:55.483Z
ttimasdf
<p>There are a few options (combining the existing answers and adding option for Calico, including example ouput):</p>

<p><strong>Option 1</strong>: Run this command On the master node (also applicable when running for example microk8s on Ubuntu)</p>

<ul>
<li><strong>kubeadm config view | grep Subnet</strong></li>
</ul>

<p>example output from local 3 node cluster, master node</p>

<pre><code>podSubnet: 172.16.0.0/16
serviceSubnet: 10.96.0.0/12
</code></pre>

<p><strong>Option 2</strong>: Run this command on the master node:</p>

<ul>
<li><strong>ps -ef | grep cluster-cidr</strong></li>
</ul>

<p>example output from local machine running microk8s</p>

<pre><code>vincent   6841 27089  0 09:52 pts/7    00:00:00 grep --color=auto cluster-cidr
root      7053     1  0 feb12 ?        00:00:14 /snap/microk8s/1173/kube-proxy --kubeconfig=/var/snap/microk8s/1173/credentials/proxy.config --cluster-cidr=10.152.183.0/24 --healthz-bind-address=127.0.0.1
</code></pre>

<p><strong>Option 3</strong>: Run this command on the master node:</p>

<ul>
<li><strong>sudo grep cidr /etc/kubernetes/manifests/kube-*</strong></li>
</ul>

<p>Example output of same master node:</p>

<pre><code>/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --allocate-node-cidrs=true
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --cluster-cidr=172.16.0.0/16
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --node-cidr-mask-size=24
</code></pre>

<p>If you run Calico you have the option to use calicoctl:</p>

<p><a href="https://docs.projectcalico.org/v3.5/usage/calicoctl/install" rel="nofollow noreferrer">https://docs.projectcalico.org/v3.5/usage/calicoctl/install</a></p>

<p>This documentation shows how to show and also change the cidr:
<a href="https://docs.projectcalico.org/v3.2/usage/changing-ip-pools" rel="nofollow noreferrer">https://docs.projectcalico.org/v3.2/usage/changing-ip-pools</a></p>

<p><strong>Option 4</strong> (Calico): Run this command to view the cidr:</p>

<ul>
<li><strong>CALICO_KUBECONFIG=~/.kube/config DATASTORE_TYPE=kubernetes calicoctl get ippool -o wide</strong></li>
</ul>

<p>Example output for the same cluster (works from any place that has the proper kubectl config and connection to the cluster):</p>

<pre><code>NAME                  CIDR            NAT    IPIPMODE   DISABLED   SELECTOR   
default-ipv4-ippool   172.16.0.0/16   true   Always     false      all()
</code></pre>

<p>Depending on your network option, you may have other options which are hopefully documented in the respective documentation.</p>

CC BY-SA 4.0
2020-02-13T09:14:01.837Z
2020-02-13T09:14:01.837Z
Vincent Gerris
<p>With kubeadm</p>

<p><code>kubeadm config view | grep Subnet</code></p>

CC BY-SA 4.0
2019-12-27T07:44:51.687Z
Thanks for posting an answer. Could you explain what is the difference with the other commands that were provided in the other answer and could you add an example of the output of this command?
030
CC BY-SA 4.0
2022-05-29T04:09:55.847Z
I get invalid subcommand: "view"  kubeadm version: &version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.9", GitCommit:"6df4433e288edc9c40c2e344eb336f63fad45cd2",
user1325696
CC BY-SA 4.0
2019-12-26T21:11:04.860Z
2019-12-26T21:11:04.860Z
user3165768
<p>To get Service IP range - i.e. IP's assigned to ClusterIP, the command is:</p>
<ul>
<li><code>ps -aux | grep kube-apiserver | grep service-cluster-ip-range</code> (you can run this on master node)</li>
<li><code>cat /etc/kubernetes/manifests/kube-apiserver.yaml | grep service-cluster-ip-range</code></li>
</ul>
<p>To find the Pod network range, when you have defined your cluster using kubeadm 1.22 and used weave as your networking addon:
first find the weave pod name using</p>
<p><code>kubectl get pod -n kube-system | grep weave</code></p>
<p>Copy any one name out of the three pod names.</p>
<pre><code>kubectl -n kube-system logs &lt;&lt;weave-net-podname-from-above-step&gt;&gt; -c weave | grep ipalloc-range
</code></pre>
<p>you will find either default i.e. 10.32.0.0/12 or whatever range you assigned during kubeadm init</p>

CC BY-SA 4.0
2021-11-29T01:31:27.910Z
2021-11-29T07:32:56.567Z
2021-11-29T07:32:56.567Z
Mayur
<p>This command will give you the pod CIDR addresses for each of the nodes in your cluster.</p>

<p><code>kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'</code> </p>

CC BY-SA 4.0
2020-01-09T10:42:46.737Z
It's blank in my case `"spec": {},`
Chris Stryczynski
CC BY-SA 4.0
2023-11-03T04:26:34.820Z
It was blank in my case too earlier but passing --pod-network-cidr during kubeadm reinitialisation resolved this
ddlr
CC BY-SA 4.0
2024-05-24T12:28:29.693Z
Unfortunately, that field is not always set in the Node structure.
allprog
CC BY-SA 4.0
2019-01-07T14:41:05.660Z
2019-01-07T14:41:05.660Z
Marcus
<p>This will show pod network CIDR which used by <code>kube-proxy</code></p>

<pre><code>kubectl cluster-info dump | grep -m 1 cluster-cidr
</code></pre>

CC BY-SA 4.0
2021-10-02T04:06:35.273Z
This returns nothing in my case.
StaticMethod
CC BY-SA 4.0
2019-06-27T11:55:30.280Z
2019-06-27T11:55:30.280Z
SamBundy
<p>my version of <code>kubeadm</code> is 1.22 and the command to view defaults is <code>kubeadm config print init-defaults</code>, towards the bottom:</p>
<pre><code>networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
</code></pre>

CC BY-SA 4.0
2022-08-08T16:40:13.987Z
This is the only answer here that worked for me (K8s v. 1.24.0) - thank you.
SamAndrew81
CC BY-SA 4.0
2022-09-15T22:09:02.867Z
For me too, the only answer that works! Thanks!
Mohammed Noureldin
CC BY-SA 4.0
2023-11-02T05:24:30.450Z
Same for me too
ddlr
CC BY-SA 4.0
2024-03-22T07:20:20.347Z
WARNING, I wanna put emphasis on the fact that this is NOT your actually configured cidr range for the cluster but only what `kubeadm init` defaults too. This works for OP because they didn't specify a pod cidr, but ONLY works in this case !
adamency
CC BY-SA 4.0
2021-10-21T20:44:04.063Z
2021-10-21T20:44:04.063Z
Paul42
<p>This works practically in any cluster:</p>
<pre><code>kubectl create service clusterip testcidr \
          --tcp='8080:8080' --clusterip='1.0.0.0'

error: failed to create ClusterIP service: Service &quot;testcidr&quot;
is invalid: spec.clusterIPs: Invalid value: []string{&quot;1.0.0.0&quot;}: 
failed to allocate IP 1.0.0.0: the provided IP (1.0.0.0) is not in 
the valid range. The range of valid IPs is 192.168.192.0/24
</code></pre>
<p>The idea is to try to create a service outside the allowed CIDR and the error message will contain the valid range.</p>

CC BY-SA 4.0
2024-05-24T12:27:09.013Z
2024-05-24T12:27:09.013Z
allprog
<p>I have a running k8s cluster initialized with <code>kubeadm</code>. </p>

<p>On initialization, I did not pass the option <code>--pod-network-cidr</code></p>

<p>How do I get the CIDR of the pod network</p>

<p>I tried </p>

<ul>
<li>Looking at the <code>/etc/kubernetes/manifests/kube-apiserver.yaml</code> which seems to be the manifest for kube-apiserver used by <code>kubeadm</code> but that information is not included</li>
<li>Looking at the <a href="https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/" rel="noreferrer"><code>kubeadm</code> document</a> but I couldn't find a default value</li>
</ul>

<kubernetes><networking>
How to get kubernetes pod network CIDR
Tran Triet
# How to get kubernetes pod network CIDR

(Asked by: username_0 on 2019-01-07)

I have a running k8s cluster initialized with `kubeadm`.

On initialization, I did not pass the option `--pod-network-cidr`

How do I get the CIDR of the pod network

I tried

* Looking at the `/etc/kubernetes/manifests/kube-apiserver.yaml` which seems to be the manifest for kube-apiserver used by `kubeadm` but that information is not included
* Looking at the [`kubeadm` document](https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/) but I couldn't find a default value

**Tags:** kubernetes, networking


---

## 9 answers

### Answer by username_8 on 2019-01-07. Score: 30

This command will give you the pod CIDR addresses for each of the nodes in your cluster.

`kubectl get nodes -o jsonpath='{.items[*].spec.podCIDR}'`

> **Comments:**
> **username_9**: It's blank in my case `"spec": {},`  
> **username_10**: It was blank in my case too earlier but passing --pod-network-cidr during kubeadm reinitialisation resolved this  
> **username_11**: Unfortunately, that field is not always set in the Node structure.  

---

### Answer by username_12 on 2019-06-27. Score: 14

This will show pod network CIDR which used by kube-proxy
kubectl cluster-info dump | grep -m 1 cluster-cidr

> **Comments:**
> **username_13**: This returns nothing in my case.  

---

### Answer by username_14 on 2021-10-21. Score: 11

my version of kubeadm is 1.22 and the command to view defaults is kubeadm config print init-defaults, towards the bottom:
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12

> **Comments:**
> **username_15**: This is the only answer here that worked for me (K8s v. 1.24.0) - thank you.  
> **username_16**: For me too, the only answer that works! Thanks!  
> **username_10**: Same for me too  
> **username_17**: WARNING, I wanna put emphasis on the fact that this is NOT your actually configured cidr range for the cluster but only what `kubeadm init` defaults too. This works for OP because they didn't specify a pod cidr, but ONLY works in this case !  

---

### Answer by username_1 on 2019-07-01. Score: 5

The `--cluster-cidr` / `--pod-network-cidr` is fed to `kube-controller-manager` config.

You can simply do `ps -ef | grep "cluster-cidr"` to get what you want.


---

### Answer by username_2 on 2019-05-22. Score: 3

It's in file /etc/kubernetes/manifests/kube-controller-manager.yaml
# sudo grep cidr /etc/kubernetes/manifests/kube-*
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --allocate-node-cidrs=true
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --cluster-cidr=192.168.0.0/16
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --node-cidr-mask-size=24


---

### Answer by username_3 on 2020-02-13. Score: 2

There are a few options (combining the existing answers and adding option for Calico, including example ouput):
Option 1: Run this command On the master node (also applicable when running for example microk8s on Ubuntu)

kubeadm config view | grep Subnet

example output from local 3 node cluster, master node
podSubnet: 172.16.0.0/16
serviceSubnet: 10.96.0.0/12

Option 2: Run this command on the master node:

ps -ef | grep cluster-cidr

example output from local machine running microk8s
vincent   6841 27089  0 09:52 pts/7    00:00:00 grep --color=auto cluster-cidr
root      7053     1  0 feb12 ?        00:00:14 /snap/microk8s/1173/kube-proxy --kubeconfig=/var/snap/microk8s/1173/credentials/proxy.config --cluster-cidr=10.152.183.0/24 --healthz-bind-address=127.0.0.1

Option 3: Run this command on the master node:

sudo grep cidr /etc/kubernetes/manifests/kube-*

Example output of same master node:
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --allocate-node-cidrs=true
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --cluster-cidr=172.16.0.0/16
/etc/kubernetes/manifests/kube-controller-manager.yaml:    - --node-cidr-mask-size=24

If you run Calico you have the option to use calicoctl:
https://docs.projectcalico.org/v3.5/usage/calicoctl/install
This documentation shows how to show and also change the cidr:
https://docs.projectcalico.org/v3.2/usage/changing-ip-pools
Option 4 (Calico): Run this command to view the cidr:

CALICO_KUBECONFIG=~/.kube/config DATASTORE_TYPE=kubernetes calicoctl get ippool -o wide

Example output for the same cluster (works from any place that has the proper kubectl config and connection to the cluster):
NAME                  CIDR            NAT    IPIPMODE   DISABLED   SELECTOR   
default-ipv4-ippool   172.16.0.0/16   true   Always     false      all()

Depending on your network option, you may have other options which are hopefully documented in the respective documentation.


---

### Answer by username_4 on 2019-12-26. Score: 2

With kubeadm

`kubeadm config view | grep Subnet`

> **Comments:**
> **username_5**: Thanks for posting an answer. Could you explain what is the difference with the other commands that were provided in the other answer and could you add an example of the output of this command?  
> **username_6**: I get invalid subcommand: "view"  kubeadm version: &version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.9", GitCommit:"6df4433e288edc9c40c2e344eb336f63fad45cd2",  

---

### Answer by username_7 on 2021-11-29. Score: 2

To get Service IP range - i.e. IP's assigned to ClusterIP, the command is:

ps -aux | grep kube-apiserver | grep service-cluster-ip-range (you can run this on master node)
cat /etc/kubernetes/manifests/kube-apiserver.yaml | grep service-cluster-ip-range

To find the Pod network range, when you have defined your cluster using kubeadm 1.22 and used weave as your networking addon:
first find the weave pod name using
kubectl get pod -n kube-system | grep weave
Copy any one name out of the three pod names.
kubectl -n kube-system logs <> -c weave | grep ipalloc-range

you will find either default i.e. 10.32.0.0/12 or whatever range you assigned during kubeadm init


---

### Answer by username_11 on 2024-05-24. Score: 0

This works practically in any cluster:
kubectl create service clusterip testcidr \
          --tcp='8080:8080' --clusterip='1.0.0.0'

error: failed to create ClusterIP service: Service "testcidr"
is invalid: spec.clusterIPs: Invalid value: []string{"1.0.0.0"}: 
failed to allocate IP 1.0.0.0: the provided IP (1.0.0.0) is not in 
the valid range. The range of valid IPs is 192.168.192.0/24

The idea is to try to create a service outside the allowed CIDR and the error message will contain the valid range.


---

