title: How to get into postgres in Kubernetes with local dev minikube
body: <p>Can please somebody help me? This is my first post here, and I am really exited to start posting here and helping people but I need help first.</p>
  
  <p>I am deploying my own Postgres database on Minikube. For db, password and username I am using secrets.</p>
  
  <p>Data is encoded with base64</p>
  
  <ol>
  <li>POSTGRES_USER = website_user</li>
  <li>POSTGRES_DB = website</li>
  <li>POSTGRES_PASSWORD = pass</li>
  </ol>
  
  <p>I also exec into container to see if I could see these envs and they were there.</p>
  
  <p>The problem is when I try to enter into postgres with psql. I checked minikube ip and typed correct password(pass) after this command:</p>
  
  <pre><code>pqsl -h 192.168.99.100 -U website_user -p 31315 website
  </code></pre>
  
  <p>Error</p>
  
  <blockquote>
    <p>Password for user website_user:<br>
    psql: FATAL:  password authentication failed for user "website_user"</p>
  </blockquote>
  
  <p>Also if I exec into my pod: </p>
  
  <pre><code>kubectl exec -it postgres-deployment-744fcdd5f5-7f7vx bash
  </code></pre>
  
  <p>And try to enter into postgres I get:</p>
  
  <pre><code>psql -h $(hostname -i) -U website_user -p 5432 website
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Password for user website_user:<br>
    psql: FATAL:  password authentication failed for user "website_user"</p>
  </blockquote>
  
  <p>I am lacking something here.I tried also <code>ps aux</code> in container, and everything seems to be find postgres processes are running</p>
  
  <pre><code>kubectl get all
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>NAME                                       READY   STATUS    RESTARTS   AGE
  pod/postgres-deployment-744fcdd5f5-7f7vx   1/1     Running   0          18m
  
  NAME                       TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
  service/kubernetes         ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          19m
  service/postgres-service   NodePort    10.109.235.114   &lt;none&gt;        5432:31315/TCP   18m
  
  NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
  deployment.apps/postgres-deployment   1/1     1            1           18m
  
  NAME                                             DESIRED   CURRENT   READY   AGE
  replicaset.apps/postgres-deployment-744fcdd5f5   1         1         1       18m
  
  # Secret store
  apiVersion: v1
  kind: Secret
  metadata:
    name: postgres-credentials
  type: Opaque
  data:
    POSTGRES_USER: d2Vic2l0ZV91c2VyCg==
    POSTGRES_PASSWORD: cGFzcwo=
    POSTGRES_DB: d2Vic2l0ZQo=
  
  
  ---
  # Persistent Volume
  apiVersion: v1
  kind: PersistentVolume
  metadata:
    name: postgres-pv
    labels:
      type: local
  spec:
    storageClassName: manual
    capacity:
      storage: 2Gi
    accessModes:
      - ReadWriteOnce
    hostPath:
      path: /data/postgres-pv
  
  
  ---
  # Persistent Volume Claim
  apiVersion: v1
  kind: PersistentVolumeClaim
  metadata:
    name: postgres-pvc
    labels:
      type: local
  spec:
    storageClassName: manual
    accessModes:
      - ReadWriteOnce
    resources:
      requests:
        storage: 2Gi
    volumeName: postgres-pv
  
  ---
  # Deployment
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: postgres-deployment
  spec:
    selector:
      matchLabels:
        app: postgres-container
    template:
      metadata:
        labels:
          app: postgres-container
      spec:
        containers:
          - name: postgres-container
            image: postgres:9.6.6
            env:
              - name: POSTGRES_USER
                valueFrom:
                  secretKeyRef:
                    name: postgres-credentials
                    key: POSTGRES_USER
  
              - name: POSTGRES_DB
                valueFrom:
                  secretKeyRef:
                    name: postgres-credentials
                    key: POSTGRES_DB
  
              - name: POSTGRES_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: postgres-credentials
                    key: POSTGRES_PASSWORD
  
            ports:
              - containerPort: 5432
            volumeMounts:
              - mountPath: /var/lib/postgresql/data
                name: postgres-volume-mount
        volumes:
          - name: postgres-volume-mount
            persistentVolumeClaim:
              claimName: postgres-pvc
  
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: postgres-service
  spec:
    selector:
      app: postgres-container
    ports:
      - port: 5432
        protocol: TCP
        targetPort: 5432
    type: NodePort
  </code></pre>