Panduan memulai: Men-deploy kumpulan pekerja contoh ke Cloud Run
Halaman ini menunjukkan cara men-deploy container kumpulan pekerja contoh. Setelah di-deploy, kumpulan pekerja akan terus menulis pesan log.
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.
-
Make sure that you have the following role or roles on the project: Cloud Run Admin, 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.
-
Make sure that you have the following role or roles on the project: Cloud Run Admin, 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 Cloud Run:
Pilih Worker pools dari menu, lalu klik Deploy container untuk menampilkan formulir Create worker pools.
Klik Uji dengan container contoh.
Klik Create untuk men-deploy image ke Cloud Run. Tunggu hingga deployment selesai.
Klik tab Log untuk melihat log yang ditulis oleh kumpulan pekerja. Worker pool terus menulis pesan log
Cloud Run Worker Pool instance is running!
.Di konsol Google Cloud , buka Cloud Run:
Pilih Worker pools dari menu, lalu pilih worker pool yang ingin Anda hapus.
Klik Hapus.
- 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.
Deploy kumpulan pekerja
Untuk men-deploy container kumpulan pekerja contoh, ikuti langkah-langkah berikut:
Pembersihan
Untuk menghindari biaya tambahan pada akun Google Cloud Anda, hapus semua resource yang Anda deploy dengan panduan memulai ini.
Menghapus repositori Anda
Anda mungkin dikenai biaya untuk menyimpan image container di Artifact Registry. Untuk menghapus repositori Artifact Registry, ikuti langkah-langkah di Menghapus repositori dalam dokumentasi Artifact Registry.
Menghapus kumpulan pekerja
Worker pool contoh terus-menerus menulis log. Untuk menghentikan logging, ikuti salah satu langkah berikut untuk menghapus kumpulan pekerja:
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:
Langkah berikutnya
Untuk mengetahui informasi selengkapnya tentang kumpulan pekerja, lihat: