<p>We wanted podnames to be resolved to IP's to configure the seed nodes in an akka cluster. This was happenning by using the concept of a headless service and stateful sets in Kubernetes. But, how do I expose a  headless service externally to hit an endpoint from outside?</p>

<p>It is hard to expose a Kubernetes service to the outside, since this would require some complex TCP proxies. The reason for this is, that the headless services is only a DNS record with an IP for each pod. But these IPs are only reachable from within the cluster.</p>

<p>One solution is to expose this via Node ports, which means the ports are opened on the host itself. Unfortunately this makes the service discovery harder, because you don't know which host has a scheduled pod on it.</p>

<p>You can setup node ports via:</p>

<ul>
<li>the services: <a href="https://kubernetes.io/docs/user-guide/services/#type-nodeport" rel="nofollow noreferrer">https://kubernetes.io/docs/user-guide/services/#type-nodeport</a></li>
<li>or directly in the Pod by defining <a href="https://kubernetes.io/docs/user-guide/services/#type-nodeport" rel="nofollow noreferrer"><code>spec.containers[].ports[].hostPort</code></a></li>
</ul>

<p>Another alternative is to use a <a href="https://kubernetes.io/docs/user-guide/services/#type-loadbalancer" rel="nofollow noreferrer">LoadBalancer</a>, if your cloud provider supports that. Unfortunately you cannot address each instance itself, since they share the same IP. This might not be suitable for your application.</p>
