In the default behaviour of Kubernetes we assign as Internal IP address to the service.And with this IP address the service will proxy and load-balance the requests to the pods.We can choose which kind of service type we need while deploying it. These service types are-

  • ClusterIP- For exposing the server on cluster-internal IP address
  • NodePort- For exposing the service through a static port on the node
  • LoadBalancer- to expose the service using an external load-balancer

What is a Headless Service?

When there is no need of load balancing or single-service IP addresses.We create a headless service which is used for creating a service grouping. That does not allocate an IP address or forward traffic.So you can do this by explicitly setting ClusterIP to “None” in the mainfest file, which means no cluster IP is allocated.

For example, if you host MongoDB on a single pod. And you need a service definition on top of it for taking care of the pod restart.And also for acquiring a new IP address. But you don’t want any load balancing or routing. You just need the service to patch the request to the back-end pod. So then you use Headless Service since it does not have an IP.

#headless #kubernetes #service

What is Headless Service? Setup a Service in Kubernetes
1.30 GEEK