<p>How can one inquire the Kubernetes pod and service subnets in use (e.g. <code>10.244.0.0/16</code> and <code>10.96.0.0/12</code> respectively) from inside a Kubernetes cluster in a portable and simple way?</p>

<p>For instance, <code>kubectl get cm -n kube-system kubeadm-config -o yaml</code> reports <code>podSubnet</code> and <code>serviceSubnet</code>. But this is not fully portable because a cluster may have been set up by another means than <code>kubeadm</code>.</p>

<p><code>kubectl get cm -n kube-system kube-proxy -o yaml</code> reports <code>clusterCIDR</code> (i.e. pod subnet) and <code>kubectl get pod -n kube-system kube-apiserver-master1 -o yaml</code> reports the value
passed as command-line option <code>--service-cluster-ip-range</code> to <code>kube-apiserver</code> (i.e. service subnet). <code>master1</code> stands for the name of any control plane node. But this seems a bit complex.</p>

<p>Is there a better way available e.g. with the Kubernetes 1.17 API?</p>

rookie099
<p>I don't think it would be possible to obtain what you want in a portable and simple way.
If you don't specify Cidr's parameters it will assign default one.</p>

<p>As you have many ways to run kubernetes as unmanaged clusters like kubeadm, minikbue, k3s, micork8s or managed like Cloud providers (GKE, Azure, AWS) it's hard to find one way to list all cidrs in all environments. Another obstacle can be versions of Kubernetes or CNI. </p>

<p>In Kubernetes 1.17 <a href="https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.17.md#deprecations-and-removals" rel="nofollow noreferrer">Release notes</a> you can find information that </p>

<blockquote>
  <p>Deprecate the default service IP CIDR. The previous default was <code>10.0.0.0/24</code> which will be removed in 6 months/2 releases. Cluster admins must specify their own desired value, by using <code>--service-cluster-ip-range</code> on kube-apiserver.</p>
</blockquote>

<p>As example of Kubeadm: <code>$ kubeadm init --pod-network-cidr 10.100.0.0/12 --service-cidr 10.99.0.0/12</code></p>

<p>There are a few ways to get this pod and service-cidr:</p>

<pre><code>$ kubectl cluster-info dump | grep -E '(service-cluster-ip-range|cluster-cidr)'
                            "--service-cluster-ip-range=10.99.0.0/12",
                            "--cluster-cidr=10.100.0.0/12",



$ kubeadm config view | grep Subnet
  podSubnet: 10.100.0.0/12
  serviceSubnet: 10.99.0.0/12
</code></pre>

<p>But if you will check all pods in this cluster, some pods are starting with 192.168.190.X or 192.168.137.X</p>

<pre><code>$ kubectl get pods -A -owide
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE    IP                NODE             NOMINATED NODE   READINESS GATES
default       nginx                                      1/1     Running   0          62m    192.168.190.129   kubeadm-worker   &lt;none&gt;           &lt;none&gt;
kube-system   calico-kube-controllers-77c5fc8d7f-9n6m5   1/1     Running   0          118m   192.168.137.66    kubeadm-master   &lt;none&gt;           &lt;none&gt;
kube-system   calico-node-2kx2v                          1/1     Running   0          117m   10.128.0.4        kubeadm-worker   &lt;none&gt;           &lt;none&gt;
kube-system   calico-node-8xqd9                          1/1     Running   0          118m   10.128.0.3        kubeadm-master   &lt;none&gt;           &lt;none&gt;
kube-system   coredns-66bff467f8-sgmkw                   1/1     Running   0          120m   192.168.137.65    kubeadm-master   &lt;none&gt;           &lt;none&gt;
kube-system   coredns-66bff467f8-t84ht                   1/1     Running   0          120m   192.168.137.67    kubeadm-master   &lt;none&gt;           &lt;none&gt;
</code></pre>

<p>If you will describe any <code>CNI</code> pods you can find another CIDRs:</p>

<pre><code>CALICO_IPV4POOL_CIDR:               192.168.0.0/16
</code></pre>

<p>For GKE example you will have:
node CIDRs</p>

<pre><code>$ kubectl describe node | grep CIDRs
PodCIDRs:                     10.52.1.0/24
PodCIDRs:                     10.52.0.0/24
PodCIDRs:                     10.52.2.0/24

$ gcloud container clusters describe cluster-2 --zone=europe-west2-b | grep Cidr
clusterIpv4Cidr: 10.52.0.0/14
  clusterIpv4Cidr: 10.52.0.0/14
  clusterIpv4CidrBlock: 10.52.0.0/14
  servicesIpv4Cidr: 10.116.0.0/20
  servicesIpv4CidrBlock: 10.116.0.0/20
  podIpv4CidrSize: 24
servicesIpv4Cidr: 10.116.0.0/20
</code></pre>

<p>Honestly I don't think there is an easy and portable way to list all podCidrs and serviceCidrs in one simple command. </p>
