<p>I have two Kubernetes deployments: <code>composite-app</code> (1 pod) and <code>product-app</code> (2 pods), both listening in port 8080. The first one needs to call the second one sometimes.</p>
<p>However, the first deployment can't find the second one. When it tries to call it using the <code>product.app</code> host it fails:</p>
<blockquote>
<p>Exception: I/O error on GET request for &quot;http://product-app:8080/product/123&quot;: product-app;
nested exception is UnknownHostException</p>
</blockquote>
<p>Am I using the right host? So far I've tried (to no avail):</p>
<ul>
<li><code>product</code></li>
<li><code>product-app.default.pod.cluster.local</code></li>
<li><code>product-app</code></li>
</ul>
<p>Here's my YAML:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: composite-service
spec:
  type: NodePort
  selector:
    app: composite-app
  ports:
    - targetPort: 8080
      port: 8080
      nodePort: 30091
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: composite-deploy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: composite-app
  template:
    metadata:
      labels:
        app: composite-app
    spec:
      containers:
      - name: composite-container
        image: 192.168.49.2:2376/composite-ms:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: product-app
  template:
    metadata:
      labels:
        app: product-app
    spec:
      containers:
      - name: product-container
        image: 192.168.49.2:2376/product-ms:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 8080
</code></pre>

Joe DiNottra
<p>You need to define a <code>Service</code> object for the <code>product-deploy</code> <code>Deployment</code> as well for the other pod to be able to connect to it. The <code>Service</code> can be of type <code>ClusterIP</code> if it is not needed to be exposed to the external world.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: product-service
spec:
  type: ClusterIP
  selector:
    app: product-app
  ports:
    - targetPort: 8080
      port: 8080
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: product-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: product-app
  template:
    metadata:
      labels:
        app: product-app
    spec:
      containers:
      - name: product-container
        image: 192.168.49.2:2376/product-ms:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 8080
</code></pre>
<p>You can connect to the other pod using the pod's IP without the service. However, that is not recommended since the pod's IP can be changed across pod updates.</p>
<p>You can then connect to the <code>product-app</code> pod from the <code>composite-app</code> using <code>product-service</code>.</p>
