<p>The question is for pods <strong>DNS resolution</strong> in kubernetes. A statement from official doc here (choose v1.18 from top right dropdown list):
<a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods</a></p>

<blockquote>
  <p>Pods.  </p>
  
  <p>A/AAAA records  </p>
  
  <p>Any pods created by a Deployment or DaemonSet have the following DNS resolution available:   </p>
  
  <p><code>pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example.</code></p>
</blockquote>

<p>Here is my kubernetes environments:</p>

<pre><code>master $ kubectl version  
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:58:59Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}  
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:50:46Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
</code></pre>

<p>After I create a simple deployment using <code>kubectl create deploy nginx --image=nginx</code>, then I create a busybox pod in <code>test</code> namespace to do nslookup like this:</p>

<pre><code>kubectl create ns test

cat &lt;&lt;EOF | kubectl apply -n test -f -
apiVersion: v1
kind: Pod
metadata:
  name: busybox1
  labels:
    name: busybox
spec:
  containers:
  - image: busybox:1.28
    command:
      - sleep
      - "3600"
    name: busybox
EOF
</code></pre>

<p>Then I do <code>nslookup</code> like this, according to the offical doc <code>pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example</code>:</p>

<pre><code>master $ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
nginx-f89759699-h8cj9   1/1     Running   0          12m   10.244.1.4   node01   &lt;none&gt;           &lt;none&gt;

master $ kubectl get deploy -o wide
NAME    READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES   SELECTOR
nginx   1/1     1            1           17m   nginx        nginx    app=nginx

master $ kubectl exec -it busybox1 -n test -- nslookup 10.244.1.4.nginx.default.svc.cluster.local
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

nslookup: can't resolve '10.244.1.4.nginx.default.svc.cluster.local'
command terminated with exit code 1

master $ kubectl exec -it busybox1 -n test -- nslookup 10-244-1-4.nginx.default.svc.cluster.local
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

nslookup: can't resolve '10-244-1-4.nginx.default.svc.cluster.local'
command terminated with exit code 1

</code></pre>

<p><strong>Question 1:</strong><br>
Why nslookup for the name failed? Is there something I did wrong?</p>

<hr>

<p>When I continue to explore the dns name for pods, I did this:</p>

<pre><code>master $ kubectl exec -it busybox1 -n test -- nslookup 10-244-1-4.default.pod.cluster.local
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      10-244-1-4.default.pod.cluster.local
Address 1: 10.244.1.4
master $ kubectl exec -it busybox1 -n test -- nslookup 10-244-1-4.test.pod.cluster.local
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      10-244-1-4.test.pod.cluster.local
Address 1: 10.244.1.4
</code></pre>

<p><strong>Questions 2:</strong><br>
Why <code>nslookup 10-244-1-4.test.pod.cluster.local</code> succeeded even the pod of 10.244.1.4 is in default namespace?</p>

Andrew Feng
<p>Regarding your first question, as far as I could check your assumptions are right, it seems like the documentation isn't accurate. The A/AAAA reference for pods is something new in the documentation (1.18). For that I highly encourage you to open an issue <a href="https://www.google.com/url?q=https://github.com/kubernetes/kubernetes/issues?q=is%253Aopen%2bis%253Aissue%2blabel%253Akind%252Fdocumentation&amp;sa=D&amp;source=hangouts&amp;ust=1592383652055000&amp;usg=AFQjCNFAXM6HjtH0p-mBBB_Rn2PDljrYtw" rel="nofollow noreferrer">here</a> so the developers can take a closer look into it. </p>

<p>I recommend you to refer to <a href="https://v1-17.docs.kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods" rel="nofollow noreferrer">1.17 documentation</a> on that regard as it's to be reflecting the actual thing.</p>

<p>In 1.17 we can see this note:</p>

<blockquote>
  <p><strong>Note:</strong>  Because A or AAAA records are not created for Pod names,  <code>hostname</code>  is required for the Pod’s A or AAAA record to be created. A Pod with no  <code>hostname</code>  but with  <code>subdomain</code>  will only create the A or AAAA record for the headless service (<code>default-subdomain.my-namespace.svc.cluster-domain.example</code>), pointing to the Pod’s IP address. Also, Pod needs to become ready in order to have a record unless  <code>publishNotReadyAddresses=True</code>  is set on the Service.</p>
</blockquote>

<p>As far as I could check this is still true on 1.18 despite of what the documentation is saying. </p>

<p>Regarding question two is going to the same direction and you can also open an issue but I personally don't see any practical reason for the usage of IP Based DNS names. These names are there for kubernetes internal use and using it isn't giving you any advantage. </p>

<p>The best scenario is to use <a href="https://v1-17.docs.kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services" rel="nofollow noreferrer">service based dns names</a> on Kubernetes. It's proven to be very reliable. </p>
