<p>Currently, some of my pods are using ephemeral volumes (those created by Docker at the container level). I want some form of persistent data stored in specific directories on the host (like bind mounts in Docker) such that my pods can restart without losing data. Persistent Volume Claims seem to be the best way to do this. How should I go about transitioning my existing pods to use PVCs that copy across data from the existing ephemeral volumes?</p>

ExplosiveFridge
<ol>
<li>On the host, create the directory to hold your data. Eg. <code>mkdir /local_data</code></li>
<li>Copy the data to the local directory. Eg. <code>kubectl cp &lt;namespace&gt;/&lt;pod&gt;:/path/in/the/container /local_data</code></li>
<li>Check and check again all your data is intact in <code>/local_data</code></li>
<li>Create a new pod with the following spec.</li>
</ol>
<p>Example:</p>
<pre><code>kind: Pod
...
spec:
  ...
  nodeName: &lt;name&gt;  # &lt;-- if you have multiple nodes this ensure your pod always run on the host that hold the data
  containers:
  - name: ...
    ...
    volumeMounts:
    - name: local_data
      mountPath: /path/in/the/container
    ...
  volumes:
  - name: local_data
    hostPath: /local_data
    type: Directory
</code></pre>
<p>Apply and check if your pod runs as expected</p>
