A ClusterIP Service provides an internal, cluster-only endpoint for Pods or Deployments. It lets containers communicate without exposing the selected workloads to the internet, while Kubernetes routes and balances requests across matching Pods. section 8.6 section 8.5.1
Use ClusterIP when a workload needs to remain reachable inside the cluster:
- Connect application components to internal APIs or other Deployments. section 8.3.2
- Keep databases such as PostgreSQL inaccessible from the public internet. section 8.3.2 section 8.4.2
- Select Pods through matching labels so the Service can attach to and balance traffic across them. section 8.3.2 section 8.5.1
Internal PostgreSQL Service
A PostgreSQL StatefulSet can use a ClusterIP Service named postgres-svc. Its port and targetPort are both 5432, and selector app: postgres routes traffic to the matching database Pod. Local verification can use kubectl port-forward service/postgres 3312:5432, followed by a client connection to localhost:3312. section 8.4.2
Listing 8.21 ClusterIP Service for Postgres
apiVersion: v1
kind: Service
metadata:
name: postgres-svc
spec:
type: ClusterIP
ports:
- port: 5432
targetPort: 5432
selector:
app: postgres
Inspect the complete ClusterIP Service manifest for PostgreSQL, including its port mapping and Pod selector. section 8.4.2





