Kubernetes interview question · Most asked
Explain the Service types: ClusterIP, NodePort, LoadBalancer, ExternalName and headless.
Summary
A Service gives a stable virtual IP and DNS name in front of a changing set of pods selected by labels. ClusterIP is reachable only inside the cluster; NodePort also opens a port on every node; LoadBalancer provisions a cloud load balancer; ExternalName is a DNS alias to an outside name; a headless Service (clusterIP: None) returns the pod IPs directly in DNS, used by StatefulSets.
Longer Answer
Endpoints are maintained as EndpointSlices containing only ready pods. kube-proxy (iptables, IPVS or nftables mode) or an eBPF data path (such as Cilium) translates the virtual IP to pod IPs on each node.
For HTTP from outside, you usually expose many Services through one Ingress or Gateway rather than one cloud load balancer per Service, which costs more. externalTrafficPolicy: Local preserves the client IP and avoids an extra hop, but only nodes with local pods receive traffic.
Key Points
- Stable VIP and DNS for a label selector.
- ClusterIP, NodePort, LoadBalancer, ExternalName.
- Headless returns pod IPs.
- EndpointSlices hold only ready pods.
More most-asked Kubernetes questions
- Describe the Kubernetes architecture: what runs on the control plane and what runs on the nodes?
- What is the difference between resource requests and limits, and what are the QoS classes?
- Deployment, StatefulSet, DaemonSet, Job and CronJob: when do you use each?
- How do rolling updates work in a Deployment, and how do you roll back?
- What happens, step by step, when you run kubectl apply for a Deployment?
- How does the scheduler place pods? Explain resource requests, node affinity, taints and tolerations.
- ConfigMaps and Secrets: how do they differ, and how should secrets really be handled?
- Liveness, readiness and startup probes: how do you configure them correctly?