<p>Summary of Setup</p>
<p>I have a remote Openshift Cluster with three pods. An nginx pod that serves a web app, a .NET pod that serves a .NET web api, and a Postgres database pod.</p>
<p>Problem</p>
<p>I am able to connect the nginx pod to the .NET pod and have no problem making api request. I cannot however get communication from the .NET pod to the Postgres pod in the Openshift cluster. I can curl the Postgres pod from the .NET pod's terminal in Openshift web console and am able to connect the Postgres pod itself (not the database) using the Postrgres pod's service name, so DNS resolution of the Postgres pod is working. Using Openshift's port forwarding to forward traffic from my local machine's localhost:5432 to my Postgres Pod's port 5432, I can connect to the Postgres datbase while running the .NET API locally using the connection string <code>Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres</code>. I can query, insert, etc with no problem as long as my connection to the database local. So connecting to the database via localhost clearly works. But when inside the Openshift cluster, I can't get the .NET pod to connect to Postgres Pod database. The database should see a connection from another pod as a remote connection right? But it isn't working at all. The postgres logs don't show anything about a connection attempt either.</p>
<p>My .NET uses <code>Host=postgres;Port=5432;Database=postgres;Username=postgres;Password=postgres</code>. This is stored in my appsettings.json. This is read in during in my Startup.cs.</p>
<pre><code>// (U) add database context
services.AddDbContext&lt;StigContext&gt;(
    options =&gt; options.UseNpgsql(Configuration[&quot;DbConnectionString&quot;])
);
</code></pre>
<p>.NET database connection method, this endpoint returns true when I run and connect to the remote Postgres pod locally on my machine via Openshift's port forwarding.</p>
<pre><code>public IActionResult TestDatabaseConnection()
{          
    try 
    {              
        stigContext.Database.OpenConnection();
        return Ok(stigContext.Database.CanConnect());
    }
    catch (Exception e)
    {
        var error = e.Message + &quot;\n&quot; + e.ToString() + &quot;\n&quot; + e.StackTrace;
        return Ok(error);
    }              
}
</code></pre>
<p>Postgres Deployment and Service, PVC is done through the Openshift web console</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  template:
    metadata:
      annotations:
          sidecar.istio.io/inject: &quot;true&quot;
          sidecar.istio.io/proxyCPULimit: 200m
          sidecar.istio.io/proxyMemory: 64Mi
          sidecar.istio.io/proxyMemoryLimit: 256Mi
          sidecar.istio.io/rewriteAppHTTPProbers: &quot;true&quot;
      labels:
        app: postgres
        version: v1
    spec:
      containers:
      - name: postgres 
        image: custom-docker-image-for-postgres:latest
        imagePullPolicy: Always
        env:
        - name: POSTGRES_DB
          value: postgres
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          value: postgres
        - name: POSTGRES_HOST_AUTH_METHOD
          value: trust
        - name: PGDATA
          value: /var/lib/postgresql/data/mydata
        ports:
        - containerPort: 5432
        volumeMounts:
        - name: postgres-pv-storage
          mountPath: /var/lib/postgresql/data
        resources:
          requests:
            memory: &quot;128Mi&quot;
            cpu: &quot;30m&quot;   
          limits:
            memory: &quot;512Mi&quot;
            cpu: &quot;60m&quot;                     
      volumes:
      - name: postgres-pv-storage
        persistentVolumeClaim:
          claimName: postgres-pv-claim
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: postgres
    service: postgres
  name: postgres
spec:
  ports:
    - name: http
      port: 5432
  selector:
    app: postgres
</code></pre>
<p>I ran a few command on the running Postgres pod to show the running config...</p>
<pre><code>$ postgres -C listen_addresses
*
</code></pre>
<pre><code>$ postgres -C hba_file
/var/lib/postgresql/data/mydata/pg_hba.conf
$ cat /var/lib/postgresql/data/mydata/pg_hba.conf
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# &quot;local&quot; is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

# warning trust is enabled for all connections
# see https://www.postgresql.org/docs/12/auth-trust.html
host all all all trust
</code></pre>
<pre><code>$ postgres -C port
5432
</code></pre>
<p>It seems like it should be able to connect remotely via pod to pod communication but definitely does not. I am at a loss as to what the issue is. I have no idea why its not working. I can provide any additional info if needed. Hopefully this is clear. Any suggestions are appreciated.</p>

JCole91
<p>tdlr: my service definition's port name for my postgres service was 'http' and not 'tcp'. The name field is actually is the protocol so it does matter what you put here.</p>
<p>solution found here <a href="https://github.com/istio/istio/issues/16506#issuecomment-636224246" rel="nofollow noreferrer">https://github.com/istio/istio/issues/16506#issuecomment-636224246</a></p>
<p>This may not be an issue if your deployment does not use istio.</p>
<p>The updated service yml for my postgres deployment is</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: postgres
    service: postgres
  name: postgres
spec:
  ports:
    - name: tcp
      port: 5432
  selector:
    app: postgres
</code></pre>
