How to create a file while creating(claiming) persistent volume?

5/16/2019

I want to create a file at a certain path. The docker image that is being used is from the file:

singleuser:
  image:
    # Get the latest image tag at:
    # https://hub.docker.com/r/jupyter/datascience-notebook/tags/
    # Inspect the Dockerfile at:
    # https://github.com/jupyter/docker-stacks/tree/master/datascience-notebook/Dockerfile
    name: jupyter/datascience-notebook
    tag: 177037d09156

The above yaml is taken from here: https://zero-to-jupyterhub.readthedocs.io/en/latest/user-environment.html

JuPyterHub creates a new pod for each user in the scheme singleUser. I want to create a file as soon as there is a creation of the new volume.

I tried reading docs and other relevant questions but none of them addressed this issue.

Below is the snippet where the storage logic is defined. Each user gets a new pvc and I want to create a new file in this pvc whenever it is created. I already have the homeMountPath and the username in the below code snippet, I don't know how to write a file - something on the similar lines as: echo "run_id = 'sample' " > /home/jovyan/username/.ipython/profile_default/startup/aviral.py

storage:
    type: dynamic
    extraLabels: {}
    extraVolumes: []
    extraVolumeMounts: []
    static:
      pvcName:
      subPath: '{username}'
    capacity: 10Gi
    homeMountPath: /home/jovyan
    dynamic:
      storageClass:
      pvcNameTemplate: claim-{username}{servername}
      volumeNameTemplate: volume-{username}{servername}
      storageAccessModes: [ReadWriteOnce]

The full helm chart is available here, the official one: https://jupyterhub.github.io/helm-chart/jupyterhub-0.8.2.tgz

I expect the pods when created in the namespace jhub have a file already created.

-- Aviral Srivastava
docker
jupyter
jupyter-notebook
kubernetes
kubernetes-helm

1 Answer

5/16/2019

you can look at configmap object. files from configmap can be mounted as volume inside container.

-- P Ekambaram
Source: StackOverflow