What is a headless Service and when would you use one?
Quick Answer
A headless Service (clusterIP: None) has no virtual IP or proxying; instead DNS returns the individual pod IPs. You use it when clients need to reach specific pods directly — StatefulSets, databases, and peer-to-peer systems.
Detailed Answer
A normal Service gives you one stable VIP and load-balances across pods, hiding individual backends. A headless Service sets clusterIP: None, so kube-proxy does nothing and DNS for the Service name returns the A/AAAA records of all matching pod IPs directly. This matters when the client needs per-pod addressing rather than a random backend: StatefulSets pair with a headless Service to give each pod a stable DNS name (web-0.mysvc, web-1.mysvc) so a database replica set or a Kafka/Cassandra cluster can address specific members. It's also used for client-side load balancing where the app wants the full endpoint list. The key idea: headless trades the convenience of a single VIP for direct, stable, per-pod discovery.
Code Example
apiVersion: v1
kind: Service
metadata: { name: cassandra }
spec:
clusterIP: None # headless
selector: { app: cassandra }
ports: [{ port: 9042 }]
# DNS: cassandra-0.cassandra, cassandra-1.cassandra ... stable per-pod namesInterview Tip
Tie it to StatefulSets: 'headless Service + StatefulSet gives each pod a stable DNS identity,' which is exactly what stateful/clustered systems need. That connection is the point of the question.