ClusterIP Services
ClusterIP is the default Service type, reachable only from inside the cluster.
Syntax
spec:
type: ClusterIP # default, can be omitted
selector: { app: <label> }
ports:
- port: <port>
targetPort: <containerPort>ClusterIP is the default Service type. It gives your Pods a virtual IP that is reachable only from within the cluster — perfect for internal traffic between microservices.
When to use it
- A backend API that only your frontend Pods call.
- A database or cache that should never be exposed publicly.
- Any service-to-service communication inside the cluster.
Reaching it
Other Pods connect using the Service's DNS name, typically just its name within the same namespace. No IP addresses to remember.
Example
apiVersionv1
kindService
metadata
namebackend
spec
typeClusterIP
selector
appbackend
ports
port8080
targetPort8080
# Reach it from another Pod as: http://backend:8080When to use it
- A backend API Service is exposed as ClusterIP so only other pods inside the cluster can call it, preventing any external access.
- A Redis cache is published as a ClusterIP Service so application pods can connect to redis-svc:6379 without knowing any pod IPs.
- A headless ClusterIP Service (clusterIP: None) lets StatefulSet pods discover peer pods via DNS for peer-to-peer clustering.
More examples
ClusterIP Service for internal API
Creates a ClusterIP Service accessible only within the cluster at api-internal:8080, selecting all pods labelled app=api.
apiVersion: v1
kind: Service
metadata:
name: api-internal
spec:
type: ClusterIP
selector:
app: api
ports:
- port: 8080
targetPort: 8080Test ClusterIP connectivity
Tests a ClusterIP Service from within the cluster using both the short name and the full DNS name across namespaces.
# From another pod in the same namespace
kubectl run curl --image=curlimages/curl --rm -it -- \
curl http://api-internal:8080/health
# From a different namespace using FQDN
curl http://api-internal.default.svc.cluster.local:8080/healthHeadless Service for StatefulSet
Sets clusterIP: None to create a headless Service that returns individual pod IPs via DNS, required by StatefulSets.
apiVersion: v1
kind: Service
metadata:
name: mysql-headless
spec:
clusterIP: None
selector:
app: mysql
ports:
- port: 3306
Discussion