<p>I am learning Kubernetes and have deployed a headless service on Kubernetes(on AWS) which is exposed to the external world via nginx ingress.</p>

<p>I want <code>nslookup &lt;ingress_url&gt;</code> to directly return IP address of PODs.
How to achieve that?</p>

<h3>Inside the cluster:</h3>

<p>It's not a good idea to let a <code>&lt;ingress_host&gt;</code> resolved to Pod IP. It's a common design to let different kinds of pod served on one single <code>hostname</code> under different paths, but you can only set one (or one group of, with DNS load balance) IP record for it.</p>

<p>However, you can do this by adding <code>&lt;ingress_host&gt; &lt;Pod_IP&gt;</code> into <code>/etc/hosts</code> in init script, since you can get <code>&lt;Pod_IP&gt;</code> by doing <code>nslookup &lt;headless_service&gt;</code>.</p>

<p><a href="https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/" rel="nofollow noreferrer">HostAlias</a> is another option if you konw the pod ip before applying the deployment.</p>

<h3>From outside:</h3>

<p>I don't think it's possible outside the cluster. Because you need to do the DNS lookup to get to the ingress controller first, which means it has to be resolved to the IP of ingress controller.</p>

<p>At last, it's a bad idea to use a headless service on Pod because many apps do DNS lookups once and cache the results, which might bring a problem because the IP of Pod can be "changed" frequently.</p>
