Membuat dan menjalankan tugas di Cloud Run
Halaman ini menunjukkan Anda cara membuat tugas di Cloud Run menggunakan container contoh, menjalankan tugas, dan melihat log untuk tugas tersebut.
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Run Admin API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Make sure that you have the following role or roles on the project: Cloud Run Developer, Logs Viewer
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Buka IAM - Pilih project.
- Klik Grant access.
-
Di kolom New principals, masukkan ID pengguna Anda. Biasanya berupa alamat email untuk Akun Google.
- Di daftar Select a role, pilih peran.
- Untuk memberikan peran tambahan, klik Tambahkan peran lain, lalu tambahkan setiap peran tambahan.
- Klik Simpan.
-
-
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Run Admin API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Make sure that you have the following role or roles on the project: Cloud Run Developer, Logs Viewer
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Buka IAM - Pilih project.
- Klik Grant access.
-
Di kolom New principals, masukkan ID pengguna Anda. Biasanya berupa alamat email untuk Akun Google.
- Di daftar Select a role, pilih peran.
- Untuk memberikan peran tambahan, klik Tambahkan peran lain, lalu tambahkan setiap peran tambahan.
- Klik Simpan.
-
-
Pastikan Anda memiliki peran Service Account User yang diberikan pada identitas layanan. Secara default, identitas layanan adalah akun layanan default Compute Engine.
Memberikan peran
Untuk memberikan akses pada resource identitas layanan, gunakan perintah
gcloud iam service-accounts add-iam-policy-binding
, dengan mengganti variabel yang ditandai dengan nilai yang sesuai:gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_EMAIL \ --member=user:PRINCIPAL \ --role=roles/iam.serviceAccountUser
Ganti kode berikut:
- SERVICE_ACCOUNT_EMAIL: alamat email akun layanan
yang Anda gunakan sebagai identitas layanan, seperti:
- Akun layanan default Compute Engine:
PROJECT_NUMBER-compute@
- Akun layanan yang Anda buat:
SERVICE_ACCOUNT_NAME@PROJECT_ID.
- Akun layanan default Compute Engine:
- PRINCIPAL: ID pengguna. Biasanya berupa alamat email Akun Google yang men-deploy resource Cloud Run.
- SERVICE_ACCOUNT_EMAIL: alamat email akun layanan
yang Anda gunakan sebagai identitas layanan, seperti:
- Tinjau harga Cloud Run atau perkirakan biaya dengan kalkulator harga.
Di konsol Google Cloud , buka halaman Cloud Run:
Pilih Jobs dari menu, lalu klik Deploy container untuk membuka formulir Create job.
Klik Uji dengan container contoh.
Di menu pull-down Region, pilih region tempat Anda ingin menjalankan tugas.
Klik Buat untuk membuat tugas.
Di tab Tugas, klik tugas yang baru saja Anda buat untuk membuka halaman Detail tugas.
Klik Jalankan.
Log untuk tugas tersedia segera setelah eksekusi tugas dimulai. Klik tab Logs untuk melihat log untuk tugas tersebut.
asia-east1
(Taiwan)asia-northeast1
(Tokyo)asia-northeast2
(Osaka)asia-south1
(Mumbai, India)europe-north1
(Finlandia)CO2 Rendah
europe-north2
(Stockholm)CO2 Rendah
europe-southwest1
(Madrid)CO2 Rendah
europe-west1
(Belgia)CO2 Rendah
europe-west4
(Belanda)CO2 Rendah
europe-west8
(Milan)europe-west9
(Paris)CO2 Rendah
me-west1
(Tel Aviv)northamerica-south1
(Meksiko)us-central1
(Iowa)CO2 Rendah
us-east1
(South Carolina)us-east4
(North Virginia)us-east5
(Columbus)us-south1
(Dallas)CO2 Rendah
us-west1
(Oregon)CO2 Rendah
africa-south1
(Johannesburg)asia-east2
(Hong Kong)asia-northeast3
(Seoul, Korea Selatan)asia-southeast1
(Singapura)asia-southeast2
(Jakarta)asia-south2
(Delhi, India)australia-southeast1
(Sydney)australia-southeast2
(Melbourne)europe-central2
(Warsawa, Polandia)europe-west10
(Berlin)CO2 Rendah
europe-west12
(Turin)europe-west2
(London, Inggris Raya)CO2 Rendah
europe-west3
(Frankfurt, Jerman)europe-west6
(Zurich, Swiss)CO2 Rendah
me-central1
(Doha)me-central2
(Dammam)northamerica-northeast1
(Montreal)CO2 Rendah
northamerica-northeast2
(Toronto)CO2 Rendah
southamerica-east1
(Sao Paulo, Brasil)CO2 Rendah
southamerica-west1
(Santiago, Cile)CO2 Rendah
us-west2
(Los Angeles)us-west3
(Salt Lake City)us-west4
(Las Vegas)Di konsol Google Cloud , buka Cloud Run:
Temukan tugas yang ingin Anda hapus dalam daftar tugas, lalu klik kotak centang tugas tersebut untuk memilihnya.
Klik Hapus. Tindakan ini akan menghentikan semua eksekusi tugas yang sedang berlangsung dan semua instance container yang sedang berjalan.
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Buat tugas
Untuk membuat tugas:
Tugas dibuat dan siap dijalankan.
Laksanakan tugas
Setelah Anda membuat tugas, Anda dapat menjalankannya:
Lokasi Cloud Run
Cloud Run bersifat regional, berarti infrastruktur yang
menjalankan layanan Cloud Run Anda terletak di region tertentu dan
dikelola oleh Google agar tersedia secara redundan di
semua zona dalam region tersebut.
Memenuhi persyaratan latensi, ketersediaan, atau ketahanan adalah faktor utama
untuk memilih region tempat layanan Cloud Run dijalankan.
Pada umumnya, Anda dapat memilih region yang paling dekat dengan pengguna Anda, tetapi Anda harus mempertimbangkan
lokasi produk Google Cloud
lainnya yang digunakan oleh layanan Cloud Run Anda.
Menggunakan Google Cloud produk secara bersamaan di beberapa lokasi dapat memengaruhi
latensi serta biaya layanan Anda.
Cloud Run tersedia di region berikut:
Tergantung harga Tingkat 1
Tergantung harga Tingkat 2
Jika sudah membuat layanan Cloud Run, Anda dapat melihat region di dasbor Cloud Run di Google Cloud konsol.
Pembersihan
Untuk menghindari biaya tambahan pada akun Google Cloud Anda, hapus semua resource yang Anda deploy dengan panduan memulai ini.
Menghapus repositori Anda
Cloud Run hanya mengenakan biaya untuk waktu eksekusi tugas Anda. Namun, Anda mungkin tetap dikenai biaya atas penyimpanan image container di Artifact Registry. Untuk menghapus repositori Artifact Registry, ikuti langkah-langkah di Menghapus repositori dalam dokumentasi Artifact Registry.
Menghapus tugas Anda
Tugas Cloud Run hanya menimbulkan biaya saat tugas pekerjaan sedang dieksekusi. Untuk menghapus tugas Cloud Run, ikuti salah satu langkah berikut:
Konsol
Untuk menghapus tugas:
gcloud
Untuk menghapus tugas, jalankan perintah berikut:
gcloud run jobs delete JOB_NAME
Ganti JOB_NAME
dengan nama tugas.
Menghapus project pengujian Anda
Menghapus project Google Cloud akan menghentikan penagihan untuk semua resource dalam project tersebut. Untuk melepaskan semua Google Cloud resource di project Anda, ikuti langkah-langkah berikut: