title: Obtain Pod DNS Name Programmatically
body: <p>I have a statefulset with 3 members. They are accessible from inside the cluster with something like:</p>
  
  <pre><code>podname-{0..n}.service.default.svc.cluster.local
  </code></pre>
  
  <p>I'm using the Kubernetes API from a Controller. I just created the Statefulset with:</p>
  
  <pre class="lang-go prettyprint-override"><code>import (
      "k8s.io/client-go/kubernetes"
      appsv1 "k8s.io/api/apps/v1"
  )
  ...
  
  s := appsv1.StatefulSet{ /* some data */ }
  kubernetes.AppsV1().StatefulSets(nameSpace).Create(s)
  </code></pre>
  
  <p>Let's assume everything worked correctly, and after a few minutes I have 3 running Pods. How can I get the Pod DNS entries for the newly created Pods?</p>
  
  <p>I know I can build the DNS with:</p>
  
  <pre><code>fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local", s.Name, idx, service, S.Namespace)
  </code></pre>
  
  <p>But I'm finding some issues:</p>
  
  <ol>
  <li>I will have to calculate the index depending on the amount of replicas</li>
  <li>I need to know about the service name used for this <code>StatefulSet</code></li>
  <li>I'm assuming the cluster domain is <code>cluster.local</code> which is not necessarily true</li>
  </ol>
  
  <p>What I think it should exists (but I'm not sure if it really exists), is an API, that given a StatefulSet will allow me to know the DNS names of the Replicas that were created. Does an API like this exists?</p>