I think the easiest way would be to create a ConfigMap
from your aviral.py
file:
kubectl create configmap aviral-configmap --from-file=aviral.py
And add it to the Deployment
used by JuPyter Hub.
You can read how to Customizing your Deployment as this would require modification of you config.yaml
and applying the changes.
Inside your deployment you need to add following container spec:
spec:
containers:
- name: <Container_Name>
image: <Image_Name>
volumeMounts:
- name: my-config
mountPath: /home/jovyan/.ipython/profile_default/startup
volumes:
- name: my-config
configMap:
name: aviral-configmap
If I'm not mistaken and this is indeed correct config.yaml for Jupyter Hub, the storage
part should look like the following:
...
extraVolumes:
- name: home
hostPath:
path: /data/homes/{username}
- name: tutorial
hostPath:
path: /data/homes/_tutorials
- name: my-config
configMap:
name: aviral-configmap
extraVolumeMounts:
- name: home
mountPath: /home/jovyan
- name: tutorial
mountPath: /home/jovyan/tutorials
readOnly: True
- name: my-config
mountPath: /home/jovyan/.ipython/profile_default/startup
...
Or another approach, you could modify your config.yaml
and change postStart
command so it might look like this:
...
postStart:
exec:
command: ["/bin/sh", "-c", "test -d $HOME/my-work || mkdir $HOME/my-work; mkdir -p /home/jovyan/.ipython/profile_default/startup; echo 'run_id = sample' > aviral.py"]
...
You can check the documentation about Define a Command and Arguments for a Container.
I hope this helps.