What is a Kubernetes headless service?

· Category: Kubernetes

Short answer

A headless service is a Kubernetes Service with clusterIP: None. Instead of providing a virtual IP, it returns the IPs of the backing Pods directly, enabling direct Pod-to-Pod communication.

How it works

When you query a headless service via DNS, you receive A records for each Pod. This is useful for stateful sets, peer discovery, and custom load balancing scenarios where the client needs to know individual Pod addresses.

Example

apiVersion: v1
kind: Service
metadata:
  name: db-headless
spec:
  clusterIP: None
  selector:
    app: db
  ports:
  - port: 5432

Why it matters

Headless services are essential for StatefulSets, where each Pod needs a stable network identity. They are also used in database clusters, distributed systems, and custom client-side load balancing.

Key differences

  • ClusterIP: Single virtual IP, load-balanced.
  • Headless: Returns individual Pod IPs, no load balancing.

Common issues

  • Clients must handle multiple IPs returned from DNS.
  • Pod readiness affects DNS records.
  • No built-in load balancing; clients connect directly to individual Pods.