Launching Jupyterlab on DigitalOcean and Publish to Kyso

helena profile picKyle O'Shea

This is a short guide to setting up and running a Jupyterlab environment on a DigitalOcean droplet. We have recently made a cool new Jupyterlab extension that allows anyone to publish their Jupyter notebooks directly to the web as awesome data blogs from anywhere.

1. Set up Account or Login

Login to https://cloud.digitalocean.com or signup for a new account. Note that Digital Ocean is currently offering $100 free credit on signup!

2. Create a Project

A project on DO is a workspace within which you can spin up and connect to virtual machines. This option is on the left-hand side navbar.

3. Create a Droplet

DigitalOcean Droplet Page

In your project, click Get started with a Droplet. Select an image based on your preferred distribution (Ubuntu 16.04.4 x 64 in this case). Choose a droplet size based on your required number of CPUs and memory, as well as your datacenter.

DigitalOcean Image Selection

Now, you can also set a password for authentication, but we recommend adding SSH key authentication.

Click Add SSH Key and paste in your key. Note that you can generate a key in your SSH client with the following command:

ssh-keygen -t rsa -b 2048

And you can copy your ssh key to the clipboard with:

pbcopy ~/.ssh/id_rsa.pub

Once the key is added, you're almost finished. For this guide we only want to spin up a single server, so leave the setting at 1 droplet and click Create. You should see a screen that shows the progress of your personal server being created.

DigitalOcean Droplet Size

4. Configure Firewall Settings

DigitalOcean Setting Inbound Rules

Now we have to create firewall settings so that we can connect to our instance. Go to Networking on the left-hand-side navbar. Navigate toFirewalls and click Create Firewalls. Set the rules for incoming traffic as shown in the image below and add this to your droplet.

5. Connect to Instance

DigitalOcean Running Instance

Once the process is complete, hover over the IP address of your new server to copy for the remote machine. Assuming you are on a Mac, we are simply going to use the terminal to ssh into our server. The command is as follows:

ssh root@"server_ip_address"

Respond yes to the terminal prompt & you are now logged into your own personal server!

What you now have is a Linux server with root access with resources not bound by your laptop’s constraints, which you pay for by the hour. You will use ssh to remotely access the server and issue commands directly on that machine.

6. Set up Data Science Environment

Before we get gather our toolset, we should update our server's software with the following two commands:

apt-get update
apt-get install

Now, to set up our data science environment. We'll install & setup the latest Anaconda distribution:

wget https://repo.continuum.io/archive/Anaconda3-5.3.0-Linux-x86_64.sh
bash Anaconda3-5.3.0-Linux-x86_64.sh
source .bashrc

Create a separate directory for our notebooks and cd into it.

7. Launch Jupyterlab

Fire up Jupyter lab:

jupyter lab

You may get the following warning: Running as root is not recommended. Use --allow-root to bypass.

For this guide we will bypass this warning, but if you'd like to know more about adding users and granting administrative privileges so as not to be running commands from the root user, this guide explains it nicely. For now, though, we'll run:

jupyter lab --allow-root

8. Connect to your Jupyter Environment

Create a new terminal session and ssh into your remote machine again. We do this because our first session allows us to monitor the running session. From the client, SSH to the Jupyterlab environment:

ssh -L 8000:localhost:8888 root@"server_ip_address"

In your browser go to localhost:8000 and enter the token. That's it, you're in!

9. Install Kyso's Publish Extension

The next step is to download Kyso's very own Jupyterlab extension. You can take a look at our documentation on Github here. The prerequisites are Jupyterlab 0.34 (or later) and a Kyso account.

You can check your Jupyterlab version by running:

jupyter lab --version

To install the extension, run the following.

For Jupyter Lab 0.35:

jupyter labextension install @kyso/jupyterlab

For Jupyter Lab 0.34:

jupyter labextension install @kyso/jupyterlab@jupyterlab-0.34.9

Note that this install requires node 5 or later. If you encounter any issues such as ValueError: Please install nodejs 5+ and npm before continuing installation when installing the above run the following & then install the extension:

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs -y

Once installed, refresh the page & you will see the *Kyso* option in the top navbar. You are now able to publish awesome data blogs directly to Kyso from an AWS EC2 instance!

Kyso Publish Jupyterlab Extension