TrainSet Academy

Running Jupyter Notebooks on Google Cloud
Part 1: Setting up the Google Project and Compute Engine Instance

Step 1 : Create a free account in Google Cloud with 300$ credit. For this step, you will have to put your payment information and verify your account. It’s the most simple step. If you fail this step, close your laptop and think where you are going in life.
Create a new project. Step 2 : You can either use an existing Google Cloud project or create a new one over here.

#

Step 3 : Create a VM instance. Once you created and/or selected a project

Click on the three lines on the upper left corner, then go to Compute Engine > VM instances to create a new GCE instance here.

#

Step 3 : Create a VM instance. Once you created and/or selected a project

I selected europe-west2 as the region but any region/zone will do for this tutorial. Compute Engine also allows you to change and customize the number of CPU cores, memory, GPUs, and boot disk.

#

To follow along the tutorial, select the g1-small (or a larger) instance, change the boot disk to Ubuntu 18.04 LTS and set the Firewall settings to allow HTTP traffic. Pricing might differ across regions but this particular configuration got me a monthly estimate cost of $17.04.

Now click on ‘Create’ and your instance is ready! It might take a few minutes to boot up the VM instance once you click create

Step 4 : Make external IP address as static By default, the external IP address is dynamic and we need to make it static to make our life easier. Click on the three horizontal lines on top left and then under networking, click on VPC network and then External IP addresses.

#

Change the type from Ephemeral to Static.

#

Step 5 : Create a Firewall rule. We enabled HTTP traffic for our GCE instance but there is one more thing we need to do. Our Flask app will be running on port 5000 and Google Cloud, by default, doesn’t listen to port 5000. The default network in the project comes with default firewall rules “default-allow-http” and “default-allow-https” to allow traffic on port 80 and 443.

We need to head over to VPC network > Firewall rules and create a new firewall rule to accept incoming connections and requests on the port our app will be running on.

#

Click Create a firewall rule and configure the settings as shown below. Make sure to add http-server to target tags, 0.0.0.0/0 to source IP ranges and set 5000 as the specified port.

#

Step 6 : Start your VM instance Now start your VM instance. When you see the green tick click on SSH. This will open a command window and now you are inside the VM.

When you have a green tick on your VM instance, click on the three vertical dots on the right side of your vm and press start to start the VM. IMPORTANT DON’T FORGET TO STOP YOUR GPU INSTANCE AFTER YOU ARE DONE BY CLICKING ON THE THREE DOTS ON THE IMAGE ABOVE AND SELECTING STOP. OTHERWISE GCP WILL KEEP CHARGING YOU ON AN HOURLY BASIS.

Part 2: Install Jupyter notebook and other packages

In your SSH terminal, enter:

              wget http://repo.continuum.io/archive/Anaconda3-4.0.0-Linux-x86_64.sh
              bash Anaconda3-4.0.0-Linux-x86_64.sh
        

Answer yes to the last question about prepending the install location to PATH. To make use of Anaconda right away, source your bashrc:

          source ~/.bashrc
        

Now, install other softwares :

          pip install tensorflow
          pip install keras
        

Set up the VM server. Open up a SSH session to your VM. Check if you have a Jupyter configuration file:

          ls ~/.jupyter/jupyter_notebook_config.py
        

If it doesn’t exist, create one:

          jupyter notebook --generate-config
        

We’re going to add a few lines to your Jupyter configuration file; the file is plain text so, you can do this via your favorite editor (e.g., vim, emacs). Make sure you replace the port number with the one you allowed firewall access to in step 5 of Part 1.

          c = get_config()
          c.NotebookApp.ip = '*'
          c.NotebookApp.open_browser = False
          c.NotebookApp.port =
        

It should look something like this :

#

Launching Jupyter Notebook. To run the jupyter notebook, just type the following command in the ssh window you are in :

          jupyter-notebook --no-browser --port=5000
        

Launching Jupyter Notebook. To run the jupyter notebook, just type the following command in the ssh window you are in :

          http://<External Static IP Address>:<Port Number>
        

where, external ip address is the ip address which we made static and port number is the one which we allowed firewall access to. Congratulations!

#

You successfully installed jupyter notebook on GCP!

Andrew Wolf

Written by Andrew Wolf

Apr 25, 2020

up