Services & Networking
Pods are ephemeral and get assigned new dynamic IP addresses whenever recreated. A Kubernetes Service provides a static IP address and DNS name entry to route traffic reliably to matching Pods.
1. Service Types Comparison
| Service Type | Scope & Accessibility | Best For |
|---|---|---|
ClusterIP (Default) | Internal cluster IP only | Inter-pod communication (Databases, Microservices, Caches) |
NodePort | Exposes static port (30000-32767) on all Worker Node IPs | Development / On-premise bare-metal testing |
LoadBalancer | Provisions cloud provider external Load Balancer (AWS ELB, GCP LB) | Production public-facing web applications & APIs |
ExternalName | Maps service to external CNAME record | Integrating external third-party services outside cluster |
2. Production LoadBalancer Service Manifest
apiVersion: v1
kind: Service
metadata:
name: frontend-service
spec:
type: LoadBalancer
selector:
app: api-server # Routes traffic to Pods labeled 'app: api-server'
ports:
- protocol: TCP
port: 80 # Public Service Port
targetPort: 3000 # Container Port inside PodNext Up
Learn Ingress & Ingress Controllers: Nginx Ingress, host/path-based routing, and Cert-Manager TLS/SSL.
Next Lesson: Ingress & TLS Termination →