<ol>
<li>I've created the persistent volume (EBS 10G) and corresponding persistent volume claim first. But when I try to deploy the postgresql pods as below (yaml file) :</li>
</ol>

<p><a href="https://i.stack.imgur.com/1bM88.png" rel="noreferrer">test-postgresql.yaml</a></p>

<p>Receive the errors from pod:</p>

<p><strong>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.</strong></p>

<p>Why the pod can't use this path? I've tried the same tests on minikube. I didn't meet any problem.  </p>

<ol start="2">
<li>I tried to change volume mount directory path to "/var/lib/test/data", the pods can be running. I created a new table and some data on it, and then killed this pod. Kubernete created a new pod. But the new one didn't preserve the previous data and table. </li>
</ol>

<p>So what's the way to correctly mount a postgresql volume using Aws EBS in Kubernete, which allows the recreated pods can reuse initial data base stored in EBS?</p>

<blockquote>
  <p>So what's the way to correctly mount a postgresql volume using Aws EBS</p>
</blockquote>

<p>You are on a right path...</p>

<p>Error you get is because you want to use root folder of mounted volume <code>/</code> as postgresql Data dir and postgresql complains that it is not best practice to do so since it is not empty and contains already some data inside (namely <code>lost+found</code> directory).</p>

<p>It is far better to locate data dir in separate empty subfolder (<code>/postgres</code> for example) and give postgresql clean slate when creating its file structure. You didn't get same thing on minicube since you most probably mounted host folder that didn't have anything inside (was empty) and didn't trigger such a complaint.</p>

<p>To do so, you would need initially empty <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="noreferrer">subPath</a> of your volume (empty <code>/postgres</code> subfolder on your PV for example) mounted to appropriate mount point (<code>/var/lib/posgresql/data</code>) in your pod. Note that you can name subPath and mount point end folder the same name, they are different here just as an example where <code>test-db-volume/postgres</code> folder would be mounted on pod to <code>/var/lib/postgresql/data</code> folder:</p>

<pre><code>...
volumeMounts:
- mountPath: /var/lib/postgresql/data
  name: test-db-volume
  subPath: postgres
...
</code></pre>
