<p>I've got a JupyterHub Kubernetes deployment.</p>

<p>When I create and attach a persistent volume (PV) it wipes out the home directory that is part of my image. It replaces it with an empty home directory where anything is written will be persisted as expected (that is fine).</p>

<p>How can I get the files from my image's home folder into the PV home folder?</p>

<p>Here is an <a href="https://zero-to-jupyterhub.readthedocs.io/en/latest/user-environment.html" rel="noreferrer">example from the docs</a> that unfortunately seems to only copy from the new PV (not the image):</p>

<pre><code>singleuser:
  lifecycleHooks:
    postStart:
      exec:
        command: ["cp", "-a", "src", "target"]
</code></pre>

<p>Here is my singleuser configuration:</p>

<pre><code>singleuser:
  image:
    name: myimage
    tag: latest
    pullPolicy: Always
  storage:
    capacity: 10Gi
    dynamic:
      storageClass: standard
</code></pre>

<p>The above should work fine.</p>

<p>You are probably mounting the PV on your home directory that is the same home directory of the container. You can either mount the PV on a different directory and do the copy or create a new image where your data is not stored in your home directory. This is an example of how to use <a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer"><code>mountPath</code></a>:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: jypyterhuyb
  namespace: default
spec:
  volumes:
  - name: myvol
    ...
  containers:
  - name: jypyter
    image: "jypytercontainer"
    volumeMounts:
    - name: myvol
      mountPath: /mnt/mypath
</code></pre>
