快速入门:将示例工作器池部署到 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.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. 启用 Cloud Run Admin API:
    启用 Cloud Run Admin API
  7. 安装并初始化 gcloud CLI。
  8. 更新组件:
    gcloud components update

部署工作器池

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

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 运行以下命令:

    gcloud beta run worker-pools deploy example-worker-pool
      --image us-docker.pkg.dev/cloudrun/container/worker-pool:latest
      --region europe-west1
    您可以根据需要为工作器池使用任何名称或区域。本快速入门假设您使用的是名称 example-worker-pool 和区域 europe-west1

  3. 部署成功完成后,Cloud Run 会显示类似如下内容的消息:

    Worker pool [my-example-worker-pool] revision [my-example-worker-pool-REVISION] has been deployed

  4. 查看工作器池写入的日志。

    1. 在 Google Cloud 控制台中,前往 Cloud Run 页面。

      转到 Cloud Run

    2. 点击工作器池

    3. 点击工作器池列表中的相应工作器池。

    4. 点击日志标签页,以获取此工作器池的所有修订版本的容器日志。工作器池会持续写入日志消息 Cloud Run Worker Pool instance is running!

清理

示例工作器池会持续写入日志。因此,如需停止工作器池,您需要将其删除。

如需删除工作器池,请使用以下命令:

gcloud beta run worker-pools delete my-example-workerpool 
--region europe-west1

如果您在部署时使用了其他名称,请将 my-example-workerpool 替换为工作器池的名称;如果您在部署时使用了其他区域,请将 europe-west1 替换为您的区域。

后续步骤

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