Skip to content

ClusterIP service type

ClusterIP is the default Service type in Kubernetes, represented as ClusterIP in the TYPE column when listing services.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]

Service Exposure

This type assigns a virtual IP address from the cluster's internal network range, often referred to as the CLUSTER-IP.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md] For example, a service might be assigned an IP like 10.96.87.175.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]

Access to the service is restricted to within the cluster. The source material demonstrates internal access by executing commands from a master node to the Service IP (e.g., curl 10.96.87.175:8000), confirming reachability from cluster-internal hosts.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md] Access is not available from external networks.

Internal DNS Resolution

Kubernetes provides an internal DNS mechanism that allows pods to discover services using standard naming conventions, rather than just static IP addresses.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]

There are two primary methods to resolve a ClusterIP service from within a pod^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]:

  • Service Name: Requests can be made using the service name directly (e.g., curl nginx-deployment-service:8080).
  • Fully Qualified Domain Name (FQDN): Requests can use the full DNS path, which follows the pattern <service-name>.<namespace>.svc (e.g., curl nginx-deployment-service.default.svc:8080).

Load Balancing

The ClusterIP virtual IP acts as a stable frontend for a set of backend pods.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md] Traffic arriving at the ClusterIP is automatically load-balanced across the healthy pods selected by the service.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]

This is demonstrated in the source logs where repeated curl requests to the single ClusterIP (10.96.87.175:8000) return different responses (111, 333, 222), indicating that requests were distributed to different backend pods hosting the application.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]

Creation

A ClusterIP service can be created using kubectl expose by defining a port mapping between the service port and the target container port.^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]

The following command creates a service named nginx-deployment that listens on port 8000 and forwards traffic to port 80 on the selected pods^[400-devops__06-Kubernetes__k8s-learning__05.service__service.md]:

[kubectl](<./kubectl.md>) expose deploy nginx-deployment --port=8000 --target-port=80

Sources

  • 400-devops__06-Kubernetes__k8s-learning__05.service__service.md