<p>I am having an issue with Kubernetes on GKE. 
I am unable to resolve services by their name using internal DNS. </p>

<p>this is my configuration</p>

<p>Google GKE v1.15</p>

<pre><code>kubectl get namespaces
NAME              STATUS   AGE
custom-metrics    Active   183d
default           Active   245d
dev               Active   245d
kube-node-lease   Active   65d
kube-public       Active   245d
kube-system       Active   245d
stackdriver       Active   198d
</code></pre>

<p>I've deployed a couple of simple services based on openjdk 11 docker image and made with spring boot + actuator in order to have a /actuator/health endpoint to test in dev </p>

<pre><code>kubectl get pods --namespace=dev
NAME                          READY   STATUS    RESTARTS   AGE
test1-5d86946c49-h9t9l        1/1     Running   0          3h1m
test2-5bb5f4ff8d-7mzc8        1/1     Running   0          3h10m
</code></pre>

<p>If i try to execute under </p>

<pre><code>kubectl --namespace=dev exec -it test1-5d86946c49-h9t9  -- /bin/bash
root@test1-5d86946c49-h9t9:/app# cat /etc/resolv.conf
nameserver 10.40.0.10
search dev.svc.cluster.local svc.cluster.local cluster.local europe-west1-b.c.back-office-236415.internal c.back-office-236415.internal google.internal
options ndots:5
root@test1-5d86946c49-h9t9:/app# nslookup test2
Server:         10.40.0.10
Address:        10.40.0.10#53

** server can't find test2: NXDOMAIN

</code></pre>

<p>The same issue occurs if I try using test2 service and try to resolve test1. There is a special configuration for namespace to enable DNS resolve? Shouldn't this be automatic?</p>

<p>I have reproduced this using master version 1.15 and and type of service as ‘ClusterIP’. I am able to do look up from the Pod of one service to another. For creating Kubernetes Services in a Google Kubernetes Engine cluster [1] might be helpful.</p>

<p>To see the services:
$ kubectl get svc --namespace=default</p>

<p>To access the deployment:
$ kubectl exec -it [Pod Name] sh</p>

<p>To lookup:
$ nslookup [Service Name]</p>

<p>Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name. By default, a client Pod’s DNS search list will include the Pod’s own namespace and the cluster’s default domain.</p>

<p>“Normal” (not headless) Services are assigned a DNS A record for a name of the form my-svc.my-namespace.svc.cluster-domain.example. This resolves to the cluster IP of the Service.</p>

<p>For “Headless” (without a cluster IP) Services are also assigned a DNS A record for a name.Though this resolves to the set of IPs of the pods selected by the Service.</p>

<p>However, DNS policies can be set on a per-pod basis. Currently Kubernetes supports the following pod-specific DNS policies. These policies are specified in the dnsPolicy field of a Pod Spec [2]:</p>

<p>“Default“: The Pod inherits the name resolution configuration from the node that the pods run on. </p>

<p>“ClusterFirst“: Any DNS query that does not match the configured cluster domain suffix, such as “www.kubernetes.io”, is forwarded to the upstream nameserver inherited from the node. Cluster administrators may have extra stub-domain and upstream DNS servers configured. </p>

<p>“ClusterFirstWithHostNet“: For Pods running with hostNetwork, need to set its DNS policy “ClusterFirstWithHostNet”.</p>

<p>“None“: It allows a Pod to ignore DNS settings from the Kubernetes environment. All DNS settings are supposed to be provided using the dnsConfig field in the Pod Spec.</p>

<p>[1]-<a href="https://cloud.google.com/kubernetes-engine/docs/how-to/exposing-apps" rel="nofollow noreferrer">https://cloud.google.com/kubernetes-engine/docs/how-to/exposing-apps</a>
[2]-<a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-config" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-config</a></p>
