Headless Service

A headless service is a service with ClusterIP set to None. This service does not have virtual IP address to access the associated pods, instead it provides DNS records for each associated pods with their names. A common use case of headless service is in StatefulSets where it allows to access pods created by their unique address.

The format of the address is shown below.

<pod-name>.<headless-svc-name>.<namespace>.svc.cluster.local

An example of resource yaml file headless service is shown below.

apiVersion: v1
kind: Service
metadata:
  name: nginx-headless-svc
spec:
  clusterIP: None # headless svc when clusterIP is None
  ports: 
    - port: 80
  selector:
    type: nginx-router

References

  1. https://kubernetes.io/docs/concepts/services-networking/service/#headless-services