Kubernetes Services and Networking
Explain the different types of Kubernetes Services (ClusterIP, NodePort, LoadBalancer) and when to use each.
ClusterIP (default) exposes the service on an internal IP, accessible only within the cluster - use for internal communication between pods. NodePort exposes the service on each node's IP at a static port (30000-32767) - use for development or when you manage your own load balancer. LoadBalancer provisions an external load balancer (in cloud environments) - use for production external traffic. Ingress is not a service type but a separate resource for HTTP/HTTPS routing with a single entry point.
Kubernetes networking is essential for connecting microservices and exposing applications. Understanding service types helps architects design secure, scalable systems and troubleshoot connectivity issues efficiently.
Kubernetes Service types
- Using LoadBalancer for every service (costly and unnecessary)
- Confusing targetPort with port
- Not understanding that NodePort opens ports on ALL nodes
- What is the difference between port, targetPort, and nodePort?
- How does kube-proxy handle service traffic?
- When would you use an Ingress instead of a LoadBalancer service?