5

I've got a JupyterHub Kubernetes deployment.

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).

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

Here is an example from the docs that unfortunately seems to only copy from the new PV (not the image):

singleuser:
  lifecycleHooks:
    postStart:
      exec:
        command: ["cp", "-a", "src", "target"]

Here is my singleuser configuration:

singleuser:
  image:
    name: myimage
    tag: latest
    pullPolicy: Always
  storage:
    capacity: 10Gi
    dynamic:
      storageClass: standard
Rico
  • 58,485
  • 12
  • 111
  • 141
yvanscher
  • 1,009
  • 1
  • 13
  • 16

1 Answers1

4

The above should work fine.

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 mountPath:

apiVersion: v1
kind: Pod
metadata:
  name: jypyterhuyb
  namespace: default
spec:
  volumes:
  - name: myvol
    ...
  containers:
  - name: jypyter
    image: "jypytercontainer"
    volumeMounts:
    - name: myvol
      mountPath: /mnt/mypath
Rico
  • 58,485
  • 12
  • 111
  • 141
  • 2
    This is what my final solution looks like 1- Store files in a folder that is not home on the image (like /tmp). Mount the PV on home using singleuser:storage:homeMountPath. Then copy the files from /tmp to home using lifecycleHooks:postStart:exec:command. – yvanscher Jan 29 '19 at 09:57
  • 1
    i took my command formatting from here to run a script in life cycle hooks; important to not forget semicolons if you have multiple commands: https://stackoverflow.com/questions/39436845/multiple-command-in-poststart-hook-of-a-container – yvanscher Jan 29 '19 at 10:00
  • I am facing same problem but i dont want to copy the files manually – HERAwais Jul 21 '21 at 06:27