<p>When creating a headless service in Kubernetes, it auto-generates the CNAME for each pod. I need to access this hostname somehow on pod boot. I can't seem to find it in the downward API or set in any kind of environment variable. Where can I get this value from within the pod itself, or is it even possible?</p>

<p>Right now running <code>dig</code> on the service returns the following:</p>

<pre><code>_etcd-server._tcp.etcd.databases.svc.cluster.local. 30  IN  SRV 10 100 2380 3730623862383630.etcd.databases.svc.cluster.local.
</code></pre>

<p>At the very least I need the <code>3730623862383630</code> portion of the URL.</p>

<p>It sounds like you want to treat your pods as pets, not cattle. Maybe you can try to use <a href="http://kubernetes.io/docs/user-guide/petset/" rel="nofollow"><code>PetSet</code></a>s and headless <code>Service</code>? Then you will have the <a href="http://kubernetes.io/docs/user-guide/petset/#network-identity" rel="nofollow">DNS entry</a> like <code>etcd-0.databases.svc.cluster.local</code> which <a href="http://kubernetes.io/docs/user-guide/petset/#peer-discovery" rel="nofollow">can be used during startup</a>.</p>
