<p>I have 2 pods: a server pod and a client pod (basically the client hits port 8090 to interact with the server). I have created a service (which in turn creates an endpoint) but the client pod cannot reach that endpoint and therefore it crashes:</p>

<blockquote>
  <p>Error :Error in client :rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial tcp :8090: connect: connection refused")</p>
</blockquote>

<p>The client pod tries to access port 8090 in its host network. What I am hoping to do is that whenever the client hits 8090 through the service it connects to the server.</p>

<p>I just cannot understand how I would connect these 2 pods and therefore require help.</p>

<p>server pod:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: server-pod
  labels:
    app: grpc-app
spec:
  containers:
  - name: server-pod
    image: image
    ports:
      - containerPort: 8090
</code></pre>

<p>client pod :</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: client-pod
  labels:
    app: grpc-app
spec:
  hostNetwork: true
  containers:
  - name: client-pod
    image: image
</code></pre>

<p>Service:</p>

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

<p>One thing that i feel is going wrong is that the services are not ready to accept connection and your client is trying to access that therefore getting a connection refused.I faced the similar problem few days back. What i did is added a readiness and liveness probe in the yaml config file.Kubernetes provides liveness and readiness probes that are used to check the health of your containers. These probes can check certain files in your containers, check a TCP socket, or make HTTP requests.</p>

<p>A sample like this</p>

<pre><code>spec:
      containers:
      - name: imagename
        image: image
        ports:
        - containerPort: 19500
          name: http
        readinessProbe:
          httpGet:
            path: /health
            port: http
          initialDelaySeconds: 120
          periodSeconds: 5
        livenessProbe:
          httpGet:
            path: /health
            port: http
            scheme: HTTP
          initialDelaySeconds: 120
          timeoutSeconds: 5
</code></pre>

<p>So it will check whether your application is ready to accept connection before redirecting traffic.</p>
