Managed Service for Apache Spark の Spark 対応 Agent Platform Workbench インスタンスを作成する

このページでは、Managed Service for Apache Spark の Spark 対応 Gemini Enterprise Agent Platform Workbench インスタンスを作成する方法について説明します。また、Managed Service for Apache Spark JupyterLab 拡張機能の利点について説明し、Managed Service for Apache Spark と Managed Service for Apache Spark on Compute Engine で拡張機能を使用する方法についても概説します。

Managed Service for Apache Spark JupyterLab 拡張機能の概要

バージョン M113 以降の Agent Platform Workbench インスタンスには、Managed Service for Apache Spark JupyterLab 拡張機能がプリインストールされています。

Managed Service for Apache Spark JupyterLab 拡張機能で Apache Spark ノートブック ジョブを実行する方法は 2 つあります。1 つは Managed Service for Apache Spark クラスタを使用する方法、もう 1 つは Managed Service for Apache Spark を使用する方法です。

  • Managed Service for Apache Spark クラスタには豊富な機能があり、Spark が実行されるインフラストラクチャを制御できます。Spark クラスタのサイズと構成を選択することで環境のカスタマイズと制御を行うことができます。この方法は、複雑なワークロード、長時間実行ジョブ、きめ細かいリソース管理に最適です。
  • Managed Service for Apache Spark を使用する場合、インフラストラクチャを気にする必要はありません。Spark ジョブを送信すると、Google がリソースのプロビジョニング、スケーリング、最適化をバックグラウンドで処理します。データ サイエンスや ML のワークロードでは、このサーバーレス アプローチは費用対効果の高い選択肢となります。

どちらの方法でも、Spark をデータ処理と分析に使用できます。Managed Service for Apache Spark クラスタと Managed Service for Apache Spark のどちらを選択するかは、ワークロードの要件、必要な制御レベル、リソースの使用パターンによって異なります。

データ サイエンスと ML のワークロードに 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 は、BigQuery や Knowledge Catalog などの他の Google Cloud プロダクトと統合されます。

詳細については、Managed Service for Apache Spark のドキュメントをご覧ください。

始める前に

  1. Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  4. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

必要なロール

Managed Service for Apache Spark クラスタまたは Managed Service for Apache Spark クラスタでノートブック ファイルを実行するために必要な権限がサービス アカウントに付与されるように、サービス アカウントに次の IAM ロールを付与するよう管理者に依頼してください。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

これらの事前定義ロールには、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 インスタンスを作成する手順は次のとおりです。

  1. Google Cloud コンソールで [インスタンス] ページに移動します。

    [インスタンス] に移動

  2. [新規作成] をクリックします。

  3. [新しいインスタンス] ダイアログで、[詳細オプション] をクリックします。

  4. [インスタンスを作成] ダイアログの [詳細] セクションで、[Dataproc Serverless インタラクティブ セッションを有効にする] が選択されていることを確認します。

  5. [Workbench のタイプ] が [インスタンス] に設定されていることを確認します。

  6. [環境] セクションで、最新バージョンまたは M113 以上のバージョン番号を使用していることを確認します。

  7. [作成] をクリックします。

    Agent Platform Workbench はインスタンスを作成し、自動的に起動します。インスタンスを使用する準備が整うと、Agent Platform Workbench で [JupyterLab を開く] リンクが有効になります。

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 で拡張機能を使用する

Agent Platform Workbench インスタンスと同じリージョンおよびプロジェクトにある Managed Service for Apache Spark ランタイム テンプレートが、JupyterLab の [Launcher] タブの [Managed Service for Apache Spark Notebooks] セクションに表示されます。

ランタイム テンプレートを作成するには、Managed Service for Apache Spark ランタイム テンプレートを作成するをご覧ください。

新しいサーバーレス Spark ノートブックを開くには、ランタイム テンプレートをクリックします。リモート Spark カーネルが起動するまでに 1 分ほどかかります。カーネルが起動したら、コーディングを開始できます。

Compute Engine 上の Managed Service for Apache Spark で拡張機能を使用する

Managed Service for Apache Spark on Compute Engine Jupyter クラスタを作成した場合、[Launcher] タブに [Managed Service for Apache Spark Cluster Notebooks] セクションが表示されます。

そのリージョンとプロジェクトでアクセス可能な Jupyter 対応 Managed Service for Apache Spark クラスタごとに、4 つのカードが表示されます。

リージョンとプロジェクトを変更するには、次の操作を行います。

  1. [Settings] > [Cloud Managed Service for Apache Spark Settings] を選択します。

  2. [Setup Config] タブの [Project Info] で、[Project ID] と [Region] を変更して、[Save] をクリックします。

    これらの変更は、JupyterLab を再起動するまで有効になりません。

  3. JupyterLab を再起動するには、[File] > [Shut Down] を選択して、Agent Platform Workbench の [インスタンス] ページで [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 の 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 リージョンを変更できます。

テストアクセス

Managed Service for Apache Spark JupyterLab 拡張機能は、Agent Platform Workbench インスタンスでデフォルトで有効になっています。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 コマンドが失敗した場合は、次のことを確認します。

  1. DNS エントリが正しく構成されている。

  2. 同じプロジェクトで使用可能なクラスタがある(存在しない場合は作成する必要があります)。

  3. クラスタで コンポーネント ゲートウェイオプションの Jupyter コンポーネントの両方が有効になっている。

Managed Service for Apache Spark をオフにする

Agent Platform Workbench インスタンスは、デフォルトで Managed Service for Apache Spark が有効になった状態で作成されます。disable-mixer metadata キーを true に設定すると、Managed Service for Apache Spark を無効にして Agent Platform Workbench インスタンスを作成できます。

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 コマンドをご覧ください。

resource "google_workbench_instance" "default" {
  name     = "workbench-instance-example"
  location = "us-central1-a"

  gce_setup {
    machine_type = "n1-standard-1"
    vm_image {
      project = "cloud-notebooks-managed"
      family  = "workbench-instances"
    }
    metadata = {
      disable-mixer = "false"
    }
  }
}

トラブルシューティング

Managed Service for Apache Spark Spark が有効なインスタンスの作成に関連する問題を診断して解決するには、Agent Platform Workbench のトラブルシューティングをご覧ください。

次のステップ