Running Jupyter Notebook service

We offer two ways to approach this case:

The cloud-config way

A cloud-config file

$ cat anaconda.txt 
#cloud-config

yum_repos:
   epel:
        name: Extra Packages for Enterprise Linux 8 - $basearch
        baseurl: http://mirrors.ircam.fr/pub/fedora/epel/8/Everything/x86_64/
        failovermethod: priority
        enabled: 1
        gpgcheck: 0

packages:
  - tree
  - vim
  - wget
  - mlocate

runcmd:
  - timedatectl set-timezone Europe/Paris
  - service chronyd restart
  - sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  - yum config-manager --set-enabled PowerTools
  - setenforce 0
  - wget --directory-prefix=/tmp https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
  - sh /tmp/Anaconda3-2020.02-Linux-x86_64.sh -b -p /opt/anaconda3

Create the instance

Create the instance ( ex: Centos8 ) and bind it to floating address.

$ openstack server create  --flavor m1.large --image  CentOS-8-x86_64 
     --nic net-id=$OS_NET --security-group default --key-name user-key 
     --user-data anaconda.txt anac3_jcc

$ openstack server add floating ip anac3_jcc 134.158.21.74

Connect to instance

$ ssh -i  ~/.ssh/os_user.pem ~/.ssh/os_user.pem centos@134.158.21.74 
[centos@anac3-jcc ~]$

Customize your environment

$ /opt/anaconda3/bin/conda init bash
no change     [/opt/anaconda3/condabin/conda]()
no change     [/opt/anaconda3/bin/conda]()
no change     [/opt/anaconda3/bin/conda-env]()
no change     [/opt/anaconda3/bin/activate]()
no change     [/opt/anaconda3/bin/deactivate]()
no change     [/opt/anaconda3/etc/profile.d/conda.sh]()
no change     [/opt/anaconda3/etc/fish/conf.d/conda.fish]()
no change     [/opt/anaconda3/shell/condabin/Conda.psm1]()
no change     [/opt/anaconda3/shell/condabin/conda-hook.ps1]()
no change     [/opt/anaconda3/lib/python3.7/site-packages/xontrib/conda.xsh]()
no change     [/opt/anaconda3/etc/profile.d/conda.csh]()
modified      [/home/centos/.bashrc]()

==> For changes to take effect, close and re-open your current shell. <==

You can reload the new customized bashrc environment

$ source  ~/.bashrc

Launch the notebook

(base) [centos@anac3-jcc ~]$ jupyter notebook
[I 13:25:36.255 NotebookApp] Writing notebook server cookie secret to [/home/centos/.local/share/jupyter/runtime/notebook_cookie_secret]()
[I 13:25:36.454 NotebookApp] JupyterLab extension loaded from [/opt/anaconda3/lib/python3.7/site-packages/jupyterlab]()
[I 13:25:36.454 NotebookApp] JupyterLab application directory is [/opt/anaconda3/share/jupyter/lab]()
[I 13:25:36.456 NotebookApp] Serving notebooks from local directory: [/home/centos]()
[I 13:25:36.456 NotebookApp] The Jupyter Notebook is running at:
[I 13:25:36.457 NotebookApp] http://localhost:8888/?token=fb8ee2da13fd16670228cb93bfa839d95640907ff6b60f0e
[I 13:25:36.457 NotebookApp]  or http://127.0.0.1:8888/?token=fb8ee2da13fd16670228cb93bfa839d95640907ff6b60f0e
[I 13:25:36.457 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 13:25:36.460 NotebookApp] No web browser found: could not locate runnable browser.
[C 13:25:36.460 NotebookApp] 

The singularity way

Requirements

Openstack instance with singularity soft into ( cloud-config ?)

Connect to instance

$ ssh -i  ~/.ssh/os_user.pem ~/.ssh/os_user.pem centos@134.158.21.74

[centos@sing2 ~]$

Launch the notebook

Download the anaconda image from the syslab repo

[centos@sing2]$ singularity pull library://juanca/default/anaconda 
INFO:    Downloading library image
 1.42 GiB / 1.42 GiB [===============================] 100.00% 15.01 MiB/s 1m36s
INFO:    Container is trusted - run 'singularity key list' to list your trusted keys
INFO:    Download complete: anaconda_latest.sif

You just have to execute in command "jupyter Notebook" in singularity.

[centos@sing2]$ singularity exec --bind /tmp:/run/user anaconda_latest.sif jupyter notebook
[I 13:02:19.791 NotebookApp] Writing notebook server cookie secret to /home/centos/.local/share/jupyter/runtime/notebook_cookie_secret
[I 13:02:20.165 NotebookApp] JupyterLab extension loaded from /opt/anaconda3/lib/python3.7/site-packages/jupyterlab
[I 13:02:20.165 NotebookApp] JupyterLab application directory is /opt/anaconda3/share/jupyter/lab
[I 13:02:20.167 NotebookApp] Serving notebooks from local directory: /home/centos/test3
[I 13:02:20.167 NotebookApp] The Jupyter Notebook is running at:
[I 13:02:20.167 NotebookApp] http://localhost:8888/?token=326816ed79e41b916a7fc95818c101481d750d247713be25
[I 13:02:20.167 NotebookApp]  or http://127.0.0.1:8888/?token=326816ed79e41b916a7fc95818c101481d750d247713be25
[I 13:02:20.167 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 13:02:20.171 NotebookApp] No web browser found: could not locate runnable browser.
[C 13:02:20.171 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/centos/.local/share/jupyter/runtime/nbserver-18466-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=326816ed79e41b916a7fc95818c101481d750d247713be25
     or http://127.0.0.1:8888/?token=326816ed79e41b916a7fc95818c101481d750d247713be25

Access the Notebook

Both cases, you must forward the Jupyter Notebook port to a local port of your working machine.

$ ssh -i ~/.ssh/os_user.pem -N -L 8889:127.0.0.1:8888  centos@134.158.21.74

Once the link is established, you can connect to the Jupyter URL from your browser, take care to replace the port with the one configured in the tunnel.