When do you use a headless service?
IntermediateScenarioKubernetes Networking
Answer
Situation read → It returns pod IPs instead of a virtual IP.
What I'd do →
- Set
clusterIP: Nonein the Service - DNS returns A records for each ready pod, and for StatefulSets stable names like
db-0.db.prod.svc.cluster.local - Use it for databases, Kafka or any client-side discovery
- Check with
nslookup db.prod.svc.cluster.local - Clients must handle multiple records and reconnect on changes
Why → No virtual IP means no load balancing by kube-proxy; the client sees the real endpoints.
Interview tip → Say StatefulSets need it for stable network identity.
More on Kubernetes Networking
Explain the Kubernetes networking model in one minute.BeginnerClusterIP, NodePort and LoadBalancer: when do you use each?BeginnerHow does a pod find another service by name?BeginnerService versus Ingress: what is the difference?BeginnerWhat does a CNI plugin do and which ones do you know?BeginnerHow do you reach a pod from your laptop for debugging without exposing it?Beginner