<p>I need to create a deployment descriptor &quot;A&quot; yaml in which I can find the endpoint IP address of a pod (that belongs to a deployment &quot;B&quot;) . There is an option to use Downward API but I don't know if I can use it in that case.</p>

<p>If I understand correctly, you want to map the <code>test.api.com</code> hostname to the IP address of a specific Pod.<br />
As <strong>@whites11</strong> rightly pointed out, you can use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#with-selectors" rel="nofollow noreferrer">Headless Services with selectors</a>:</p>
<blockquote>
<p>For headless Services that define selectors, the endpoints controller creates Endpoints records in the API, and modifies the DNS configuration to return A records (IP addresses) that point directly to the Pods backing the Service.</p>
</blockquote>
<p>In this case, it may be difficult to properly configure the <code>/etc/hosts</code> file inside a Pod, but it is possible to configure the Kubernetes cluster DNS to achieve this goal.</p>
<p>If you are using <code>CoreDNS</code> as a DNS server, you can configure <code>CoreDNS</code> to map one domain (<code>test.api.com</code>) to another domain (headless service DNS name) by adding a <code>rewrite</code> rule.</p>
<p>I will provide an example to illustrate how it works.</p>
<hr />
<p>First, I prepared a sample <code>web</code> Pod with an associated <code>web</code> Headless Service:</p>
<pre><code># kubectl get pod,svc -o wide
NAME           READY   STATUS    RESTARTS   AGE   IP          NODE      NOMINATED NODE   READINESS GATES
pod/web        1/1     Running   0          66m   10.32.0.2   kworker   &lt;none&gt;           &lt;none&gt;

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE   SELECTOR
service/web          ClusterIP   None         &lt;none&gt;        80/TCP    65m   run=web
</code></pre>
<p>We can check if the <code>web</code> headless Service returns A record (IP address) that points directly to the <code>web</code> Pod:</p>
<pre><code># kubectl exec -i -t dnsutils -- nslookup web.default.svc
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   web.default.svc.cluster.local
Address: 10.32.0.2
</code></pre>
<p>Next, we need to configure <code>CoreDNS</code> to map <code>test.api.com</code> -&gt; <code>web.default.svc.cluster.local</code>.</p>
<p>Configuration of <code>CoreDNS</code> is stored in the <code>coredns</code> <code>ConfigMap</code> in the <code>kube-system</code> namespace. You can edit it using:</p>
<pre><code># kubectl edit cm coredns -n kube-system
</code></pre>
<p>Just add one <code>rewrite</code> rule, like in the example below:</p>
<pre><code>apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health {
           lameduck 5s
        }
        rewrite name test.api.com web.default.svc.cluster.local # mapping test.api.com to web.default.svc.cluster.local
...
</code></pre>
<p>To reload CoreDNS, we may delete <code>coredns</code> Pods (<code>coredns</code> is deployed as Deployment, so new Pods will be created)</p>
<p>Finally, we can check how it works:</p>
<pre><code># kubectl exec -i -t dnsutils -- nslookup test.api.com
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   test.api.com
Address: 10.32.0.2
</code></pre>
<p>As you can see, the <code>test.api.com</code> domain also returns the IP address of the <code>web</code> Pod.</p>
<p>For more information on the <code>rewrite</code> plugin, see the  <a href="https://coredns.io/plugins/rewrite/" rel="nofollow noreferrer">Coredns rewrite documentation</a>.</p>
