本页面介绍了如何创建 Serverless for Apache Spark 交互式会话和会话模板。会话模板可用于根据会话模板配置创建多个互动式会话。
创建交互式会话
您可以使用 Google Cloud CLI 或 Dataproc API 创建 Serverless for Apache Spark 交互式会话。
gcloud
您可以使用 gcloud beta dataproc sessions create command SESSION_NAME
创建 Serverless for Apache Spark 交互式会话。
gcloud beta dataproc sessions create spark SESSION_ID \ --location=REGION \ optional flags ...
替换或添加以下内容:
SESSION_ID:必填。会话的 ID。
REGION:必填。用于放置会话的可用区域。
--version
: 可选。受支持的 Spark 运行时版本。 如果您未使用此标志指定版本,则系统会使用当前的默认 Spark 运行时版本。--container-image
:可选。用于会话的自定义容器映像。--property
: 可选。会话的一个或多个以英文逗号分隔的 Spark 属性。--service-account
: 可选。要用于会话的服务账号。如果未指定,则使用 Compute Engine 默认服务账号。--subnet
: 可选。会话区域中子网的名称。如果未指定,无服务器版 Apache Spark 会使用会话区域中的default
子网。Serverless for Apache Spark 会在子网中启用专用 Google 访问通道 (PGA)。如需了解网络连接要求,请参阅 Google Cloud Serverless for Apache Spark 网络配置。
REST
您可以使用 Dataproc sessions.create
API 创建 Serverless for Apache Spark 交互式会话。
注意:
name
: 必需。会话名称。version
: 可选。会话支持的任何 Spark 运行时版本。如果您未指定版本,则使用当前的默认版本。containerImage
: 可选。用于会话的自定义容器映像。properties
: 可选。从会话属性名称到值的映射。请参阅 Spark 属性。serviceAccount
: 可选。用于运行会话的服务账号。如果未指定,则使用 Compute Engine 默认服务账号。subnetworkUri
: 可选。会话区域中子网的名称。如果未指定,无服务器版 Apache Spark 会使用会话区域中的default
子网。Serverless for Apache Spark 会在子网中启用专用 Google 访问通道 (PGA)。如需了解网络连接要求,请参阅 Google Cloud Serverless for Apache Spark 网络配置。
创建会话模板
Serverless for Apache Spark 会话模板用于定义创建一项或多项 Serverless for Apache Spark 交互式会话的配置设置。您可以使用 Google Cloud 控制台、gcloud CLI 或 Dataproc API 为 Jupyter 或 Spark Connect 会话创建 Serverless for Apache Spark 会话模板。
控制台
如需使用 Google Cloud 控制台创建 Serverless for Apache Spark 会话模板,请完成以下步骤:
在 Google Cloud 控制台中,前往会话模板页面。
- 点击创建。
在创建会话模板页面中,输入或确认模板配置设置。请注意以下几点:
- 模板运行时 ID:必需。接受默认 ID(名称)或指定模板运行时名称。
- 地区:必需。接受默认区域,或为模板会话指定可用区域。
- 运行时版本:可选。可选择的会话运行时对应于 Serverless for Apache Spark 运行时版本。
- BigQuery Studio 笔记本会话要求:如果您要创建用于 BigQuery Studio 笔记本 Spark Connect 会话的模板,则必须使用 Spark 运行时版本 2.3 及更高版本。
- 模板配置类型:必需。选择类型。如果您选择
Jupyter
,请指定显示名称并选择 Jupyter 内核类型。 另请参阅在 Serverless for Apache Spark 上启动 Jupyter 笔记本。- BigQuery Studio 笔记本会话要求: BigQuery Studio 笔记本会话必须指定 Spark Connect 作为模板配置类型。
- 服务账号:可选。用于运行模板化会话的服务账号。如果未指定,则使用 Compute Engine 默认服务账号。
- 自定义容器映像:可选。用于模板化会话的自定义容器映像。
- 属性:可选。点击添加项目,为模板化会话设置各项属性。如需了解详情,请参阅 Spark 属性。
- 网络配置: * 必需。选择会话区域中的子网。Serverless for Apache Spark 会在指定的子网中启用专用 Google 访问通道 (PGA)。如需了解网络连接要求,请参阅 Google Cloud Serverless for Apache Spark 网络配置。
点击提交以创建会话模板。
gcloud
您无法使用 gcloud CLI 直接创建 Serverless for Apache Spark 会话模板,但可以使用 gcloud beta dataproc session-templates import
命令导入现有会话模板。您可以修改导入的模板,然后使用 gcloud beta dataproc session-templates export
命令将其导出。
REST
您可以使用 Dataproc sessionTemplates.create
API 创建 Serverless for Apache Spark 会话模板。
注意:
name
: 必需。会话模板名称。version
: 可选。任何受支持的 Spark 运行时版本,适用于模板化会话。如果您未指定版本,则系统会使用默认版本。- BigQuery Studio 笔记本会话要求:如果您要创建用于 BigQuery Studio 笔记本 Spark Connect 会话的模板,则必须使用 Spark 运行时版本 2.3 及更高版本。
sessionConfig
:指定jupyter_session
或spark_connect_session
。如果您指定jupyter_session
,还需指定JupyterConfig.display_name
和JupyterConfig.kernel
。 另请参阅在 Serverless for Apache Spark 上启动 Jupyter 笔记本。- BigQuery Studio 笔记本会话要求: BigQuery Studio 笔记本会话必须指定 Spark Connect 作为模板配置类型。
containerImage
: 可选。用于模板化会话的自定义容器映像。properties
: 可选。从会话属性名称到值的映射。请参阅 Spark 属性。serviceAccount
: 可选。用于运行模板化会话的服务账号。如果未指定,则使用 Compute Engine 默认服务账号。subnetworkUri
: 可选。会话区域中子网的名称。如果未指定,无服务器版 Apache Spark 会使用会话区域中的default
子网。Serverless for Apache Spark 会在子网中启用专用 Google 访问通道 (PGA)。如需了解网络连接要求,请参阅 Google Cloud Serverless for Apache Spark 网络配置。