<p>I followed the guide in the following link: 
<a href="http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html" rel="noreferrer">http://blog.kubernetes.io/2017/01/running-mongodb-on-kubernetes-with-statefulsets.html</a></p>

<p>and set up a mongo DB replica set on Kubernetes with StatefulSets. So far so good, but how do I expose that static hostnames outside the cluster so that I can access them from a Google instance for example? </p>

<p>If I use the IPs of the nodes it will work fine but those can change anytime (upon pod failure and restart with a different IP etc.)... </p>

<p>Thanks in advance!</p>

<p>It looks like the answer is present in the StatefulSet Basics documentation section <a href="https://kubernetes.io/docs/concepts/abstractions/controllers/statefulsets/%20https://kubernetes.io/docs/user-guide/services/#headless-services" rel="nofollow noreferrer">Using Stable Network Identities</a>:</p>

<blockquote>
  <p>The Pods’ ordinals, hostnames, SRV records, and A record names have
  not changed, but the IP addresses associated with the Pods may have
  changed. In the cluster used for this tutorial, they have. This is why
  it is important not to configure other applications to connect to Pods
  in a StatefulSet by IP address.</p>
  
  <p>If you need to find and connect to the active members of a
  StatefulSet, you should query the CNAME of the Headless Service
  <strong><code>(nginx.default.svc.cluster.local)</code></strong>. The SRV records associated with the
  CNAME will contain only the Pods in the StatefulSet that are Running
  and Ready.</p>
  
  <p>If your application already implements connection logic that tests for
  liveness and readiness, you can use the SRV records of the Pods <strong><code>( web-&gt; 0.nginx.default.svc.cluster.local, web-1.nginx.default.svc.cluster.local)</code></strong>, 
  as they are stable, and your
  application will be able to discover the Pods’ addresses when they
  transition to Running and Ready.</p>
</blockquote>
