For the below manifest to create service type(CluserIP):
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app.kubernetes.io/name: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
Assume that K8s is hosted in Azure cloud(AKS).
What is the IP address that K8s cluster assign to this service? Is it based on the AWS subnet(within VPC/VNET) IP range(where K8s cluster is hosted)?
In a Kubernetes cluster hosted on a cloud platform like Azure Kubernetes Service (AKS), the service CIDR range is typically configured to align with the cloud provider's networking setup to avoid IP conflicts. This means that the service CIDR range is chosen in such a way that it does not overlap with the VNet IP range where the AKS cluster is hosted.
To find the specific IP range used for services in your AKS cluster, you can check the cluster configuration. This information is usually set when the cluster is initially created and can be found in the AKS cluster's networking settings. You can use Azure CLI or Azure portal to view these details.
The actual IP address assigned to a specific service (like
my-servicein your example) is dynamically allocated from within this service CIDR range and is managed by Kubernetes. You typically do not control or predict the exact IP address; Kubernetes handles this allocation to ensure each service gets a unique IP within the cluster.To view the assigned ClusterIP for your service, you can run the command
kubectl get service my-serviceafter creating the service in your AKS cluster. This will display the ClusterIP assigned to your service along with other details.So now if I take an example of the sample AKS cluster network configuration,
Pod CIDR:
10.244.0.0/1610.244.0.1to10.244.255.254.Service CIDR:
10.0.0.0/16ClusterIPsfor services from this range. The range for your services' ClusterIPs is from10.0.0.1to10.0.255.254.DNS Service IP:
10.0.0.10Cluster IP of the
kubernetesService:10.0.0.1Cluster IP of
my-service:10.0.169.125my-service). It's also within your defined service CIDR.So, summarizing:
10.244.0.1to10.244.255.254.kubernetesandmy-service) can have IPs in the range of10.0.0.1to10.0.255.254.Reference Document: official K8s cluster-IP allocation document