<p>I'm trying to run two services with k8s running on minikube installation.
So I have the sevice <code>Foo</code> and <code>Bar</code>, so when I'm accessing the service <code>Foo</code> it must trigger service <code>Bar</code> to get the data.</p>

<p>Here is the deployment configuration for <code>Foo</code> service
<code>foo-deployment.yaml</code>:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: foo-server
  labels:
    app: foo-server
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: foo-server
        serving: "true"
    spec:
      containers:
      - name: foo-server
        image: foo-container
        env:
        - name: BAR_SERVICE_URL
          value: http://bar-server:8081
        ports:
        - containerPort: 8080
          name: http
</code></pre>

<p><code>foo-svc.yaml</code>:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: foo-server
  labels:
    app: foo-server
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
    name: http
  selector:
    app: foo-server
    serving: "true"
</code></pre>

<p>The <code>BAR_SERVICE_URL</code> evn variable is used inside the <code>Foo</code> so the service knows the host to <code>Bar</code>.
And here is the service configuration for <code>Bar</code> service
<code>bar-svc.yaml</code>:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: bar-server
  labels:
    app: bar-server
spec:
  type: NodePort
  ports:
  - port: 8081
    targetPort: 8081
    name: http
  selector:
    app: bar-server
</code></pre>

<p><code>bar-deployment.yaml</code>:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: bar-server-v1
  labels:
    app: bar-server
    version: "1.0"
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: bar-server
        version: "1.0"
        serving: "true"
    spec:
      containers:
      - name: bar-server
        image: bar-container
        ports:
        - containerPort: 8081
          name: http
</code></pre>

<p>When I'm accessing the <code>Foo</code> service with the minikube ip and exposed service port I receive the following error in the pod logs:</p>

<pre><code>2018-02-08 14:32:25.875 ERROR 1 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://bar-server:8081/endpoint": bar-server; nested exception is java.net.UnknownHostException: bar-server] with root cause

java.net.UnknownHostException: bar-server
</code></pre>

<p>However, I can access the <code>bar-server/endpoint</code> using the minikube ip and exposed port like this <code>http://192.168.99.100:31168/endpoint</code>.</p>

<p>So looks like I can access the <code>Foo</code> and <code>Bar</code> services from outside the cluster. But <code>Foo</code> service cannot resolve the <code>Bar</code> service host and cannot access it.</p>

<p><strong>UPD</strong>: Here are some update with troubleshouting details. </p>

<ul>
<li>On <code>minikube</code> the <code>kube-dns</code> addon is enabled. </li>
<li>Trying from the iside of <code>Foo</code> pod to <code>wget</code> to the <code>Bar</code> service endpoint. I'm able to do it via IP address of the <code>bar-server</code> but not with <code>bar-server:8081/endpoint</code>.</li>
<li><p>Trying <code>nslookup kubernetes.default.svc.cluster.local localhost</code> looks good. Here is the ouptput:</p>

<p>Server:    127.0.0.1
Address 1: 127.0.0.1 localhost</p></li>
<li><p>Also <code>dns</code> pod looks up and running. Here is the output for <code>kubectl get pods -n=kube-system | grep -i dns</code></p>

<p>kube-dns-6777479f6b-vxd7m               3/3       Running   9          1d</p></li>
</ul>

<p>Kubernetes does service discovery using DNS (<code>kube-dns</code>). If DNS in k8s is working, service <code>Foo</code> should be able to <code>ping</code> or <code>curl</code> service <code>Bar</code>, and vice-versa.</p>

<p>A way to check if <code>kube-dns</code> is working is to see if the following commands work inside any pod:</p>

<pre><code>nslookup kubernetes.default.svc.cluster.local localhost
nslookup kubernetes.default localhost
</code></pre>

<p><code>kube-dns</code> pod's health can be checked in the output of:</p>

<pre><code>kubectl get pods -n=kube-system | grep -i dns
</code></pre>
