ClusterIP Service
ClusterIP is the default Service type. It exposes the Service on an internal IP in the cluster. This makes the Service only reachable from within the cluster – perfect for backend services that should not be exposed to the outside world.What Is ClusterIP?
A ClusterIP Service gets a virtual IP address assigned. Only resources inside the cluster can reach it. This is ideal for internal communication, such as a database service or a backend API that only your frontend Pods need to call.
Example: Backend API Service
Assume you have a backend Deployment with label
app: backend. Create a ClusterIP Service:apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: ClusterIP
selector:
app: backend
ports:
- port: 8080
targetPort: 8080Apply it:kubectl apply -f backend-service.yamlAccessing the Service from a Pod
Kubernetes provides DNS for Services. A frontend Pod can reach the backend using the Service name:
http://backend-service:8080. No need to know the IP.You can test from within a temporary Pod:
kubectl run test --rm -it --image=curlimages/curl -- shInside the shell, run:curl backend-service:8080When to Use ClusterIP
- Internal APIs or microservices that should not be public.
- Database access from application Pods.
- Any service that only needs to be consumed within the cluster.
Two Minute Drill
- ClusterIP is the default Service type, internal only.
- It gives a stable virtual IP and DNS name inside the cluster.
- Other Pods can access it via
servicename.namespace.svc.cluster.localor justservicename. - Use for backend, database, or any internal communication.
Need more clarification?
Drop us an email at career@quipoinfotech.com
