🌐 Internal vs External Access
Pods have IPs, but they change. Services provide stable access. Choose the right type: ClusterIP (internal), NodePort (external on node IP), LoadBalancer (cloud load balancer).
📝 Service Types
ClusterIP (default):
- Internal cluster access only
- Virtual IP accessible inside cluster
- Use for microservices communicating internally
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: ClusterIP
selector:
app: myapp
ports:
- port: 80
targetPort: 8080
🎯 NodePort and LoadBalancer
NodePort:
- Exposes service on each node's IP at a static port
- Access: <node-ip>:<node-port>
- Use for testing, development
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: NodePort
selector:
app: myapp
ports:
- port: 80
targetPort: 8080
nodePort: 30080 # Optional (range: 30000-32767)
LoadBalancer:
- Cloud provider load balancer (AWS ELB, Azure LB, GCP LB)
- Access: <external-ip>:<port>
- Use for production external access
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: LoadBalancer
selector:
app: myapp
ports:
- port: 80
targetPort: 8080
💡 When to Use Which
- ClusterIP: Internal microservices communication
- NodePort: Development, testing, on-premise
- LoadBalancer: Production, cloud environments
- Ingress: HTTP/HTTPS routing, SSL termination (recommended for web apps)
“Exposed service as NodePort, but couldn’t access from outside. Switched to LoadBalancer. Cloud provisioned ELB, external access worked. Use right type for your environment.”
