<p>I'm using minikube to run kubernetes locally. My local k8s have two pods which one of them is PostgreSQL and another one is my own app. I've mounted a <code>PersistentVolume</code> and <code>PersistentVolumeClaim</code> in order to make a stateful pod for PostgreSQL:</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: postgres-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/psql"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: postgres-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
</code></pre>

<p>Here is PostgreSQL deployment yaml file:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: postgres
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: postgres
    spec:
      containers:
      - name: postgres
        imagePullPolicy: Never
        image: postgres:9.6
        ports:
        - name: postgres
          containerPort: 5432
        volumeMounts:
        - mountPath: /var/lib/postgresql
          name: postgres-persistent-storage
      volumes:
      - name: postgres-persistent-storage
        persistentVolumeClaim:
          claimName: postgres-pv-claim
</code></pre>

<p>The problem is that PostgreSQL service doesn't start and this error occurs when I run its pod:</p>

<pre><code>Error: /var/lib/postgresql/9.6/main is not accessible; please fix the directory permissions (/var/lib/postgresql/9.6/ should be world readable)
No PostgreSQL clusters exist; see "man pg_createcluster" ... (warning).
</code></pre>

<p>I've checked inside of PostgreSQL pod and I found that <code>/var/lib/postgresql</code> is empty, just like <code>/data/psql</code> In minikube host.
Can anyone help?</p>

<p>Change:</p>

<pre><code>volumeMounts:
  - mountPath: /var/lib/postgresql
</code></pre>

<p>to</p>

<pre><code>volumeMounts:
  - mountPath: /var/lib/postgresql/data
</code></pre>

<p>With the wrong mountPoint postgres executables were overridden.</p>

<p>I attach an image with the data I see from inside the pod (on the left) and from inside minikube space (on the right, the little shell from virtualbox).</p>

<p><a href="https://i.stack.imgur.com/m8rko.png" rel="noreferrer"><img src="https://i.stack.imgur.com/m8rko.png" alt="enter image description here"></a></p>
