In this lesson, you will learn how to use the ClusterIP service type to provide a permanent, stable networking address for your dynamic group of application Pods.
The Problem: Ephemeral Pod IPs
As we discussed previously, Pods are ephemeral; they are created and destroyed constantly as Deployments scale or perform rolling updates. Every time a Pod restarts, it receives a brand-new IP address. If your front-end application hardcoded the IP address of a back-end Pod, that connection would break the moment the back-end Pod was replaced.
The Solution: Stable Virtual Networking
A ClusterIP Service acts as a persistent "middleman." It provides a single, stable virtual IP address that remains constant, regardless of how many Pods are running behind it or how often they change.
When you create a ClusterIP Service, you define selector labels that match your target Pods. Kubernetes then automatically monitors those Pods, keeping a list of all currently healthy ones. When another part of your application sends traffic to the ClusterIP address, Kubernetes handles the routing, load-balancing that traffic across the active Pods.
Example Configuration
To create this bridge, you define a Service resource like this:
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: ClusterIP
selector:
app: backend
ports:
- port: 80
targetPort: 8080
In this example, any traffic sent to backend-service on port 80 is routed to port 8080 on any Pod labeled app: backend. Because the Service name and its virtual IP don't change, your front-end application can reliably connect to the backend-service name via internal DNS without ever needing to know the specific, changing IP addresses of the individual Pods. This creates a stable internal network where your services can talk to each other seamlessly, even while the underlying Pods are in constant flux.
Key Takeaway: The ClusterIP Service provides a consistent, stable entry point for internal traffic, decoupling your communication logic from the volatile lifecycle of individual Pods.