<p>In my Kubernetes cluster, on my DB container, my persistent storage (dynamically provisioned on Digital Ocean) does not persist the storage if the pod is deleted.</p>

<p>I have changed the reclaim policy of the storage from Delete to Retain but this does not make a difference.</p>

<p>This is a copy of DB YAML file:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: db
  namespace: hm-namespace01
    app: app1
spec:
  type: NodePort
  ports:
   - port: 5432
  selector:
   app: app1

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: hm-pv-claim
  namespace: hm-namespace01
  labels:
    app: app1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: do-block-storage

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1
  namespace: hm-namespace01
  labels:
    app: app1
spec:
  selector:
    matchLabels:
      app: app1
      tier: backend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: app1
        tier: backend
    spec:
      containers:
        - name: app1
          image: postgres:11
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 5432
          volumeMounts:
          - name: postgredb
            mountPath: /var/lib/postgresql

      volumes:
        - name: postgredb
          persistentVolumeClaim:
            claimName: hm-pv-claim
</code></pre>

Rutnet
<p>You must match your <code>mountPath</code> with the Postgres <code>PGDATA</code> environment variable.</p>

<p>The <a href="https://hub.docker.com/_/postgres" rel="noreferrer">default value of <code>PGDATA</code></a> is <code>/var/lib/postgresql/data</code> (not <code>/var/lib/postgresql</code>).</p>

<p>You need to either adjust your <code>mountPath</code> or set the <code>PGDATA</code> env to match it.</p>
