<p>I have a deployment and service yaml file. I use <code>minikube</code> to run <code>Kubernetes</code> in my <code>WSL</code>.</p>
<ul>
<li>postgres-deployment.yaml:</li>
</ul>
<pre><code># PostgreSQL StatefulSet
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgresql-db
spec:
  replicas: 1
  serviceName: postgresql-db-service
  selector:
    matchLabels:
      app: postgresql-db
  template:
    metadata:
      labels:
        app: postgresql-db
    spec:
      containers:
      - name: postgresql-db
        image: postgres:latest
        volumeMounts:
        - name: postgresql-db-disk
          mountPath: /data
        env:
        - name: POSTGRES_PASSWORD
          value: testpassword
        - name: PGDATA
          value: /data/pgdata
# Volume Claim
  volumeClaimTemplates:
  - metadata:
      name: postgresql-db-disk
    spec:
      accessModes: [&quot;ReadWriteOnce&quot;]
      resources:
        requests:
          storage: 25Gi
</code></pre>
<ul>
<li>postgres-service.yaml:</li>
</ul>
<pre><code># PostgreSQL StatefulSet Service
apiVersion: v1
kind: Service
metadata:
  name: postgres-db-lb
spec:
  selector:
    app: postgresql-db
  type: LoadBalancer
  ports:
  - port: 5432
    targetPort: 5432
</code></pre>
<p>I run them with:</p>
<blockquote>
<p># kubectl apply -f postgres-deployment.yaml <br>
# kubectl apply -f postgres-service.yaml</p>
</blockquote>
<p>The deployment works, I get the Cluster IP of the service with <code>kubectl get all</code>.</p>
<p>I run the pgAdmin with the command:</p>
<blockquote>
<p>docker run -p 80:80 <br />
-e 'PGADMIN_DEFAULT_EMAIL=user@domain.com' <br />
-e 'PGADMIN_DEFAULT_PASSWORD=SuperSecret' <br />
-d dpage/pgadmin4</p>
</blockquote>
<p>I try to connect to the postgres but I am unable to connect.
<a href="https://i.stack.imgur.com/sQLLN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sQLLN.png" alt="enter image description here" /></a></p>
<h1>EDIT:</h1>
<ul>
<li>I changed the user for connection to <code>postgres</code>, still doesn't works.</li>
<li>I tried to change the LoadBalancer to ClusterIp and NodePort, it doesn't work either.</li>
<li>I tried to change my OS to Ubuntu, in case of some weird WSL issues, it doesn't work either.</li>
</ul>

Hamza Ince
<p>To access the Postgres locally, I have to use NodePort.<br>
We need to find the NodePort ip and port.</p>
<ul>
<li>To find the nodeport internal-ip, do:</li>
</ul>
<blockquote>
<p>$ kubectl get nodes -o wide</p>
</blockquote>
<ul>
<li>For the port we can do <code>kubectl describe svc postgres-db-lb</code> or <code>kubectl get svc</code>.<br></li>
</ul>
<p>In pgAdmin the hostname should-be <code>&lt;node-ip&gt;:&lt;node-port&gt;</code>.
<br>We can also do <code>minikube service postgres-db-lb</code> to find the url.</p>
<h1>EDIT</h1>
<p>Or more simply <code>minikube service &lt;NAME_OF_SERVICE&gt;</code>.</p>
