<p>I'm trying to configure postgres for my k8s. But after launching postgres pod, i recieve an error:</p>
<pre><code>&quot;psql: error: connection to server on socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot; failed: FATAL:  role &quot;amigoscode&quot; does not exist&quot;
</code></pre>
<p>Here is my configmap:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-config
data:
  POSTGRES_DB: amigoscode
  POSTGRES_USER: amigoscode
  POSTGRES_PASSWORD: password
</code></pre>
<p>stateful set:</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  serviceName: postgres
  replicas: 1
  template:
    metadata:
      name: postgres
      labels:
        app: postgres
    spec:
      volumes:
        - name: postgres
          persistentVolumeClaim:
            claimName: postgres-pc-volume-claim
      containers:
        - name: postgres
          image: postgres
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - mountPath: &quot;/var/lib/postgresql/data&quot;
              name: postgres
          envFrom:
            - configMapRef:
                name: postgres-config
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 500m
              memory: 512Mi
      restartPolicy: Always
  selector:
    matchLabels:
      app: postgres
</code></pre>
<p>I'm using kubectl apply -f &lt;folder_name&gt; command to start and build my postgres-pod</p>

LordArnur
<p>You should add a service like that:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: postgres
</code></pre>
<p>specify the container port into the StatefulSet</p>
<pre><code>ports:
  - containerPort: 5432
</code></pre>
<p>and then access the database with the command:</p>
<pre><code>psql -v -U amigoscode --dbname amigoscode -h &lt;host&gt; &lt;&lt;-EOSQL
   &lt;psql lines&gt; 
EOSQL
</code></pre>
