Open NohaIhab opened 1 year ago
Modifying service command ROCK as follows does help. Environment variables are not expanded in the command and service fails to start:
$ microk8s.kubectl -n test logs notebook-pod
2023-10-03T16:10:11.394Z [pebble] Started daemon.
2023-10-03T16:10:11.430Z [pebble] Service "jupyter" starting: ./jupyter lab --notebook-dir=${HOME} --ip=0.0.0.0 --no-browser --port=8888 --ServerApp.token="" --ServerApp.password="" --ServerApp.allow_origin="*" --ServerApp.base_url=${NB_PREFIX} --ServerApp.authenticate_prometheus="False"
2023-10-03T16:10:11.431Z [pebble] POST /v1/services 33.467774ms 202
2023-10-03T16:10:11.431Z [pebble] Started default services with change 1.
2023-10-03T16:10:13.233Z [jupyter] [C 2023-10-03 16:10:13.232 ServerApp] Bad config encountered during initialization: No such directory: ''/opt/conda/bin/${HOME}''
2023-10-03T16:10:13.270Z [pebble] Service "jupyter" stopped unexpectedly with code 1
This needs to be resolved prior to experimenting with passing environment variables set in Pod to Pebble/service command.
Used bash -c
to wrap around command:
command: bash -c './jupyter lab --notebook-dir=${HOME} --ip=0.0.0.0 --no-browser --port=8888 --ServerApp.token=\"\" --ServerApp.password=\"\" --ServerApp.allow_origin=\"*\" --ServerApp.base_url=${NB_PREFIX} --ServerApp.authenticate_prometheus=False'
When this ROCK is deployed, service starts correctly without errors, because it is relying on environment variables specified in service (note that environment variables are not expanded in the logs, but values are passed to command correctly which is indicated by the logs):
$ microk8s.kubectl -n test logs notebook-pod
2023-10-03T19:52:52.677Z [pebble] Started daemon.
2023-10-03T19:52:52.691Z [pebble] POST /v1/services 13.452901ms 202
2023-10-03T19:52:52.691Z [pebble] Started default services with change 1.
2023-10-03T19:52:52.705Z [pebble] Service "jupyter" starting: bash -c './jupyter lab --notebook-dir=${HOME} --ip=0.0.0.0 --no-browser --port=8888 --ServerApp.token=\"\" --ServerApp.password=\"\" --ServerApp.allow_origin=\"*\" --ServerApp.base_url=${NB_PREFIX} --ServerApp.authenticate_prometheus=False'
2023-10-03T19:52:54.033Z [jupyter] [I 2023-10-03 19:52:54.033 ServerApp] jupyter_server_mathjax | extension was successfully linked.
2023-10-03T19:52:54.035Z [jupyter] [I 2023-10-03 19:52:54.035 ServerApp] jupyterlab | extension was successfully linked.
2023-10-03T19:52:54.035Z [jupyter] [I 2023-10-03 19:52:54.035 ServerApp] jupyterlab_git | extension was successfully linked.
2023-10-03T19:52:54.037Z [jupyter] [I 2023-10-03 19:52:54.037 ServerApp] nbclassic | extension was successfully linked.
2023-10-03T19:52:54.037Z [jupyter] [I 2023-10-03 19:52:54.037 ServerApp] nbdime | extension was successfully linked.
2023-10-03T19:52:54.038Z [jupyter] [I 2023-10-03 19:52:54.037 ServerApp] Writing Jupyter server cookie secret to /home/jovyan/.local/share/jupyter/runtime/jupyter_cookie_secret
2023-10-03T19:52:54.477Z [jupyter] [I 2023-10-03 19:52:54.477 ServerApp] notebook_shim | extension was successfully linked.
2023-10-03T19:52:54.510Z [jupyter] [I 2023-10-03 19:52:54.510 ServerApp] notebook_shim | extension was successfully loaded.
2023-10-03T19:52:54.510Z [jupyter] [I 2023-10-03 19:52:54.510 ServerApp] jupyter_server_mathjax | extension was successfully loaded.
2023-10-03T19:52:54.511Z [jupyter] [I 2023-10-03 19:52:54.511 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab
2023-10-03T19:52:54.511Z [jupyter] [I 2023-10-03 19:52:54.511 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
2023-10-03T19:52:54.512Z [jupyter] [I 2023-10-03 19:52:54.512 ServerApp] jupyterlab | extension was successfully loaded.
2023-10-03T19:52:54.513Z [jupyter] [I 2023-10-03 19:52:54.513 ServerApp] jupyterlab_git | extension was successfully loaded.
2023-10-03T19:52:54.516Z [jupyter] [I 2023-10-03 19:52:54.515 ServerApp] nbclassic | extension was successfully loaded.
2023-10-03T19:52:54.599Z [jupyter] [I 2023-10-03 19:52:54.599 ServerApp] nbdime | extension was successfully loaded.
2023-10-03T19:52:54.600Z [jupyter] [I 2023-10-03 19:52:54.599 ServerApp] Serving notebooks from local directory: /home/jovyan
2023-10-03T19:52:54.600Z [jupyter] [I 2023-10-03 19:52:54.599 ServerApp] Jupyter Server 1.24.0 is running at:
2023-10-03T19:52:54.600Z [jupyter] [I 2023-10-03 19:52:54.600 ServerApp] http://notebook-pod:8888/lab?token=...
2023-10-03T19:52:54.600Z [jupyter] [I 2023-10-03 19:52:54.600 ServerApp] or http://127.0.0.1:8888/lab?token=...
2023-10-03T19:52:54.600Z [jupyter] [I 2023-10-03 19:52:54.600 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
Created Pod with environment variables that have invalid values:
apiVersion: v1
kind: Pod
metadata:
name: notebook-pod
spec:
containers:
- name: jupyter
image: charmedkubeflow/jupyter-pytorch-test:v1.7.0_20.04_1
env:
- name: HOME
value: "some/invalid/home"
- name: NB_PREFIX
value: "some/invalid/prefix"
ports:
- containerPort: 8888
When deploying this Pod the expectation is that environment variables will be passed to command
of service
in the ROCK which will cause workload to fail, this did not however happened. Values of enviroment variables from the service were taken:
$ microk8s.kubectl -n test apply -f notebook-pod.yaml
2023-10-03T19:59:15.793Z [pebble] Started daemon.
2023-10-03T19:59:15.810Z [pebble] POST /v1/services 16.47018ms 202
2023-10-03T19:59:15.811Z [pebble] Started default services with change 1.
2023-10-03T19:59:15.826Z [pebble] Service "jupyter" starting: bash -c './jupyter lab --notebook-dir=${HOME} --ip=0.0.0.0 --no-browser --port=8888 --ServerApp.token=\"\" --ServerApp.password=\"\" --ServerApp.allow_origin=\"*\" --ServerApp.base_url=${NB_PREFIX} --ServerApp.authenticate_prometheus=False'
2023-10-03T19:59:17.158Z [jupyter] [I 2023-10-03 19:59:17.158 ServerApp] jupyter_server_mathjax | extension was successfully linked.
2023-10-03T19:59:17.160Z [jupyter] [I 2023-10-03 19:59:17.160 ServerApp] jupyterlab | extension was successfully linked.
2023-10-03T19:59:17.160Z [jupyter] [I 2023-10-03 19:59:17.160 ServerApp] jupyterlab_git | extension was successfully linked.
2023-10-03T19:59:17.161Z [jupyter] [I 2023-10-03 19:59:17.161 ServerApp] nbclassic | extension was successfully linked.
2023-10-03T19:59:17.161Z [jupyter] [I 2023-10-03 19:59:17.161 ServerApp] nbdime | extension was successfully linked.
2023-10-03T19:59:17.162Z [jupyter] [I 2023-10-03 19:59:17.162 ServerApp] Writing Jupyter server cookie secret to /home/jovyan/.local/share/jupyter/runtime/jupyter_cookie_secret
2023-10-03T19:59:17.582Z [jupyter] [I 2023-10-03 19:59:17.582 ServerApp] notebook_shim | extension was successfully linked.
2023-10-03T19:59:17.617Z [jupyter] [I 2023-10-03 19:59:17.616 ServerApp] notebook_shim | extension was successfully loaded.
2023-10-03T19:59:17.617Z [jupyter] [I 2023-10-03 19:59:17.617 ServerApp] jupyter_server_mathjax | extension was successfully loaded.
2023-10-03T19:59:17.618Z [jupyter] [I 2023-10-03 19:59:17.617 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab
2023-10-03T19:59:17.618Z [jupyter] [I 2023-10-03 19:59:17.618 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
2023-10-03T19:59:17.619Z [jupyter] [I 2023-10-03 19:59:17.619 ServerApp] jupyterlab | extension was successfully loaded.
2023-10-03T19:59:17.620Z [jupyter] [I 2023-10-03 19:59:17.620 ServerApp] jupyterlab_git | extension was successfully loaded.
2023-10-03T19:59:17.623Z [jupyter] [I 2023-10-03 19:59:17.623 ServerApp] nbclassic | extension was successfully loaded.
2023-10-03T19:59:17.699Z [jupyter] [I 2023-10-03 19:59:17.699 ServerApp] nbdime | extension was successfully loaded.
2023-10-03T19:59:17.700Z [jupyter] [I 2023-10-03 19:59:17.700 ServerApp] Serving notebooks from local directory: /home/jovyan
2023-10-03T19:59:17.700Z [jupyter] [I 2023-10-03 19:59:17.700 ServerApp] Jupyter Server 1.24.0 is running at:
2023-10-03T19:59:17.700Z [jupyter] [I 2023-10-03 19:59:17.700 ServerApp] http://notebook-pod:8888/lab?token=...
2023-10-03T19:59:17.700Z [jupyter] [I 2023-10-03 19:59:17.700 ServerApp] or http://127.0.0.1:8888/lab?token=...
2023-10-03T19:59:17.700Z [jupyter] [I 2023-10-03 19:59:17.700 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
The above experiment shows that environment variables from the Pod are not passed to command in services.
command
s in Jupyter ROCKs should be updated to use environment variables and bash -c
The problem will still exist though, since environment variables from the Pod are not making it to the process. Eg. deployed Pod in 1.7/edge has the following environment variables:
spec:
containers:
- env:
- name: NB_PREFIX
value: /notebook/admin/test2
- name: KF_PIPELINES_SA_TOKEN_PATH
value: /var/run/secrets/kubeflow/pipelines/token
Those are not passed down to the command
and their values do not match defaults used in ROCK. And since charm is not really launching Jupyter notebook server we cannot replan the service.
Pod environment variables are being passed to the workload, however, if those environment variables are also specified in environment
of the corresponding service
in Rockcraft project, the values from the Rockcraft project will be taken.
The solution for the issue is:
command
s in Jupyter ROCKs should be updated to use environment variables and bash -c
command
s should use HOME
and NB_PREFIX
environment variables.HOME
and NB_PREFIX
environment variables should be commented out with a note in Rockcraft project files.When ROCK with above requirements is deployed, while creating notebook server, user can connect through UI. The only issue is that it requires configuration of the token and that it displays the following:
track/1.7
fix should be forward ported to main as well
In upstream notebook server images, the
base_url
is set to an environment variable${NB_PREFIX}
here. This variable should be used in the command to start the Pebble service, but it is currently hardcoded to"/"
in the ROCK definitions, see here as an example.As a consequence, the server gets started at the wrong URL and we cannot connect to notebook servers.
Logs
To reproduce: