<p>When I create a deployment in Kubernetes (specifically Amazon EKS), it spins up <em>N</em> pods:</p>

<pre><code>worker-node-dddf68987-67fsq      192.168.149.142
worker-node-dddf68987-f77ks      192.168.155.15
worker-node-dddf68987-zndn4      192.168.232.226
</code></pre>

<p>And those pods can be resolved in DNS as (e.g.) <code>192-168-232-226.my-namespace.pod.cluster.local</code>.</p>

<p>But they're not resolvable as (e.g.) <code>worker-node-dddf68987-zndn4.my-namespace.pod.cluster.local</code>. <strong>Why not?</strong></p>

<p>Every answer I've seen says something like "well actually, you really want to look up the <em>service</em>". I <em>don't</em>.</p>

<p>My motivation is this: when connecting Erlang nodes into a cluster, the node name must match <em>exactly</em> on both ends, and I'd prefer my node name to be <code>worker-node@worker-node-dddf68987-zndn4</code>, rather than <code>worker-node@192.168.232.226</code>.</p>

<p>I can set the "server" node name by using <code>hostname -f</code>, but if that name's not discoverable in DNS, the "client" node can't connect to it.</p>

<p>I'm aware that by using a StatefulSet, I can permanently associate a name with a pod. That's not what I want. My nodes don't have any state. I don't mind that the name changes -- I'm using libcluster, which will automatically deal with Erlang cluster membership. I just want the names to be readable.</p>

<hr>

<p>Aside: the dashed IP lookup is basically a hack:</p>

<pre><code># ping 1-1-1-1.default.pod.cluster.local
PING 1-1-1-1.default.pod.cluster.local (1.1.1.1) 56(84) bytes of data.
64 bytes from one.one.one.one (1.1.1.1): icmp_seq=1 ttl=52 time=1.97 ms
</code></pre>

Roger Lipscombe
<p>Because <code>kubernetes service</code> creates an abstraction layer in front of pods in deployments and works as a load balancer for them. Pod names are volatile and will change once you recreate the deployment or modify it.</p>

<p>What you're trying to achieve can be done by creating a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">headless service</a> to <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-hostname-and-subdomain-fields" rel="nofollow noreferrer">disable load balancing</a>:</p>

<blockquote>
  <p>If there exists a headless service in the same namespace as the pod
  and with the same name as the subdomain, the cluster’s DNS Server also
  returns an A or AAAA record for the Pod’s fully qualified hostname.</p>
</blockquote>

<p>Or just use <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">StatefulSet</a> for which a headless service is required </p>

<blockquote>
  <p>Each Pod in a StatefulSet derives its hostname from the name of the StatefulSet and the ordinal of the Pod. </p>
</blockquote>
