Roadmap › Kubernetes (K8s) & AKS › Module: Architecture and Core Objects
Lessons in this course (15)
3. Services and service types
Basic★ Must knowLesson 3 of 15
Pods come and go with changing IPs; a Service gives a stable virtual IP and DNS name (shop-api.default.svc.cluster.local, or just shop-api in the same namespace) and load-balances to ready pods matching its selector.
| Type | Exposes | Use |
|---|---|---|
| ClusterIP (default) | Internal virtual IP only | Service-to-service |
| NodePort | A port (30000–32767) on every node | Testing, legacy |
| LoadBalancer | Cloud load balancer with external IP | Expose a service directly (one LB per service) |
| ExternalName | DNS CNAME to an external host | Alias external services |
Headless (clusterIP: None) | DNS returns pod IPs | StatefulSets, client-side discovery |
yaml
apiVersion: v1
kind: Service
metadata: { name: shop-api }
spec:
type: ClusterIP
selector: { app: shop-api }
ports:
- port: 80 # service port
targetPort: 8080 # container port