本頁面說明如何建立已啟用 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, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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, if any are not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.
必要的角色
為確保服務帳戶具備必要權限,可在 Managed Service for Apache Spark 叢集或 Managed Service for Apache Spark 叢集上執行 Notebook 檔案,請要求管理員向服務帳戶授予下列 IAM 角色:
- 專案中的 Dataproc 工作站 (
roles/dataproc.worker) - 叢集的 Dataproc 編輯者 (
roles/dataproc.editor) 角色,具備dataproc.clusters.use權限
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
這些預先定義的角色具備必要權限,可在 Managed Service for Apache Spark 叢集或 Managed Service for Apache Spark 叢集上執行筆記本檔案。如要查看確切的必要權限,請展開「Required permissions」(必要權限) 部分:
所需權限
如要在 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 控制台的「Instances」(執行個體) 頁面。
按一下「 建立新項目」。
在「New instance」對話方塊中,按一下「Advanced options」。
在「Create instance」(建立執行個體) 對話方塊的「Details」(詳細資料) 部分,確認已選取「Enable Dataproc Serverless Interactive Sessions」(啟用 Dataproc Serverless 互動式工作階段)。
確認「Workbench 類型」設為「執行個體」。
在「Environment」(環境) 區段中,確認您使用的是最新版本或
M113以上版本。點選「建立」。
Agent Platform Workbench 會建立執行個體,並自動啟動。執行個體可供使用時,Agent Platform Workbench 會啟用「Open JupyterLab」(開啟 JupyterLab) 連結。
開啟 JupyterLab
按一下執行個體名稱旁的「Open JupyterLab」(開啟 JupyterLab)。
瀏覽器會開啟 JupyterLab 的「Launcher」分頁。根據預設,其中包含「Managed Service for Apache Spark Notebooks」和「Managed Service for Apache Spark Jobs and Sessions」。如果所選專案和區域中有支援 Jupyter 的叢集,就會顯示「Managed Service for Apache Spark Cluster Notebooks」專區。
搭配使用擴充功能與 Managed Service for Apache Spark
如果 Managed Service for Apache Spark 執行階段範本與 Agent Platform Workbench 執行個體位於相同區域和專案,就會顯示在 JupyterLab「Launcher」(啟動器) 分頁的「Managed Service for Apache Spark Notebooks」部分。
如要建立執行階段範本,請參閱「建立 Managed Service for Apache Spark 執行階段範本」。
如要開啟新的無伺服器 Spark 筆記本,請點選執行階段範本。遠端 Spark 核心會在約一分鐘內啟動。核心啟動後,即可開始編寫程式碼。
搭配使用擴充功能與 Managed Service for Apache Spark on Compute Engine
如果您建立了 Managed Service for Apache Spark on Compute Engine Jupyter 叢集,「Launcher」(啟動器) 分頁會顯示「Managed Service for Apache Spark Cluster Notebooks」(Managed Service for Apache Spark 叢集 Notebook) 專區。
在該區域和專案中,您有權存取的每個 Jupyter 支援 Managed Service for Apache Spark 叢集,都會顯示四張資訊卡。
如要變更區域和專案,請按照下列步驟操作:
依序選取「Settings」(設定) > 「Cloud Managed Service for Apache Spark Settings」(Cloud Managed Service for Apache Spark 設定)。
在「Setup Config」(設定) 分頁的「Project Info」(專案資訊) 下方,變更「Project ID」(專案 ID) 和「Region」(區域),然後按一下「Save」(儲存)。
重新啟動 JupyterLab 後,這些變更才會生效。
如要重新啟動 JupyterLab,請依序選取「File」>「Shut Down」, 然後在 「Agent Platform Workbench instances」頁面中點選「Open JupyterLab」。
如要建立新的筆記本,請點選資訊卡。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) 是在本機執行的核心,會在執行個體的 VM 中執行。在啟用 Managed Service for Apache Spark 的 Agent Platform Workbench 執行個體上,筆記本會透過遠端核心在 Managed Service for Apache Spark 叢集上執行。遠端核心會在執行個體 VM 以外的服務上執行,因此您可以存取相同專案中的任何 Managed Service for Apache Spark 叢集。
根據預設,Agent Platform Workbench 會使用與執行個體位於相同區域的 Managed Service for Apache Spark 叢集,但只要在 Managed Service for Apache Spark 叢集上啟用元件閘道和選用的 Jupyter 元件,即可變更 Managed Service for Apache Spark 區域。
測試存取權
Agent Platform Workbench 執行個體預設會啟用 Managed Service for Apache Spark JupyterLab 擴充功能。如要測試 Managed Service for Apache Spark 的存取權,請將下列 curl 要求傳送至 kernels.googleusercontent.com 網域,檢查執行個體遠端核心的存取權:
curl --verbose -H "Authorization: Bearer $(gcloud auth print-access-token)" https://PROJECT_ID-dot-REGION.kernels.googleusercontent.com/api/kernelspecs | jq .
如果 curl 指令失敗,請確認下列事項:
DNS 項目設定正確。
相同專案中有可用的叢集 (如果沒有,則須建立一個)。
叢集已啟用元件閘道和選用 Jupyter 元件。
關閉 Managed Service for Apache Spark
建立 Agent Platform Workbench 執行個體時,預設會啟用 Managed Service for Apache Spark。如要建立關閉 Managed Service for Apache Spark 的 Agent Platform Workbench 執行個體,請將 disable-mixer metadata 鍵設為 true。
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-mixermetadata 鍵設為 false,啟用 Managed Service for Apache Spark。將 disable-mixer 中繼資料鍵設為 true,即可關閉 Managed Service for Apache Spark。
如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
疑難排解
如要診斷及解決建立 Managed Service for Apache Spark 執行個體 (已啟用 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」。
如要瞭解無伺服器 Spark,請參閱 GitHub 上的
serverless-spark-workshop。