<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>

Tanmay Shrivastava
<p>The most standard solution for this problem is to forget about connecting to localhost, then create ClusterIP service connected to the selected server pod in the same namespace:
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: server-service
  labels:
    app: your-label
spec:
  type: ClusterIP
  ports:
  - port: 8090
    targetPort: 8090
    protocol: TCP
  selector:
    app: your-label
</pre></code></p>

<p>Remember to use the same <code>metadata.labels.app</code> value in your pod description, otherwise the two will not be connected to each other.<br>
If you have your cluster configured properly, and CoreDNS up and running, you should be able to access the server using <code>server-service:8090</code> if you are running your client and server pods in the same namespace.</p>
