I am using JuPyter hub on k8s. It has a persistent volume claim. I want to have my users use a variable run_id = "sample"
every time they use jupyter notebook.
Doing so requires making a file aviral.py
in the path /home/jovyan/.ipython/profile_default/startup
with the content run_id = "sample"
.
I have to do this manually and would want this to be done as soon as the new user's pod is created for the first time i.e. the file gets written there itself.
Is there any way to automate this?
Everything mentioned here is taken off the shelf, as described here:
https://zero-to-jupyterhub.readthedocs.io/en/latest/setup-jupyterhub.html
I think the easiest way would be to create a
ConfigMap
from youraviral.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 youconfig.yaml
and applying the changes.Inside your deployment you need to add following container spec:
If I'm not mistaken and this is indeed correct config.yaml for Jupyter Hub, the
storage
part should look like the following:Or another approach, you could modify your
config.yaml
and changepostStart
command so it might look like this:You can check the documentation about Define a Command and Arguments for a Container.
I hope this helps.