快速入门:将示例工作器池部署到 Cloud Run

本页面介绍了如何部署示例工作器池容器。部署后,工作器池会持续写入日志消息。

准备工作

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

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

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

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 选择项目。
    3. 点击 授予访问权限
    4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

    5. 选择角色列表中,选择一个角色。
    6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
    7. 点击 Save(保存)。
  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 (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. 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

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

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

    1. In the Google Cloud console, go to the IAM page.

      前往 IAM
    2. 选择项目。
    3. 点击 授予访问权限
    4. 新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。

    5. 选择角色列表中,选择一个角色。
    6. 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
    7. 点击 Save(保存)。
  8. 确保您已向服务身份授予 Service Account User 角色。默认情况下,服务身份是 Compute Engine 默认服务账号。

    授予角色

    如需授予服务身份资源的访问权限,请使用 gcloud iam service-accounts add-iam-policy-binding 命令,并将突出显示的变量替换为适当的值:

          gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_EMAIL \
              --member=user:PRINCIPAL \
              --role=roles/iam.serviceAccountUser
          

    替换以下内容:

    • SERVICE_ACCOUNT_EMAIL:您用作服务身份的服务账号邮箱,例如:
      • Compute Engine 默认服务账号:PROJECT_NUMBER-compute@developer.gserviceaccount.com
      • 您创建的服务账号:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com
    • PRINCIPAL:用户标识符。这通常是用于部署 Cloud Run 资源的 Google 账号电子邮件地址。
  9. 查看 Cloud Run 价格或使用价格计算器估算费用。
  10. 部署工作器池

    如需部署示例工作器池容器,请按以下步骤操作:

    1. 在 Google Cloud 控制台中,前往 Cloud Run:

      转到 Cloud Run

    2. 从菜单中选择工作器池,然后点击部署容器以显示创建工作器池表单。

    3. 点击使用示例容器进行测试

    4. 点击创建以将映像部署到 Cloud Run,然后等待部署完成。

    5. 点击日志标签页以查看工作器池写入的日志。工作器池会持续写入日志消息 Cloud Run Worker Pool instance is running!

    清理

    为避免您的 Google Cloud 账号产生额外费用,请删除您在本快速入门中部署的所有资源。

    删除仓库

    您可能需要支付将容器映像存储在 Artifact Registry 中而产生的相关费用。如需删除 Artifact Registry 仓库,请按照 Artifact Registry 文档中删除仓库的步骤操作。

    删除工作器池

    示例工作器池会持续写入日志。如需停止记录日志,请按以下步骤之一删除工作器池:

    1. 在 Google Cloud 控制台中,前往 Cloud Run:

      转到 Cloud Run

    2. 从菜单中选择工作器池,然后选择要删除的工作器池。

    3. 点击删除

    删除测试项目

    删除 Google Cloud 项目后,系统即会停止对该项目中的所有资源计费。如需释放项目中的所有 Google Cloud 资源,请按照以下步骤操作:

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    后续步骤

    如需详细了解工作器池,请参阅: