<p>I am testing a PostgreSQL configuration in kubernetes.</p>
<p>Windows 11
HyperV
Minikube</p>
<p>Everything works (or seems to work) fine
I can connect to the dabase via</p>
<pre><code>kubectl exec -it pod/postgres-0 -- bash
bash-5.1$ psql --username=$POSTGRES_USER -W --host=localhost --port=5432 --dbname=pg_test
Password:
psql (13.6)
Type &quot;help&quot; for help.

pg_test=#
</code></pre>
<p>I cam also view the database through DBeaver.</p>
<p>But when I try to connect from any browser,
localhost:5432
I get errors such as :</p>
<pre><code>firefox canot connect,
ERR_CONNECTION_REFUSED
</code></pre>
<p>I have no proxy</p>
<p>when I try</p>
<pre><code>kubectl port-forward service/postgres-service 5432:5432
Forwarding from 127.0.0.1:5432 -&gt; 5432
Forwarding from [::1]:5432 -&gt; 5432
Handling connection for 5432
Handling connection for 5432
... this line repeats indefinitely for connections attempt
Handling connection for 5432
Handling connection for 5432
...
</code></pre>
<p>Here is my YAML config file</p>
<p>...</p>
<pre><code>apiVersion: v1
data:
  db: pg_test
  user: admin
kind: ConfigMap
metadata:
  name: postgres-config

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: &quot;postgres&quot;
  replicas: 2
  selector:
    matchLabels:
      env: prod
      domain: infrastructure
  template:
    metadata:
      labels:
        env: prod
        domain: infrastructure
    spec:
      terminationGracePeriodSeconds: 20
      securityContext:
        runAsUser: 70
        fsGroup: 70
      containers:
      - name: kubia-postgres
        image: postgres:13-alpine
        env:
        - name: POSTGRES_PASSWORD
          value: admin
          # valueFrom:
          #   secretKeyRef:
          #     name: postgres-secret
          #     key: password
        - name: POSTGRES_USER
          value: admin
          # valueFrom:
          #   configMapKeyRef:
          #     name: postgres-config
          #     key: user
        - name: POSTGRES_DB
          valueFrom:
            configMapKeyRef:
              name: postgres-config
              key: db
        ports:
        - containerPort: 5432
          protocol: TCP
        volumeMounts:
        - name: postgres-test-volume
          mountPath: /var/lib/postgresql
        resources:
          requests:
            memory: &quot;64Mi&quot;
            cpu: &quot;250m&quot;
          limits:
            memory: &quot;128Mi&quot;
            cpu: &quot;500m&quot;
      volumes:
      - name: postgres-test-volume
        emptyDir: {}

---

apiVersion: v1
kind: Service
metadata:
  name: postgres-service
  labels:
    env: prod
    domain: infrastructure
spec:
  ports:
  - port: 5432
    targetPort: 5432
    protocol: TCP
    name: pgsql
  clusterIP: None
  selector:
    env: prod
    domain: infrastructure
</code></pre>
<p>What am I doing wrong ?</p>

Tarek EZZAT
<p>If you want to access your Postgres instance using a web browser, you need to deploy and configure something like <a href="https://www.pgadmin.org/" rel="nofollow noreferrer">pgAdmin</a>.</p>
