Room 16
CLUSTERIP SERVICES
The Internal Network
- Services provide stable network endpoints for ephemeral pods.
- A ClusterIP service is the default - only reachable within the cluster. Wire up the connections.
📜 Mission Briefing
- Apply
backend-deploy.yaml- a deployment with 3 nginx pods. - Create a ClusterIP service to expose the deployment:
service.yaml. - Verify the service has endpoints:
kubectl get endpoints. - Create a temporary pod to test connectivity:
- The nginx pods serve a page that contains the password.
- The password is
clusterip.
Key Commands
| Command | Purpose |
|---|---|
kubectl get svc |
List services |
kubectl describe svc NAME |
Service details |
kubectl get endpoints NAME |
Service endpoints |
kubectl expose deployment NAME --port=PORT |
Create service |
kubectl port-forward svc/NAME LOCAL:REMOTE |
Local access |
How Services Work
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ClusterIP # Default type
selector:
app: my-app # Matches pod labels
ports:
- port: 80 # Service port
targetPort: 8080 # Container port
protocol: TCP
# Service types:
# ClusterIP (default): Internal-only virtual IP
# NodePort: Exposes on each node's IP at a static port
# LoadBalancer: Provisions external load balancer
# ExternalName: Maps to DNS name (CNAME)
# Create service imperatively
kubectl expose deployment my-app --port=80 --target-port=8080
# Service DNS: <service>.<namespace>.svc.cluster.local
# Short forms: <service> (same namespace), <service>.<namespace>
# Test connectivity from within the cluster
kubectl run test --image=busybox --rm -it --restart=Never -- \
wget -qO- http://my-service.default.svc.cluster.local
# Check endpoints (pod IPs backing the service)
kubectl get endpoints my-service
# Port-forward for local testing
kubectl port-forward svc/my-service 8080:80
Hints
Hint 1
Apply the deployment and service:
Hint 2
Test the service:
Hint 3
The password is clusterip.