Menjalankan instance notebook terkelola di dalam cluster Dataproc

Halaman ini menunjukkan cara menjalankan file notebook instance notebook terkelola di cluster Dataproc.

Sebelum memulai

  1. 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.
  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 Dataproc 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 Dataproc 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

  8. Peran yang diperlukan

    Untuk memastikan bahwa akun layanan memiliki izin yang diperlukan untuk menjalankan file notebook di cluster Serverless 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 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 cluster Serverless 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 yang telah ditetapkan sebelumnya.

    Membuat cluster Dataproc

    Untuk menjalankan file notebook instance notebook terkelola di cluster Dataproc, 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 Dataproc, 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 Dataproc Anda tersedia untuk digunakan. Pelajari lebih lanjut cara membuat cluster Dataproc.

    Buka JupyterLab

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

      Buka Managed notebooks

    2. Di samping nama instance notebook terkelola, klik Buka JupyterLab.

    Menjalankan file notebook di cluster Dataproc Anda

    Anda dapat menjalankan file notebook di cluster Dataproc 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 Dataproc 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 Dataproc, pilih nama kernel yang menyertakan nama cluster Anda di bagian akhir. Misalnya, kernel PySpark di cluster Dataproc bernama mycluster diberi nama PySpark di mycluster.

    4. Klik Pilih untuk menutup dialog.

      Sekarang Anda dapat menjalankan kode file notebook di cluster Dataproc.

    Langkah berikutnya