Installazione ed esecuzione di un notebook Jupyter su un cluster Dataproc


Obiettivi

Questo tutorial mostra come installare il componente Jupyter su un nuovo cluster e poi connettersi all'interfaccia utente del blocco note Jupyter in esecuzione sul cluster dal browser locale utilizzando il gateway dei componenti di Dataproc.

Costi

In questo documento, utilizzi i seguenti componenti fatturabili di Google Cloud:

Per generare una stima dei costi in base all'utilizzo previsto, utilizza il calcolatore prezzi.

I nuovi Google Cloud utenti potrebbero avere diritto a una prova gratuita.

Prima di iniziare

Se non l'hai ancora fatto, crea un progetto e un bucket Cloud Storage. Google Cloud

  1. Configurazione del progetto

    1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
    2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Go to project selector

    3. Make sure that billing is enabled for your Google Cloud project.

    4. Enable the Dataproc, Compute Engine, and Cloud Storage APIs.

      Enable the APIs

    5. Install the Google Cloud CLI.

    6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    7. To initialize the gcloud CLI, run the following command:

      gcloud init
    8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Go to project selector

    9. Make sure that billing is enabled for your Google Cloud project.

    10. Enable the Dataproc, Compute Engine, and Cloud Storage APIs.

      Enable the APIs

    11. Install the Google Cloud CLI.

    12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    13. To initialize the gcloud CLI, run the following command:

      gcloud init
    14. Creazione di un bucket Cloud Storage nel tuo progetto per archiviare i blocchi note che crei in questo tutorial.

      1. In the Google Cloud console, go to the Cloud Storage Buckets page.

        Go to Buckets

      2. Click Create.
      3. On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
        1. In the Get started section, do the following:
          • Enter a globally unique name that meets the bucket naming requirements.
          • To add a bucket label, expand the Labels section (), click Add label, and specify a key and a value for your label.
        2. In the Choose where to store your data section, do the following:
          1. Select a Location type.
          2. Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
          3. To set up cross-bucket replication, select Add cross-bucket replication via Storage Transfer Service and follow these steps:

            Set up cross-bucket replication

            1. In the Bucket menu, select a bucket.
            2. In the Replication settings section, click Configure to configure settings for the replication job.

              The Configure cross-bucket replication pane appears.

              • To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
              • To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
              • Click Done.
        3. In the Choose how to store your data section, do the following:
          1. Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
          2. To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
        4. In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
        5. In the Choose how to protect object data section, do the following:
          • Select any of the options under Data protection that you want to set for your bucket.
            • To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
            • To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
            • To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
              • To enable Object Retention Lock, click the Enable object retention checkbox.
              • To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
          • To choose how your object data will be encrypted, expand the Data encryption section (), and select a Data encryption method.
      4. Click Create.
      5. I tuoi notebook verranno archiviati in Cloud Storage in gs://bucket-name/notebooks/jupyter.

Crea un cluster e installa il componente Jupyter

Crea un cluster con il componente Jupyter installato.

Apri le UI di Jupyter e JupyterLab

Fai clic sui link del gateway dei componenti della console nella console Google Cloud per aprire le UI di Jupyter Notebook o JupyterLab in esecuzione sul tuo cluster.Google Cloud

La directory di primo livello visualizzata dall'istanza Jupyter è una directory virtuale che ti consente di visualizzare i contenuti del bucket Cloud Storage o del file system locale. Puoi scegliere la posizione facendo clic sul link GCS per Cloud Storage o su Disco locale per il file system locale del nodo master nel cluster.

  1. Fai clic sul link GCS. La UI web del notebook Jupyter mostra i notebook archiviati nel bucket Cloud Storage, inclusi quelli che crei in questo tutorial.

Esegui la pulizia

Al termine del tutorial, puoi liberare spazio eliminando le risorse che hai creato in modo che non utilizzino più la quota e non generino addebiti. Le seguenti sezioni descrivono come eliminare o disattivare queste risorse.

Elimina il progetto

Il modo più semplice per eliminare la fatturazione è quello di eliminare il progetto creato per il tutorial.

Per eliminare il progetto:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Elimina il cluster

  • Per eliminare il cluster:
    gcloud dataproc clusters delete cluster-name \
        --region=${REGION}
    

Elimina il bucket

  • Per eliminare il bucket Cloud Storage creato nel passaggio 2 della sezione Prima di iniziare, inclusi i blocchi note archiviati nel bucket:
    gcloud storage rm gs://${BUCKET_NAME} --recursive
    

Passaggi successivi