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

  1. 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.
  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. Verify that billing is enabled for your Google Cloud project.

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

    Enable the APIs

  5. 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

  6. Verify that billing is enabled for your Google Cloud project.

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

    Enable the APIs

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:

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 Anda

  • CLUSTER_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

  1. Di konsol Google Cloud , buka halaman Managed notebooks.

    Buka Managed notebooks

  2. 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

  1. Di antarmuka JupyterLab instance notebook terkelola Anda, pilih File > Baru > Notebook.

  2. 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.

  3. 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

  1. Di antarmuka JupyterLab instance notebook terkelola Anda, klik tombol  File Browser, pilih file notebook yang ingin dijalankan, lalu buka.

  2. Untuk membuka dialog Pilih kernel, klik nama kernel file notebook Anda, misalnya: Python (Lokal).

  3. 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 mycluster diberi nama PySpark di mycluster.

  4. Klik Pilih untuk menutup dialog.

    Sekarang Anda dapat menjalankan kode file notebook di cluster Managed Service for Apache Spark.

Langkah berikutnya