How to fix headless service not found in Kubernetes
A StatefulSet or Pod is trying to connect to a headless Service that does not exist or is not properly configured. This breaks DNS-based service discovery.
Quick fix
Fixes headless service not found
kubectl get svc -n your-namespace- Verify the headless service exists
- Create the headless service
- Match service selector to Pod labels
- Test DNS resolution
kubectl get svc -n your-namespaceheadless service not found
What this error means
Headless Services (with clusterIP: None) provide DNS entries for individual Pod IPs instead of a single Service IP. This is critical for StatefulSets and applications needing direct Pod-to-Pod communication. When a headless service is missing or misconfigured, DNS resolution fails and Pods cannot discover each other.
Typical symptoms
- StatefulSet Pods cannot resolve service DNS
- nslookup or dig fails for service domain
- Pods get "Name or service not known" errors
- Database cluster (e.g., Cassandra, Mongo) cannot form cluster
- gRPC service discovery fails between Pods
- Pod logs show "failed to resolve" messages
Common causes
- Headless Service was not created for the StatefulSet
- Service selector labels do not match Pod labels
- Service and Pods are in different namespaces
- Service was deleted but Pods still reference it
- Typo in service name or namespace
- Ingress or networking plugin blocking DNS
How to fix "headless service not found"
Check if the service is created:
kubectl get svc -n your-namespaceLook for the service name (typically matches the StatefulSet name). If missing, create it.
Create a headless service YAML:
apiVersion: v1
kind: Service
metadata:
name: my-db
namespace: default
spec:
clusterIP: None # This makes it headless
selector:
app: my-db
ports:
- port: 5432
targetPort: 5432Apply it:
kubectl apply -f service.yamlEnsure your StatefulSet Pods have the matching labels:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: my-db
spec:
serviceName: my-db # Must match service name
selector:
matchLabels:
app: my-db # Must match service selector
template:
metadata:
labels:
app: my-dbFrom within a Pod, test if the service resolves:
kubectl exec -it my-db-0 -- nslookup my-db.default.svc.cluster.localYou should get multiple A records (one per Pod). For a service with 3 replicas, you should see 3 IPs.
Verify that running Pods have the correct labels:
kubectl get pods --show-labelsConfirm all Pods have the label referenced in the service selector. If not, recreate the StatefulSet.
Advanced notes
StatefulSets require the serviceName field to be set to the headless service. The service must exist before the StatefulSet is created. For multi-zone clusters, ensure DNS is properly configured across zones. Some service meshes (Istio, Linkerd) may interfere with headless service discovery—check mesh documentation if using one.
Frequently asked questions
- What does "headless service not found" mean?
- Headless Services (with clusterIP: None) provide DNS entries for individual Pod IPs instead of a single Service IP. This is critical for StatefulSets and applications needing direct Pod-to-Pod communication. When a headless service is missing or misconfigured, DNS resolution fails and Pods cannot discover each other.
- How do I fix "headless service not found"?
- A StatefulSet or Pod is trying to connect to a headless Service that does not exist or is not properly configured. This breaks DNS-based service discovery.
- What causes "headless service not found"?
- Headless Service was not created for the StatefulSet Service selector labels do not match Pod labels Service and Pods are in different namespaces
- Is the "headless service not found" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚Kubernetes Official Documentation
- 📖Kubernetes: Headless Services(Official Docs)
- 📖Kubernetes: StatefulSet(Official Docs)
- 💬SO: Headless service DNS resolution(Stack Overflow)