本页面介绍了如何创建启用了 Spark 的 Managed Service for Apache Spark Gemini Enterprise Agent Platform Workbench 实例。本页面还介绍了 Managed Service for Apache Spark JupyterLab 扩展程序的优势,并概述了如何将该扩展程序与 Managed Service for Apache Spark 和 Compute Engine 上的 Managed Service for Apache Spark 搭配使用。
Managed Service for Apache Spark JupyterLab 扩展程序概览
从 M113 版及更高版本开始,Agent Platform Workbench 实例预安装了 Managed Service for Apache
Spark JupyterLab 扩展程序。
Managed Service for Apache Spark JupyterLab 扩展程序提供了两种运行 Apache Spark 笔记本作业的方式:Managed Service for Apache Spark 集群和 Managed Service for Apache Spark。
- Managed Service for Apache Spark 集群 包含一组丰富的功能,可控制 Spark 运行的基础架构。您可以选择 Spark 集群的大小和配置,从而 对您的环境进行自定义和控制。此方法非常适合复杂的工作负载、长时间运行的作业和精细的资源管理。
- Managed Service for Apache Spark 消除了对基础架构的担忧。您只需提交 Spark 作业, Google 会在后台处理资源的预配、伸缩和优化。这种无服务器方法为数据科学和机器学习工作负载提供了 经济实惠的方案。
无论选择哪一种方法,您都可以使用 Spark 进行数据处理 和分析。选择 Managed Service for Apache Spark 集群还是 Managed Service for Apache Spark 取决于您的特定 工作负载要求、所需的控制级别和资源使用模式。
使用 Managed Service for Apache Spark 处理数据科学和 机器学习工作负载的优势包括:
- 无需管理集群:您无需担心 预配、配置或管理 Spark 集群。这样可以节省 时间和资源。
- 自动扩缩:Managed Service for Apache Spark 会根据工作负载自动扩缩,因此您只需为使用的资源付费。
- 高性能:Managed Service for Apache Spark 针对性能进行了优化,并利用 Google Cloud'的基础架构。
- 与其他 Google Cloud 技术集成 : Managed Service for Apache Spark 与其他 Google Cloud 产品(例如 BigQuery 和 Knowledge Catalog)集成。
如需了解详情,请参阅 Managed Service for Apache Spark 文档。
准备工作
- 登录您的 Google Cloud 账号。如果您是新手 Google Cloud, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Cloud Resource Manager, Managed Service for Apache Spark, and Notebooks APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
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 role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
Enable the Cloud Resource Manager, Managed Service for Apache Spark, and Notebooks APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
所需的角色
如需确保服务帐号拥有在 Managed Service for Apache Spark 集群或 Managed Service for Apache Spark 集群上运行笔记本文件所需的权限,请让您的管理员为服务帐号授予以下 IAM 角色:
如果未能向正确的主账号授予这些角色,可能会导致权限错误。- Dataproc Worker (
roles/dataproc.worker) 针对您的项目的 - 针对拥有
dataproc.clusters.use权限的集群的 Dataproc Editor (roles/dataproc.editor)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
这些预定义角色包含 在 Managed Service for Apache Spark 集群或 Managed Service for Apache Spark 集群上运行笔记本文件所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
在 Managed Service for Apache Spark 集群或 Managed Service for Apache Spark 集群上运行笔记本文件需要以下权限:
-
dataproc.agents.create -
dataproc.agents.delete -
dataproc.agents.get -
dataproc.agents.update -
dataproc.tasks.lease -
dataproc.tasks.listInvalidatedLeases -
dataproc.tasks.reportStatus -
dataproc.clusters.use
您的管理员也可以使用自定义角色或其他预定义角色为服务帐号授予这些权限。
创建启用了 Managed Service for Apache Spark 的实例
如需创建启用了 Managed Service for Apache Spark 的 Agent Platform Workbench 实例,请执行以下操作:
在 Google Cloud 控制台中,前往实例页面。
点击 新建。
在新建实例对话框中,点击高级选项。
在创建实例对话框的详细信息部分中,确保选中启用 Dataproc Serverless Interactive 会话。
确保将 Workbench 类型设置为实例。
在环境部分中,确保您使用最新版本或编号为
M113或更高的版本。点击创建 。
Agent Platform Workbench 会创建实例并自动启动该实例。 当实例可供使用时,Agent Platform Workbench 会激活一个打开 JupyterLab 链接。
打开 JupyterLab
在实例名称旁边,点击打开 JupyterLab。
JupyterLab 启动器 标签页会在浏览器中打开。默认情况下,它包含 Managed Service for Apache Spark 笔记本 和 Managed Service for Apache Spark 作业和会话 部分。如果所选项目和区域中存在支持 Jupyter 的集群,则系统会显示一个名为 Managed Service for Apache Spark 集群笔记本 的部分。
将扩展程序与 Managed Service for Apache Spark 搭配使用
与 Agent Platform Workbench 实例位于同一区域和项目中的 Managed Service for Apache Spark 运行时模板显示在 JupyterLab 启动器 标签页的 Managed Service for Apache Spark 笔记本 部分中。
如需创建运行时模板,请参阅创建 Managed Service for Apache Spark 运行时模板。
如需打开新的 Serverless Spark 笔记本,请点击运行时模板。远程 Spark 内核大约需要一分钟才能启动。内核启动后,您就可以开始编写代码了。
将扩展程序与 Compute Engine 上的 Managed Service for Apache Spark 搭配使用
如果您创建了 Compute Engine 上的 Managed Service for Apache Spark Jupyter 集群, 则启动器标签页会有一个 Managed Service for Apache Spark 集群笔记本部分。
对于您有权访问该区域和项目中的每个支持 Jupyter 的 Managed Service for Apache Spark 集群,系统都会显示四个卡片。
如需更改区域和项目,请执行以下操作:
选择设置 > Cloud Managed Service for Apache Spark 设置。
在 Setup Config 标签页上的项目信息 下,更改 项目 ID 和 区域 ,然后点击保存 。
这些更改在您重启 JupyterLab 后才会生效。
如需重启 JupyterLab,请选择 文件 > 关停 ,然后 点击 打开 JupyterLab 页面上的 Agent Platform Workbench 实例 。
如需创建新笔记本,请点击卡片。Managed Service for Apache Spark 集群上的远程内核启动后,您可以开始编写代码,然后在集群上运行代码。
使用 gcloud CLI 和 API 管理实例上的 Managed Service for Apache Spark
本部分介绍了在 Agent Platform Workbench 实例上管理 Managed Service for Apache Spark 的方法。
更改 Managed Service for Apache Spark 集群的区域
Agent Platform Workbench 实例的默认内核(例如 Python 和 TensorFlow)是在实例的虚拟机中运行的本地内核。 在启用了 Spark 的 Managed Service for Apache Spark Agent Platform Workbench 实例上,您的笔记本通过远程内核在 Managed Service for Apache Spark 集群上运行。 远程内核在实例虚拟机之外的服务上运行,这让您可以访问同一项目中的任何 Managed Service for Apache Spark 集群。
默认情况下,Agent Platform Workbench 使用实例所在区域中的 Managed Service for Apache Spark 集群 ,但您可以更改 Managed Service for Apache Spark 区域,只要 Managed Service for Apache Spark 集群上启用了 组件网关和 可选的 Jupyter 组件 。
测试访问权限
默认情况下,Agent Platform Workbench 实例启用了 Managed Service for Apache Spark JupyterLab
扩展程序。如需测试对 Managed Service for Apache Spark 的访问权限,您可以向
kernels.googleusercontent.com 域名发送以下 c网址 请求,以检查对实例的远程内核的访问权限:
curl --verbose -H "Authorization: Bearer $(gcloud auth print-access-token)" https://PROJECT_ID-dot-REGION.kernels.googleusercontent.com/api/kernelspecs | jq .
如果 c网址 命令失败,请检查以确保:
您的 DNS 条目配置正确。
同一项目中有可用的集群(如果不存在,您需要创建一个)。
您的集群同时启用了 组件网关和 可选的 Jupyter 组件 。
关闭 Managed Service for Apache Spark
默认情况下,创建的 Agent Platform Workbench 实例启用了 Managed Service for Apache
Spark。您可以通过将 disable-mixer
metadata 键设置为 true,在创建 Agent Platform
Workbench 实例时关闭 Managed Service for Apache Spark。
gcloud workbench instances create INSTANCE_NAME --metadata=disable-mixer=true
启用 Managed Service for Apache Spark
您可以通过更新元数据值,在已停止的 Agent Platform Workbench 实例上启用 Managed Service for Apache Spark。
gcloud workbench instances update INSTANCE_NAME --metadata=disable-mixer=false
使用 Terraform 管理 Managed Service for Apache Spark
在 Terraform 上,Agent Platform Workbench 实例的 Managed Service for Apache Spark
使用元数据字段中的 disable-mixer 键进行管理。
将 disable-mixer
metadata 键设置为
false 可以开启 Managed Service for Apache Spark。将 disable-mixer 元数据键设置为
true 可以关闭 Managed Service for Apache Spark。
如需了解如何应用或移除 Terraform 配置,请参阅 基本 Terraform 命令。
问题排查
如需诊断和解决与创建 启用了 Spark 的 Managed Service for Apache Spark 实例相关的问题,请参阅排查 Agent Platform Workbench问题。
后续步骤
如需详细了解 Managed Service for Apache Spark JupyterLab 扩展程序,请参阅 使用 JupyterLab 扩展程序开发无服务器 Spark 工作负载。
如需详细了解 Managed Service for Apache Spark,请参阅 Managed Service for Apache Spark 文档
如需详细了解如何将 Spark 与 Google Cloud 产品和 服务搭配使用,请参阅 Spark on Google Cloud。
在 GitHub 上浏览可用的 Managed Service for Apache Spark 模板。
通过
serverless-spark-workshop上的 GitHub了解 Serverless Spark。阅读 Apache Spark 文档。