Difficulty: Intermediate
What are the different types of Services in Kubernetes?
Services provide a stable IP/DNS name to reach a group of Pods.
1. **ClusterIP (Default)**: Exposes the service on an internal IP in the cluster. It's only reachable from within the cluster. 2. **NodePort**: Exposes the service on each Node's IP at a static port (30000-32767). Reachable from outside the cluster at `<NodeIP>:<NodePort>`. 3. **LoadBalancer**: Exposes the service externally using a cloud provider's load balancer (AWS ELB, GCP LB). It automatically creates a NodePort and ClusterIP. 4. **ExternalName**: Maps a service to a DNS name (e.g., `my-db.example.com`). It doesn't use selectors.
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
type: LoadBalancer
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 3000
External traffic hits port 80 and is routed to pod port 3000.
ClusterIP, NodePort, LoadBalancer, ExternalName