<ul>
<li>I have 2 pods running on 2 nodes, each pod runs in different node.</li>
<li>These nodes are on the same subnet and can TCP/UDP/ICMP themselves.</li>
</ul>

<p>These pods got some hostnames, ie:</p>

<ul>
<li>drill-staging-75cddd789-kbzsq</li>
<li>drill-staging-75cddd789-amsrj</li>
</ul>

<p><strong>From pod drill-staging-75cddd789-kbzsq I cannot resolve host name for drill-staging-75cddd789-amsrj and vice versa.</strong> Resolving self pod's name works.</p>

<p>I tried setting various dnsPolicies:</p>

<ul>
<li>ClusterFirst: no luck</li>
<li>Default: no luck</li>
<li>ClusterFirstWithHostNet: no luck and it event couldn't resolve hostname of it's own node</li>
<li>None: not tried (I don't think it's a good way)</li>
</ul>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "app.name" . }}
  namespace: {{ .Values.global.namespace }}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: {{ include "app.name" . }}
  template:
    metadata:
      labels:
        app: {{ include "app.name" . }}
    spec:
      containers:
      - name: {{ include "app.name" . }}
        image: ...
        resources:
          ...
        ports:
          ...
        imagePullPolicy: Always
      restartPolicy: Always
</code></pre>

rudolfdobias
<p>Normally, <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#what-things-get-dns-names" rel="noreferrer">only Services get DNS names</a>, not Pods. So, by default, you can't refer to another Pod directly by a domain name, only by its IP address.</p>

<p>Pods get DNS names only under certain condidtions that include a headless Service, as <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-hostname-and-subdomain-fields" rel="noreferrer">explained in the documentation</a>. In particular, the conditions are:</p>

<ul>
<li>The Pods have a <code>hostname</code> field</li>
<li>The Pods have a <code>subdomain</code> field</li>
<li>There is a headless Service (in the same namespace) that selects the Pods</li>
<li>The name of the headless Service equals the <code>subdomain</code> field of the Pods</li>
</ul>

<p>In this case, each Pod gets a fully-qualified domain name of the following form:</p>

<pre><code>my-hostname.my-subdomain.default.svc.cluster.local
</code></pre>

<p>Where <code>my-hostname</code> is the <code>hostname</code> field of the Pod and <code>my-subdomain</code> is the <code>subdomain</code> field of the Pod.</p>

<blockquote>
  <p>Note: the DNS name is created for the "hostname" of the Pod and not the "name" of the Pod.</p>
</blockquote>

<p>You can test this with the following setup:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-subdomain
spec:
  selector:
    name: my-test
  clusterIP: None
---
apiVersion: v1
kind: Pod
metadata:
  name: my-pod-1
  labels:
    name: my-test
spec:
  hostname: my-hostname-1
  subdomain: my-subdomain
  containers:
  - image: weibeld/ubuntu-networking
    command: [sleep, "3600"]
    name: ubuntu-networking
---
apiVersion: v1
kind: Pod
metadata:
  name: my-pod-2
  labels:
    name: my-test
spec:
  hostname: my-hostname-2
  subdomain: my-subdomain
  containers:
  - image: weibeld/ubuntu-networking
    command: [sleep, "3600"]
    name: ubuntu-networking
</code></pre>

<p>After applying this, you can exec into one of the Pods:</p>

<pre><code>kubectl exec -ti my-pod-1 bash
</code></pre>

<p>And you should be able to resolve the fully-qualifed domain names of the two Pods:</p>

<pre><code>host my-hostname-1.my-subdomain.default.svc.cluster.local
host my-hostname-2.my-subdomain.default.svc.cluster.local
</code></pre>

<p>Since you're making the requests from the same namespace as the target Pods, you can abbreviate the domain name to:</p>

<pre><code>host my-hostname-1.my-subdomain
host my-hostname-2.my-subdomain
</code></pre>
