<p>There is Pod with Centos. I want to get Pod IP by DNS. But there was an error.</p>

<pre><code>[root@namenode /]# nslookup namenode.space.default.svc.cluster.local
Server:         10.96.0.10
Address:        10.96.0.10#53
** server can't find namenode.space.default.svc.cluster.local: NXDOMAIN

[root@namenode /]# nslookup namenode
Server:         10.96.0.10
Address:        10.96.0.10#53

Name:   namenode.default.svc.cluster.local
Address: 10.107.117.123
</code></pre>

<p>This is my yaml file</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: test-con
 labels:
  app: test
spec:
 hostname: namenode
 subdomain: space
 containers:
 - name: test-con
   image: 192.168.50.130:5000/test
   command: [ "/usr/sbin/sshd", "-D"]
</code></pre>

<p>service.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: namenode
spec:
  selector:
    name: test
  ports:
   -  name: "ssh"
      port: 22
      targetPort: 22
  type: NodePort
</code></pre>

<p>namespace is default. How can i solve this problem?</p>

K.k
<p>First take a look into <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-hostname-and-subdomain-fields" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-hostname-and-subdomain-fields</a>.</p>

<p>According to this tutorial you have to change some parts:</p>

<ul>
<li>update <code>spec.selector</code> to <code>app: test</code> in your service.</li>
<li>service name has to be equal with the <code>spec.subdomain</code>.</li>
<li>service has to be <code>headless</code> (<code>spec.clusterIP</code> set to <code>None</code>)</li>
</ul>

<p>After everything is ready, try <code>$ namenode.space.default.svc.cluster.local</code>.</p>
