Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Executar uma instância de notebooks gerenciado em um cluster do Dataproc
Nesta página, mostramos como executar o arquivo de notebook de uma instância de notebooks gerenciado em um cluster do Dataproc.
Antes de começar
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.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Para garantir que a conta de serviço tenha as permissões necessárias para executar um arquivo de notebook em um cluster do Dataproc sem servidor, peça ao administrador para conceder à conta de serviço os seguintes papéis do IAM:
Esses papéis predefinidos contêm
as permissões necessárias para executar um arquivo de notebook em um cluster do Dataproc sem servidor. Para conferir as permissões exatas
necessárias, expanda a seção Permissões necessárias:
Permissões necessárias
As seguintes permissões são necessárias para executar um arquivo de notebook em um cluster do Dataproc sem servidor:
Para executar o arquivo de notebook de uma instância de notebooks gerenciado em um cluster do Dataproc, o cluster precisa atender aos seguintes critérios:
É necessário ativar o gateway do componente do cluster.
Ao lado do nome da instância de notebooks gerenciados, clique em Abrir JupyterLab.
Executar um arquivo de notebook no cluster do Dataproc
É possível executar um arquivo de notebook no cluster do Dataproc em qualquer instância de notebooks gerenciados no mesmo projeto e região.
Executar um novo arquivo de notebook
Na interface do JupyterLab da instância de notebooks gerenciados, selecione Arquivo > Novo
> Notebook.
Os kernels disponíveis do cluster do Dataproc aparecem no menu Selecionar kernel, selecione o kernel que você quer usar e clique em Selecionar.
O novo arquivo do notebook será aberto.
Adicione o código ao novo arquivo do notebook e execute o código.
Para alterar o kernel que você quer usar depois de criar o arquivo de notebook, consulte a seção a seguir.
Executar um arquivo de notebook existente
Na interface do JupyterLab da instância de notebooks gerenciados, clique no botão folderNavegador de arquivos, navegue até o arquivo de notebook que você quer executar e abra-o.
Para abrir a caixa de diálogo Select Kernel, clique no nome do kernel do arquivo do notebook.
Por exemplo: Python (Local).
Para selecionar um kernel do cluster do Dataproc,
selecione um nome do kernel que inclua o nome do cluster ao final.
Por exemplo, um kernel do PySpark em um cluster do Dataproc
chamado mycluster é chamado de PySpark em meucluster.
Clique em Selecionar para fechar a caixa de diálogo.
Agora é possível executar o código do arquivo do notebook no cluster do Dataproc.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-18 UTC."],[],[],null,["# Run a managed notebooks instance on a Dataproc cluster\n======================================================\n\n\n| Vertex AI Workbench managed notebooks is\n| [deprecated](/vertex-ai/docs/deprecations). On\n| April 14, 2025, support for\n| managed notebooks will end and the ability to create managed notebooks instances\n| will be removed. Existing instances will continue to function\n| but patches, updates, and upgrades won't be available. To continue using\n| Vertex AI Workbench, we recommend that you\n| [migrate\n| your managed notebooks instances to Vertex AI Workbench instances](/vertex-ai/docs/workbench/managed/migrate-to-instances).\n\n\u003cbr /\u003e\n\nThis page shows you how to run a managed notebooks instance's\nnotebook file on a Dataproc cluster.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Notebooks and Dataproc APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=notebooks.googleapis.com,dataproc)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Notebooks and Dataproc APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=notebooks.googleapis.com,dataproc)\n\n1. If you haven't already, [create\n a managed notebooks instance](/vertex-ai/docs/workbench/managed/create-instance#create).\n\n### Required roles\n\n\nTo ensure that the service account has the necessary\npermissions to run a notebook file on a Dataproc Serverless cluster,\n\nask your administrator to grant the service account the\nfollowing IAM roles:\n\n| **Important:** You must grant these roles to the service account, *not* to your user account. Failure to grant the roles to the correct principal might result in permission errors.\n\n- [Dataproc Worker](/iam/docs/roles-permissions/dataproc#dataproc.worker) (`roles/dataproc.worker`) on your project\n- [Dataproc Editor](/iam/docs/roles-permissions/dataproc#dataproc.editor) (`roles/dataproc.editor`) on the cluster for the `dataproc.clusters.use` permission\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThese predefined roles contain\n\nthe permissions required to run a notebook file on a Dataproc Serverless cluster. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\n#### Required permissions\n\nThe following permissions are required to run a notebook file on a Dataproc Serverless cluster:\n\n- ` dataproc.agents.create `\n- ` dataproc.agents.delete `\n- ` dataproc.agents.get `\n- ` dataproc.agents.update `\n- ` dataproc.tasks.lease `\n- ` dataproc.tasks.listInvalidatedLeases `\n- ` dataproc.tasks.reportStatus `\n- ` dataproc.clusters.use`\n\n\nYour administrator might also be able to give the service account\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nCreate a Dataproc cluster\n-------------------------\n\nTo run a managed notebooks instance's notebook file\nin a Dataproc cluster, your cluster must meet the following\ncriteria:\n\n- The cluster's component gateway must be enabled.\n\n- The cluster must have\n the [Jupyter component](/dataproc/docs/concepts/components/jupyter).\n\n- The cluster must be in the same region as\n your managed notebooks instance.\n\nTo create your Dataproc cluster,\nenter the following command in either\n[Cloud Shell](https://console.cloud.google.com?cloudshell=true) or another\nenvironment where the [Google Cloud CLI](/sdk/docs) is installed. \n\n```bash\ngcloud dataproc clusters create CLUSTER_NAME\\\n --region=REGION \\\n --enable-component-gateway \\\n --optional-components=JUPYTER\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the Google Cloud location of\n your managed notebooks instance\n\n- \u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e: the name of your new\n cluster\n\nAfter a few minutes, your Dataproc cluster\nis available for use. [Learn more about creating Dataproc\nclusters](/dataproc/docs/guides/create-cluster).\n\nOpen JupyterLab\n---------------\n\n1. If you haven't already,\n [create\n a managed notebooks instance](/vertex-ai/docs/workbench/managed/create-instance#create) in the same region\n where your Dataproc cluster is.\n\n2. In the Google Cloud console, go to the **Managed notebooks** page.\n\n [Go to Managed notebooks](https://console.cloud.google.com/vertex-ai/workbench/managed)\n3. Next to your managed notebooks instance's name,\n click **Open JupyterLab**.\n\nRun a notebook file in your Dataproc cluster\n--------------------------------------------\n\nYou can run a notebook file in your Dataproc cluster\nfrom any managed notebooks instance in the same project and\nregion.\n\n### Run a new notebook file\n\n1. In your managed notebooks instance's JupyterLab interface,\n select **File \\\u003e\n New \\\u003e Notebook**.\n\n2. Your Dataproc cluster's available kernels appear in\n the **Select kernel** menu. Select the kernel that you want to use,\n and then click **Select**.\n\n Your new notebook file opens.\n3. Add code to your new notebook file, and run the code.\n\nTo change the kernel that you want to use\nafter you've created your notebook file, see the following section.\n\n### Run an existing notebook file\n\n1. In your managed notebooks instance's JupyterLab interface,\n click the\n folder **File Browser** button,\n navigate to the notebook file that you want to run, and open it.\n\n2. To open the **Select kernel** dialog, click the kernel name of your notebook\n file, for example: **Python (Local)**.\n\n3. To select a kernel from your Dataproc cluster,\n select a kernel name that includes your cluster name at the end of it.\n For example, a PySpark kernel on a Dataproc cluster\n named `mycluster` is named **PySpark on mycluster**.\n\n4. Click **Select** to close the dialog.\n\n You can now run your notebook file's code\n on the Dataproc cluster.\n\nWhat's next\n-----------\n\n- Learn more about [Dataproc](/dataproc/docs/concepts/overview)."]]