<p>I am using AKS cluster on Azure. I am trying to discover service using DNS (<a href="http://my-api.default.svc.cluster.local:3000/" rel="nofollow noreferrer">http://my-api.default.svc.cluster.local:3000/</a>) but, it's not working (This site can’t be reached). With service IP endpoint everything is working fine.</p>

<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-api
  labels:
    app: my-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-api
  template:
    metadata:
      labels:
    app: my-api
    spec:
      containers:
      - name: my-api
    image: test.azurecr.io/my-api:latest
    ports:
    - containerPort: 3000
      imagePullSecrets:
      - name: testsecret
---
apiVersion: v1
kind: Service
metadata:
  name: my-api
spec:
  selector:
    app: my-api
  ports:
  - protocol: TCP
    port: 3000
    targetPort: 3000
</code></pre>

<blockquote>
  <p>kubectl describe services kube-dns --namespace kube-system</p>
</blockquote>

<pre><code>Name:              kube-dns
Namespace:         kube-system
Labels:            addonmanager.kubernetes.io/mode=Reconcile
               k8s-app=kube-dns
               kubernetes.io/cluster-service=true
               kubernetes.io/name=KubeDNS
Annotations:       kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile","k8s-app":"kube-dns","kubernet...
Selector:          k8s-app=kube-dns
Type:              ClusterIP
IP:                10.10.110.110
Port:              dns  53/UDP
TargetPort:        53/UDP
Endpoints:         10.10.100.54:53,10.10.100.64:53
Port:              dns-tcp  53/TCP
TargetPort:        53/TCP
Endpoints:         10.10.100.54:53,10.10.100.64:53
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<blockquote>
  <p>kubectl describe svc my-api</p>
</blockquote>

<pre><code>Name:              my-api
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"my-api","namespace":"default"},"spec":{"ports":[{"port":3000,"protocol":...
Selector:          app=my-api
Type:              ClusterIP
IP:                10.10.110.104
Port:              &lt;unset&gt;  3000/TCP
TargetPort:        3000/TCP
Endpoints:         10.10.100.42:3000
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p><strong>From Second POD</strong></p>

<pre><code>kubectl exec -it second-pod /bin/bash
curl my-api.default.svc.cluster.local:3000
Response: {"value":"Hello world2"}
</code></pre>

<p><strong>From Second POD website is running which is using the same endpoint but it's not connecting to the service.</strong></p>

<p><a href="https://i.stack.imgur.com/VSCfp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VSCfp.png" alt="enter image description here"></a></p>

<p>Fixing the indentation of your yaml file, I was able to launch the deployment and service successfully. Also the DNS resolution worked fine.</p>

<p>Differences:</p>

<ul>
<li>Fixed indentation</li>
<li>Used <code>test1</code> namespaces instead of <code>default</code></li>
<li>Used containerPort <code>80</code> instead of <code>3000</code></li>
<li>Used my image</li>
</ul>

<p>Deployment:</p>

<pre><code>apiVersion: apps/v1beta2
kind: Deployment
metadata:
  labels:
    app: my-api
  name: my-api
  namespace: test1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-api
  template:
    metadata:
      labels:
        app: my-api
    spec:
      containers:
      - image: leodotcloud/swiss-army-knife
        name: my-api
        ports:
        - containerPort: 80
          protocol: TCP
</code></pre>

<p>Service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-api
  namespace: test1
spec:
  ports:
  - port: 3000
    protocol: TCP
    targetPort: 80
  selector:
    app: my-api
  type: ClusterIP
</code></pre>

<p><a href="https://i.stack.imgur.com/e4nN9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e4nN9.png" alt="second-pod-test"></a></p>

<p>Debugging steps:</p>

<ul>
<li>Install tcpdump inside both of the kube-dns containers and start capturing DNS traffic (with filters from the second pod IP)</li>
<li>From inside the second pod, run <code>curl</code> or <code>dig</code> command using the FQDN.</li>
<li>Check if the DNS query packets are reaching the kube-dns containers.</li>
<li>If not, check for networking issues.</li>
<li>If the DNS resolution is working, then start tcpdump inside your application container and check if the curl packet is reaching the container.</li>
<li>Check the source and destination IP address of the packets.</li>
<li>Check the iptables rules on the hosts.</li>
<li>Check sysctl settings.</li>
</ul>
