Menggunakan Serverless for Apache Spark dengan notebook terkelola
Halaman ini menunjukkan cara menjalankan file notebook di Serverless Spark dalam instance notebook terkelola Vertex AI Workbench menggunakan Google Cloud Serverless for Apache Spark.
Instance notebook terkelola Anda dapat mengirimkan kode file notebook untuk dijalankan di layanan Serverless for Apache Spark. Layanan menjalankan kode pada infrastruktur komputasi terkelola yang otomatis menskalakan resource sesuai kebutuhan. Oleh karena itu, Anda tidak perlu menyediakan dan mengelola cluster Anda sendiri.
Biaya Serverless for Apache Spark hanya berlaku saat workload dijalankan.
Persyaratan
Untuk menjalankan file notebook di Serverless for Apache Spark, lihat persyaratan berikut.
Sesi Serverless untuk Apache Spark Anda harus berjalan di region yang sama dengan instance notebook terkelola Anda.
Batasan Wajibkan Login OS (
constraints/compute.requireOsLogin) tidak boleh diaktifkan untuk project Anda. Baca Mengelola Login OS di organisasi.Untuk menjalankan file notebook di Serverless untuk Apache Spark, Anda harus menyediakan akun layanan yang memiliki izin khusus. Anda dapat memberikan izin ini ke akun layanan default atau memberikan akun layanan kustom. Lihat bagian Izin di halaman ini.
Sesi Serverless for Apache Spark Anda menggunakan jaringan Virtual Private Cloud (VPC) untuk menjalankan workload. Subnetwork VPC harus memenuhi persyaratan tertentu. Lihat persyaratan di Google Cloud Serverless for Apache Spark untuk konfigurasi jaringan Spark.
Izin
Untuk memastikan bahwa akun layanan memiliki izin yang diperlukan untuk menjalankan file notebook di Serverless for Apache Spark,
minta administrator Anda untuk memberikan akun layanan
peran IAM Dataproc Editor (roles/dataproc.editor)
di project Anda.
Peran bawaan ini berisi izin yang diperlukan untuk menjalankan file notebook di Serverless for Apache Spark. Untuk melihat izin yang benar-benar diperlukan, perluas bagian Izin yang diperlukan:
Izin yang diperlukan
Izin berikut diperlukan untuk menjalankan file notebook di Serverless for Apache Spark:
-
dataproc.agents.create -
dataproc.agents.delete -
dataproc.agents.get -
dataproc.agents.update -
dataproc.session.create -
dataproc.sessions.get -
dataproc.sessions.list -
dataproc.sessions.terminate -
dataproc.sessions.delete -
dataproc.tasks.lease -
dataproc.tasks.listInvalidatedLeases -
dataproc.tasks.reportStatus
Administrator Anda mungkin juga dapat memberi akun layanan izin ini dengan peran khusus atau peran yang telah ditetapkan sebelumnya.
Sebelum memulai
- 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.
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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Notebooks, Vertex AI, and Dataproc 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Notebooks, Vertex AI, and Dataproc 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. - Jika belum melakukannya, konfigurasikan jaringan VPC yang memenuhi persyaratan yang tercantum dalam Konfigurasi jaringanGoogle Cloud Serverless for Apache Spark.
Di konsol Google Cloud , buka halaman Managed notebooks.
Di samping nama instance notebook terkelola, klik Open JupyterLab.
Di antarmuka JupyterLab instance notebook terkelola Anda, pilih tab Launcher, lalu pilih Serverless Spark. Jika tab Launcher tidak terbuka, pilih File > New Launcher untuk membukanya.
Dialog Create Serverless Spark session akan muncul.
Di kolom Nama sesi, masukkan nama untuk sesi Anda.
Di bagian Execution configuration, masukkan Service account yang ingin Anda gunakan. Jika Anda tidak memasukkan akun layanan, sesi Anda akan menggunakan akun layanan default Compute Engine.
Di bagian Network configuration, pilih Network dan Subnetwork dari jaringan yang memenuhi persyaratan yang tercantum dalam Google Cloud Serverless untuk konfigurasi jaringan Apache Spark.
Klik Buat.
File notebook baru akan terbuka. Sesi Serverless untuk Apache Spark yang Anda buat adalah kernel yang menjalankan kode file notebook Anda.
Tambahkan kode ke file notebook baru, dan jalankan kodenya.
Untuk menjalankan kode pada kernel lain, ubah kernel.
Jika Anda ingin menjalankan lagi kode pada sesi Serverless for Apache Spark, ubah kernel kembali ke kernel Serverless for Apache Spark.
Di JupyterLab, tutup file notebook yang dibuat saat Anda membuat sesi Serverless for Apache Spark.
Pada dialog yang muncul, klik Hentikan sesi.
Di konsol Google Cloud , buka halaman Sesi Dataproc.
Pilih sesi yang ingin Anda hentikan, lalu klik Hentikan.
Di konsol Google Cloud , buka halaman Sesi Dataproc.
Pilih sesi yang ingin Anda hapus, lalu klik Delete.
- Pelajari lebih lanjut Serverless for Apache Spark.
Buka JupyterLab
Memulai sesi Serverless for Apache Spark
Untuk memulai sesi Serverless for Apache Spark, selesaikan langkah-langkah berikut.
Jalankan kode Anda di Serverless for Apache Spark dan kernel lainnya
Menghentikan sesi Serverless for Apache Spark
Anda dapat menghentikan sesi Serverless untuk Apache Spark di antarmuka JupyterLab atau di konsol Google Cloud . Kode di file notebook Anda akan dipertahankan.
JupyterLab
Konsol Google Cloud
Menghapus sesi Serverless for Apache Spark Anda
Anda dapat menghapus sesi Serverless for Apache Spark menggunakan konsol Google Cloud . Kode di file notebook Anda akan dipertahankan.