<p>I'm trying to get the address from the below result of my <code>nslookup</code></p>
<p>Here I want to get is the 2nd address which is <code>10.0.45.45</code></p>
<pre class="lang-sh prettyprint-override"><code>Server:         10.152.183.10
Address:        10.152.183.10#53

Name:   pg-master-0.pg-master-headless.postgres.svc.cluster.local
Address: 10.1.45.45
</code></pre>
<p>Here is my code</p>
<pre class="lang-sh prettyprint-override"><code>MASTER_HOST=$(nslookup pg-master-0.pg-master-headlesss | awk '/^Address:/ {A=$2}; END {print A}');

echo $MASTER_HOST
</code></pre>
<p>Unfortunately, my output is:</p>
<pre class="lang-sh prettyprint-override"><code>10.152.183.10#53
</code></pre>
<p>Here I'm logged into the pod
<a href="https://i.stack.imgur.com/CSGsk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CSGsk.png" alt="enter image description here" /></a>
then ran the nslookup that way.</p>

Jayson Gonzaga
<p>It looks like <code>nslookup</code> cannot resolve <code>pg-master-0.pg-master-headlesss</code>. You might be running the operation from a different pod or from your personal server/machine which would have no idea of the services running in a cluster. (Your laptop doesn't use CoreDNS in your K8s cluster)</p>
<p>You can try running the script from the pod in your cluster and with the full FQDN to be safe:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl run -i --tty --rm debug --image=ubuntu --restart=Never -- bash
#
# apt update; apt -y install dnsutils # Installs dnslookup ...
# export MASTER_HOST=$(nslookup pg-master-0.pg-master-headless.postgres.svc.cluster.local | awk '/^Address:/ {A=$2}; END {print A}'); echo $MASTER_HOST&quot;
</code></pre>
