<p>So I'm just trying to get a web app running on GKE experimentally to familiarize myself with Kubernetes and GKE. </p>

<p>I have a statefulSet (Postgres) with a persistent volume/ persistent volume claim which is mounted to the Postgres pod as expected.  The problem I'm having is having the Postgres data endure. If I mount the PV at <code>var/lib/postgres</code> the data gets overridden with each pod update. If I mount at <code>var/lib/postgres/data</code> I get the warning:</p>

<p><code>initdb: directory "/var/lib/postgresql/data" exists but is not empty
It contains a lost+found directory, perhaps due to it being a mount point.
Using a mount point directly as the data directory is not recommended.
Create a subdirectory under the mount point.</code></p>

<p>Using Docker alone having the volume mount point at <code>var/lib/postgresql/data</code> works as expected and data endures, but I don't know what to do now in GKE. How does one set this up properly?</p>

<p>Setup file:</p>

<pre><code>---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sm-pd-volume-claim
spec:
  storageClassName: "standard"
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1G
---
apiVersion: "apps/v1"
kind: "StatefulSet"
metadata:
  name: "postgis-db"
  namespace: "default"
  labels:
    app: "postgis-db"
spec:
  serviceName: "postgis-db"
  replicas: 1
  selector:
    matchLabels:
      app: "postgis-db"
  template:
    metadata:
      labels:
        app: "postgis-db"
    spec:
      terminationGracePeriodSeconds: 25
      containers:
      - name: "postgis"
        image: "mdillon/postgis"
        ports:
        - containerPort: 5432
          name: postgis-port
        volumeMounts:
        - name: sm-pd-volume
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: sm-pd-volume
        persistentVolumeClaim:
          claimName: sm-pd-volume-claim
</code></pre>

konkrer
<p>You are getting this error because the postgres pod has tried to mount the data directory on / folder.  It is not recommended to do so. </p>

<p>You have to create subdirectory to resolve this issues on the statefulset manifest yaml files.</p>

<pre><code>  volumeMounts:
    - name: sm-pd-volume
      mountPath: /var/lib/postgresql/data
      subPath: data
</code></pre>
