Jupyter Notebook
GCP
Google Cloud Platform
cloud computing
data science

Keep Jupyter Notebook running on GCP

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Jupyter Notebooks, a staple for data scientists, allow for interactive exploration and development of code. However, a common challenge is keeping these notebooks active, especially when deployed on platforms like Google Cloud Platform (GCP). This article provides a comprehensive guide on maintaining an active Jupyter Notebook on GCP, ensuring seamless execution and accessibility.

Setting Up Jupyter on GCP

To run Jupyter Notebook on GCP, we need to deploy it on a virtual machine (VM) using Google Compute Engine (GCE). Here are the steps:

  1. Create a Google Cloud Project:
    • Go to the Google Cloud Console.
    • Create a new project.
  2. Enable Billing:
    • Make sure billing is activated for your project, as GCP services require this.
  3. Enable Compute Engine API:
    • Navigate to the "APIs & Services" menu and enable the Compute Engine API.
  4. Launch a Google Compute Engine VM:
    • Go to the "Compute Engine" section and click "Create Instance."
    • Choose an appropriate machine type (e.g., n1-standard-1) and an operating system (e.g., Ubuntu).
    • Configure firewall settings to allow HTTP and HTTPS traffic.
  5. SSH into the VM:
    • Use the SSH tool in GCP Console to open a terminal to your VM.

Installing and Configuring Jupyter Notebook

On your VM instance, perform the following:

  1. Install Jupyter Notebook:
    • Open the Jupyter configuration file located at ~/.jupyter/jupyter_notebook_config.py .
    • Locate the line #c.NotebookApp.password = '' and set a password hash.
    • Generate a password hash using the following in a Python shell:
    • Copy the generated hash into the config file.
    • Edit ~/.jupyter/jupyter_notebook_config.py to include:
    • Create a file named jupyter.service in /etc/systemd/system/ .
    • Place the following configuration in the file:
  • Use Tmux or Screen: These tools allow you to run processes in the background without being affected by session timeouts.
  • Increase Idle Timeout: Configure your GCP project’s network settings to increase the TCP idle timeout settings.
  • Auto SSH Key Renewal: Use Cloud Functions or cron jobs to ensure SSH keys don’t expire.

Course illustration
Course illustration

All Rights Reserved.