<p>I have implemented a gRPC client server in Go. I have now set them up in Kubernetes as client and server pods where the client connects to the server. I've set this cluster up using vagrant (centos/7) on my PC. My issue is that the client wants to hit the port 8090 (sever serves on this port) and send a message to the server, but as they are in different pods the client cannot hit localhost 8090 and therefore the pod fails. How do I solve this problem?</p>

<pre class="lang-golang prettyprint-override"><code>func main() {
    conn, err := grpc.Dial(":8090", grpc.WithInsecure())
    if err != nil {
        log.Fatalf("did not connect :%v", err)
    }
    cli := proto.NewPingClient(conn)
</code></pre>

<p>as seen it tries to dial 8090, but not able to map it to the localhost of the server pod.</p>

<p><code>localhost</code> can only be used to address the group of containers running in a single Pod. </p>

<p>Pod to Pod communications should go via a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service</a>. </p>

<p>The following example service will forward traffic to any Pods labelled with <code>app: grpc-app</code></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: grpc-service
spec:
  selector:
    app: grpc-app
  ports:
    - protocol: TCP
      port: 8090
      targetPort: 8090
</code></pre>

<p>You will then have a DNS hostname to access the service with. </p>

<p><code>grpc-service.&lt;namespace&gt;.svc.&lt;cluster-domain&gt;</code>
which is usually<br> <code>grpc-service.default.svc.cluster.local</code></p>

<pre><code>func main() {
    conn, err := grpc.Dial("name-of-your-grpc-service:8090", grpc.WithInsecure())
    if err != nil {
        log.Fatalf("did not connect :%v", err)
    }
    cli := proto.NewPingClient(conn)
</code></pre>
