πŸ“šBook Signing at KubeCon EU 2026Meet us at Booking.com HQ (Mon 18:30-21:00) & vCluster booth #521 (Tue 24 Mar, 12:30-1:30pm) β€” free book giveaway!RSVP Booking.com Event
Networking intermediate ⏱ 15 minutes K8s 1.28+

Kubernetes Headless Service Explained

Create Kubernetes headless services for StatefulSet DNS, direct pod addressing, and service discovery. Understand when clusterIP None is the right choice.

By Luca Berton β€’ β€’ πŸ“– 5 min read

πŸ’‘ Quick Answer: networking

The Problem

This is a fundamental Kubernetes topic that engineers search for frequently. A comprehensive reference with production-ready examples saves hours of trial and error.

The Solution

Create a Headless Service

apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  clusterIP: None       # ← This makes it headless
  selector:
    app: postgres
  ports:
    - port: 5432

DNS Behavior Difference

# Regular Service DNS β†’ returns ClusterIP (virtual IP, load-balanced)
dig my-service.default.svc.cluster.local
# ANSWER: 10.96.5.10

# Headless Service DNS β†’ returns ALL pod IPs (no load balancing)
dig postgres.default.svc.cluster.local
# ANSWER: 10.244.1.5, 10.244.2.8, 10.244.3.12

# With StatefulSet β†’ individual pod DNS records
dig postgres-0.postgres.default.svc.cluster.local
# ANSWER: 10.244.1.5
dig postgres-1.postgres.default.svc.cluster.local
# ANSWER: 10.244.2.8

When to Use Headless Services

Use CaseWhy Headless
StatefulSet (databases)Clients need to connect to specific pods
Client-side load balancingApp does its own routing (gRPC)
Peer discoveryPods need to find each other (clustering)
DNS-based service discoveryExternal tools need pod IPs

Headless + StatefulSet (Required)

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres   # Must match headless Service name
  replicas: 3
graph TD
    A[Regular Service] -->|DNS returns| B[ClusterIP 10.96.5.10]
    B -->|kube-proxy routes to| C[Random pod]
    D[Headless Service] -->|DNS returns| E[Pod IPs directly]
    E --> F[postgres-0: 10.244.1.5]
    E --> G[postgres-1: 10.244.2.8]
    E --> H[postgres-2: 10.244.3.12]

Frequently Asked Questions

Can I have both headless and regular services for the same pods?

Yes! Common pattern: headless service for StatefulSet pod addressing + regular ClusterIP service for load-balanced client access.

Best Practices

  • Start with the simplest configuration that meets your needs
  • Test changes in staging before production
  • Use kubectl describe and events for troubleshooting
  • Document your decisions for the team

Key Takeaways

  • This is essential Kubernetes knowledge for production operations
  • Follow the principle of least privilege and minimal configuration
  • Monitor and iterate based on real-world behavior
  • Automation reduces human error and improves consistency
#headless-service #statefulset #dns #service-discovery #kubernetes
Luca Berton
Written by Luca Berton

Principal Solutions Architect specializing in Kubernetes, AI/GPU infrastructure, and cloud-native platforms. Author of Kubernetes Recipes and creator of CopyPasteLearn courses.

Kubernetes Recipes book cover

Want More Kubernetes Recipes?

This recipe is from Kubernetes Recipes, our 750-page practical guide with hundreds of production-ready patterns.

Luca Berton Ansible Pilot Ansible by Example Open Empower K8s Recipes Terraform Pilot CopyPasteLearn ProteinLens