Menggunakan Managed Service for Apache Spark dengan notebook terkelola
Halaman ini menunjukkan cara menjalankan file notebook di Serverless Spark dalam instance notebook terkelola Vertex AI Workbench menggunakan Managed Service for Apache Spark.
Instance notebook terkelola Anda dapat mengirimkan kode file notebook untuk dijalankan pada layanan Managed Service 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 Managed Service for Apache Spark hanya berlaku saat workload dijalankan.
Persyaratan
Untuk menjalankan file notebook di Managed Service for Apache Spark, lihat persyaratan berikut.
Sesi Managed Service for 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 Managed Service for 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 Managed Service for Apache Spark Anda menggunakan jaringan Virtual Private Cloud (VPC) untuk menjalankan workload. Subnetwork VPC harus memenuhi persyaratan tertentu. Lihat persyaratan di Managed Service for Apache Spark untuk konfigurasi jaringan Spark.
Izin
Untuk memastikan bahwa akun layanan memiliki izin yang diperlukan untuk menjalankan file notebook di Managed Service for Apache Spark,
minta administrator Anda untuk memberikan
peran IAM Dataproc Editor (roles/dataproc.editor)
kepada akun layanan di project Anda.
Peran bawaan ini berisi izin yang diperlukan untuk menjalankan file notebook di Managed Service 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 Managed Service 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 bawaan lainnya.
Sebelum memulai
- Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
-
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 Managed Service for Apache Spark 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 Managed Service for Apache Spark 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 jaringan Managed Service for Apache Spark.
Buka JupyterLab
Di konsol Google Cloud , buka halaman Managed notebooks.
Di samping nama instance notebook terkelola, klik Open JupyterLab.
Memulai sesi Managed Service for Apache Spark
Untuk memulai sesi Managed Service for Apache Spark, selesaikan langkah-langkah berikut.
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 Managed Service for Apache Spark network configuration.
Klik Create.
File notebook baru akan terbuka. Sesi Managed Service for Apache Spark yang Anda buat adalah kernel yang menjalankan kode file notebook Anda.
Menjalankan kode Anda di Managed Service for Apache Spark dan kernel lainnya
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 Managed Service for Apache Spark, ubah kernel kembali ke kernel Managed Service for Apache Spark.
Menghentikan sesi Managed Service for Apache Spark
Anda dapat menghentikan sesi Managed Service for Apache Spark di antarmuka JupyterLab atau di konsol Google Cloud . Kode di file notebook Anda akan dipertahankan.
JupyterLab
Di JupyterLab, tutup file notebook yang dibuat saat Anda membuat sesi Managed Service for Apache Spark.
Pada dialog yang muncul, klik Hentikan sesi.
Konsol Google Cloud
Di konsol Google Cloud , buka halaman Sesi Dataproc.
Pilih sesi yang ingin Anda hentikan, lalu klik Hentikan.
Menghapus sesi Managed Service for Apache Spark Anda
Anda dapat menghapus sesi Managed Service for Apache Spark menggunakan konsol Google Cloud . Kode di file notebook Anda akan dipertahankan.
Di konsol Google Cloud , buka halaman Sesi Dataproc.
Pilih sesi yang ingin Anda hapus, lalu klik Delete.
Langkah berikutnya
- Pelajari lebih lanjut Managed Service for Apache Spark.