🔗
Kubernetes

ClusterIP Service

Internal-only Service — pods talk to each other inside the cluster without exposing ports publicly

📋Configuration Files

deployment.yml

yaml
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4 name: api-deploy
5 labels:
6 app: api-deploy
7spec:
8 replicas: 2
9 selector:
10 matchLabels:
11 app: api-deploy
12 template:
13 metadata:
14 labels:
15 app: api-deploy
16 spec:
17 containers:
18 - name: api
19 image: nginx:alpine
20 ports:
21 - containerPort: 80

service-clusterip.yml

ClusterIP — reachable only inside the cluster (default Service type)

yaml
1apiVersion: v1
2kind: Service
3metadata:
4 name: api-clusterip
5 labels:
6 app: api-deploy
7spec:
8 type: ClusterIP
9 selector:
10 app: api-deploy
11 ports:
12 - port: 80
13 targetPort: 80
14 protocol: TCP
📄

Step 01

Apply ClusterIP Service

(01)Deploy and verify internal DNS

Linux
1kubectl apply -f deployment.yml
2kubectl apply -f service-clusterip.yml
3kubectl get svc api-clusterip
4# Test from another pod:
5kubectl run curl --rm -it --image=curlimages/curl -- curl -s http://api-clusterip