Instale e execute um bloco de notas do Jupyter num cluster do Dataproc

Objetivos

Este tutorial mostra como instalar o componente Jupyter do Dataproc num novo cluster e, em seguida, ligar-se à IU do bloco de notas Jupyter em execução no cluster a partir do seu navegador local através do Component Gateway do Dataproc.

Custos

Neste documento, usa os seguintes componentes faturáveis do Google Cloud:

Para gerar uma estimativa de custos com base na sua utilização projetada, use a calculadora de preços.

Os novos Google Cloud utilizadores podem ser elegíveis para uma avaliação gratuita.

Antes de começar

Se ainda não o fez, crie um Google Cloud projeto e um contentor do Cloud Storage.

  1. Configurar o seu projeto

    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.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

      Go to project selector

    3. Verify that billing is enabled for your Google Cloud project.

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

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the APIs

    5. Install the Google Cloud CLI.

    6. Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

    7. Para inicializar a CLI gcloud, execute o seguinte comando:

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

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

      Go to project selector

    9. Verify that billing is enabled for your Google Cloud project.

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

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the APIs

    11. Install the Google Cloud CLI.

    12. Se estiver a usar um fornecedor de identidade (IdP) externo, tem primeiro de iniciar sessão na CLI gcloud com a sua identidade federada.

    13. Para inicializar a CLI gcloud, execute o seguinte comando:

      gcloud init
    14. Criar um contentor do Cloud Storage no seu projeto para armazenar todos os blocos de notas que criar neste 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. Os seus notebooks são armazenados no Cloud Storage em gs://bucket-name/notebooks/jupyter.

    15. Crie um cluster e instale o componente Jupyter

      Crie um cluster com o componente Jupyter instalado.

      Abra as IU do Jupyter e JupyterLab

      Clique nos Google Cloud links do gateway de componentes da consola na Google Cloud consola para abrir os UIs do Jupyter Notebook ou do JupyterLab em execução no

      O diretório de nível superior apresentado pela sua instância do Jupyter é um diretório virtual que lhe permite ver o conteúdo do seu contentor do Cloud Storage ou do seu sistema de ficheiros local. Pode escolher a localização clicando no link GCS para o Cloud Storage ou em Disco local para o sistema de ficheiros local do nó principal no cluster.

      1. Clique no link GCS. A IU Web do bloco de notas do Jupyter apresenta os blocos de notas armazenados no seu contentor do Cloud Storage, incluindo os blocos de notas que criar neste tutorial.

      Limpar

      Depois de concluir o tutorial, pode limpar os recursos que criou para que deixem de usar a quota e incorrer em custos. As secções seguintes descrevem como eliminar ou desativar estes recursos.

      Elimine o projeto

      A forma mais fácil de eliminar a faturação é eliminar o projeto que criou para o tutorial.

      Para eliminar o projeto:

      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.

      Elimine o cluster

      • Para eliminar o cluster:
        gcloud dataproc clusters delete cluster-name \
            --region=${REGION}
        

      Elimine o contentor

      • Para eliminar o contentor do Cloud Storage que criou no passo 2 da secção Antes de começar, incluindo os blocos de notas armazenados no contentor:
        gcloud storage rm gs://${BUCKET_NAME} --recursive
        

      O que se segue?