How do you find the cluster service CIDR of a Kubernetes cluster?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In a Kubernetes cluster, two critical components in network configuration are the Cluster CIDR and the Service CIDR. These IP ranges manage the allocation of IP addresses for Pods and Services, respectively. Knowing how to find and utilize these CIDRs effectively is vital for managing network policies, ensuring connectivity, and diagnosing network issues in the cluster. This article provides a detailed explanation on how to find these CIDRs within a Kubernetes cluster.
Understanding Cluster and Service CIDR
Cluster CIDR
The Cluster CIDR is an IP address block that is used for allocating IP addresses to Pods. Each node in the Kubernetes cluster receives a subnet from this range and manages the Pod IP allocations within its subnet.
Service CIDR
The Service CIDR is the IP address block used for allocating IP addresses to Services. These IPs are virtual and enable communication between Pods and external services.
Finding Cluster CIDR
Through kube-controller-manager
A common method to discover the Cluster CIDR is to review the kube-controller-manager logs or configurations. Use the following command to access the manifest or logs, depending on how the cluster is set up:
You should identify the controller-manager pod, then retrieve its logs:
Alternatively, inspecting the configuration files or command-line arguments used to start kube-controller-manager can also reveal the Cluster CIDR.
Using Kubernetes API
If the logs or configurations are inaccessible, utilize the Kubernetes API to gather cluster information. This requires knowledge of your cluster's API server endpoints and authentication tokens to access the cluster's API securely.
Finding Service CIDR
Through kube-apiserver
The Service CIDR is often specified in the kube-apiserver settings. By reviewing the /etc/kubernetes/manifests/kube-apiserver.yaml file on a control plane node, you can find the --service-cluster-ip-range flag, which specifies the Service CIDR.
Accessing these configs typically involves:
Verifying with Services
Another indirect method is to examine the IP range of services deployed:
By reviewing the IPs assigned to services, you can infer the Service CIDR if explicit configurations are hard to locate.
Key Considerations
- Permissions: Ensure you have the necessary permissions to access sensitive configuration files.
- Cluster Management: Tools such as kubeadm, GKE, and EKS may handle these configurations abstractly. Refer to specific cloud provider documentation for details.
- Cluster Networking Model: Some models, like certain CNI plugins, might abstract CIDR management, affecting direct access to these details.
Example
Suppose the following are the logs from kube-controller-manager:
And the kube-apiserver settings show:
Here, the Cluster CIDR is 10.244.0.0/16, and the Service CIDR is 10.96.0.0/12.
Table of Key Points
| Component | How to Find | Example Value |
| Cluster CIDR | Logs or manifest from kube-controller-manager
API resources may provide hints | 10.244.0.0/16 |
| Service CIDR | Configuration in kube-apiserver
Service object examination | 10.96.0.0/12 |
Additional Details
Impact on Network Policies
Understanding your Cluster and Service CIDR impacts how you write network policies. Network policies can allow or deny traffic among Pods and Services, reliant on knowing the correct IP ranges.
Multi-Tenant Cluster Considerations
In environments where multiple tenants are using a Kubernetes cluster, awareness of CIDR allocations is crucial for isolation, performance, and security configurations.
Conclusion
Navigating and identifying the CIDR allocations within Kubernetes is essential for effective cluster management. While this article provides a foundational approach, always consider specific configurations and versions, as they may influence how CIDRs are managed and retrieved. Equipped with this knowledge, you can more effectively manage and troubleshoot network configurations within your Kubernetes environment.
Related reading
- How do you get a Kubernetes pod's name from its IP address?
- How do you get kubectl to log in to an AWS EKS cluster?
- How do you put your source code into Kubernetes?
- How do you remove the deploymentConfig, image streams, etc using Openshift OC?
- How do you pass Authorization header through API Gateway to HTTP endpoint?
- How do you turn off swagger-ui in production
- How does gRPC connection work on kubernetes service ClusterIP
- How does k8s service route the traffic to mulitiple endpoints

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.