Menjalankan instance notebook terkelola di cluster Managed Service for Apache Spark
Halaman ini menunjukkan cara menjalankan file notebook instance notebook terkelola di cluster Managed Service for Apache Spark.
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 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 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.
Peran yang diperlukan
Untuk memastikan bahwa akun layanan memiliki izin yang diperlukan untuk menjalankan file notebook di cluster Managed Service for Apache Spark, minta administrator Anda untuk memberikan peran IAM berikut kepada akun layanan:
-
Dataproc Worker (
roles/dataproc.worker) di project Anda -
Editor Dataproc (
roles/dataproc.editor) di cluster untuk izindataproc.clusters.use
Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.
Peran bawaan ini berisi izin yang diperlukan untuk menjalankan file notebook di cluster 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 cluster 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
Administrator Anda mungkin juga dapat memberi akun layanan izin ini dengan peran khusus atau peran bawaan lainnya.
Membuat cluster Managed Service untuk Apache Spark
Untuk menjalankan file notebook instance notebook terkelola di cluster Managed Service for Apache Spark, cluster Anda harus memenuhi kriteria berikut:
Gateway komponen cluster harus diaktifkan.
Cluster harus memiliki komponen Jupyter.
Cluster harus berada di region yang sama dengan instance notebook terkelola Anda.
Untuk membuat cluster Managed Service for Apache Spark, masukkan perintah berikut di Cloud Shell atau lingkungan lain tempat Google Cloud CLI diinstal.
gcloud dataproc clusters create CLUSTER_NAME\ --region=REGION \ --enable-component-gateway \ --optional-components=JUPYTER
Ganti kode berikut:
REGION: Google Cloud lokasi instance notebook terkelola AndaCLUSTER_NAME: nama cluster baru.
Setelah beberapa menit, cluster Managed Service for Apache Spark Anda tersedia untuk digunakan. Pelajari lebih lanjut cara membuat cluster Managed Service for Apache Spark.
Buka JupyterLab
Di konsol Google Cloud , buka halaman Managed notebooks.
Di samping nama instance notebook terkelola, klik Open JupyterLab.
Menjalankan file notebook di cluster Managed Service for Apache Spark Anda
Anda dapat menjalankan file notebook di cluster Managed Service for Apache Spark dari instance notebook terkelola mana pun dalam project dan region yang sama.
Menjalankan file notebook baru
Di antarmuka JupyterLab instance notebook terkelola Anda, pilih File > Baru > Notebook.
Kernel yang tersedia pada cluster Managed Service for Apache Spark Anda akan muncul di menu Pilih kernel. Pilih kernel yang ingin Anda gunakan, lalu klik Pilih.
File notebook baru akan terbuka.
Tambahkan kode ke file notebook baru, dan jalankan kodenya.
Untuk mengubah kernel yang ingin digunakan setelah membuat file notebook, lihat bagian berikut.
Menjalankan file notebook yang ada
Di antarmuka JupyterLab instance notebook terkelola Anda, klik tombol File Browser, pilih file notebook yang ingin dijalankan, lalu buka.
Untuk membuka dialog Pilih kernel, klik nama kernel file notebook Anda, misalnya: Python (Lokal).
Untuk memilih kernel dari cluster Managed Service for Apache Spark, pilih nama kernel yang menyertakan nama cluster Anda di bagian akhir. Misalnya, kernel PySpark di cluster Managed Service for Apache Spark bernama
myclusterdiberi nama PySpark di mycluster.Klik Pilih untuk menutup dialog.
Sekarang Anda dapat menjalankan kode file notebook di cluster Managed Service for Apache Spark.
Langkah berikutnya
- Pelajari lebih lanjut Managed Service for Apache Spark.