This is a short guide to setting up and running a Jupyterlab environment on an Google Cloud instance. 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.
If you don't already have a Google Cloud account, head on over to GCP and sign up for a free account (Google Cloud provides 300$ credit). Note that you will have to enter your payment information and verify your account for this step.
If you do already have an account and haven't already activated your free trial, there should be an info bar at the top of your dashboard with a link to do just that. Once you're all set up, navivgate over to the console.
Click on the 3 dots at the top left of the screen and create a new project. Note that you can also use an existing project.
Ok, now we need to create our virtual machine. Back on the console dashboard, click on the 3 lines in upper left corner to reveal the left-hand side navbar.
Go to VM Instances under VM Instances.
Now we have to create the instance. Hit Create.
Time to configure our instance. Name the instance. Google's Compute Engine (GCE) provides various type of VM, with various CPU types, operating system and memory. Also, be sure to choose the right zone. Click here for details on the different zones. If you click on Customize, you will be able to find options for using GPUs.
We've also set some initial firewall rules above for access to the remote server, HTTP & HTTPS to allow specific network traffic for when we connect to the Jupyerlab App.
Now click on Create and your instance is ready to go! Note that this may take a minute or two. The green indicates that our instance is active. Be careful with this, as your account will continue to be charged as long as the instance is active, regardless of whether or not it is in use.
Before we go to use our VM, it's a good thing to confirm the connection. First of all, check that the IP address is static. Click on the 3 dots on the left-hand side of your instance on the VM Instances page.
Click View network details and then External IP Addresses on left-hand side toolbar of the next page. You will see the ip address we set in the last step. Ensure that the Type is static. If not, change it.
Secondly, we need to set the Firewall rules for incoming traffic, necessary for launching and connecting to Jupyterlab on the instance. On the Network Interface Details page, go to Firewall Rules (on left_hand side) and click Create Firewall Rule (top of page).
Name your firewall rule and descriptions. Under protocols and ports you can choose any port range. Leave all other settings as the defaults. When ready click on the create button. See the image below for the way I've configured it.
Back on the VM Instances page, click on SSH to connect to the remote server. This will open a command window. You are now inside the VM. Alternatively you can can ssh into the instance from another ssh client. For this guide, we'll stick to the simpler option.
Before we get gather our toolset, we should update our server's software with the following two commands:
Now, let's get the latest Anaconda build for linux. Enter:
to download the build. Now execute the installer:
Notice: If you see the warning bzip2 does not appear to be installed, this may cause problems below, this process may fail. If so, please execute the following command below, before proceeding:
And follow the on-screen instructions. The defaults should work fine, but make sure you answer yes to the last question about prepending the install location to PATH.
To make use of Anaconda right away, source your bashrc:
If the installer doesn't allow you to set the Anaconda3 install location to PATH in your /home/"username"/.bashrc you can set it manually:
Now let's launch our app!
Make a separate folder for our notebooks and cd into that directory:
It’s time to get the Jupyter Lab environment going. Initiate Jupyterlab in your notebooks directory with the following command:
which is the source and port I set earlier when configuring the firewall rules.
You should see some script in the VM terminal that shows the Jupyter environment is running:
Open a brower on your local machine, and in the address bar enter:
where xx.xxx.xx.xxx is the static IP address of your VM, and 8000 is the port the notebook is running on. So there you have it — a fully functioning Jupyter Lab setup on your local browser, but operating on a remote VM.
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:
To install the extension, run the following.
For Jupyter Lab 0.35:
For Jupyter Lab 0.34:
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:
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 Google Cloud!