What is a Headless Service in Kubernetes?
In Kubernetes, a Service is typically used to provide a stable IP address and DNS name for a set of Pods. By default, Kubernetes assigns a ClusterIP
to the Service, and traffic is load balanced between available Pods.
But sometimes you don’t want load balancing — you want direct DNS records for each Pod. That’s where a Headless Service comes in.
How It Works
A Headless Service is created by setting:
clusterIP: None
This tells Kubernetes not to assign a virtual IP. Instead, DNS returns A records for each Pod behind the Service.
Example: Headless Service
apiVersion: v1
kind: Service
metadata:
name: my-db
labels:
app: my-db
spec:
clusterIP: None
selector:
app: my-db
ports:
- port: 5432
name: db
With this setup:
Instead of one IP, DNS will return multiple entries:
my-db.default.svc.cluster.local -> Pod1_IP, Pod2_IP, Pod3_IP
nslookup ignite-headless
Server: 10.233.0.3
Address: 10.233.0.3:53
Name: ignite-headless
Address: 10.234.199.202
Name: ignite-headless
Address: 10.234.103.153
Name: ignite-headless
Address: 10.234.81.223
Common Use Cases
- Databases (Postgres, Cassandra, etc.): each Pod may store different data and should be accessed individually.
- StatefulSets: Pods have stable DNS names like pod-0.my-db.default.svc.cluster.local.
- Service Discovery: some applications prefer to handle load balancing themselves.
Conclusion
Headless Services give you more control over how applications discover and connect to Pods, making them a key tool in advanced Kubernetes deployments.