クイックスタート: サンプル ワーカープールを 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. 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. [新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。

    5. [ロールを選択] リストでロールを選択します。
    6. 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
    7. [保存] をクリックします。
  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    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. [新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。

    5. [ロールを選択] リストでロールを選択します。
    6. 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
    7. [保存] をクリックします。
  8. サービス ID にサービス アカウント ユーザーのロールが付与されていることを確認します。デフォルトでは、サービス ID は Compute Engine のデフォルトのサービス アカウントです。

    ロールを付与する

    サービス ID リソースに対するアクセス権を付与するには、gcloud iam service-accounts add-iam-policy-binding コマンドを使用します。ハイライト表示された変数は、適切な値に置き換えてください。

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

    次のように置き換えます。

    • SERVICE_ACCOUNT_EMAIL: サービス ID として使用しているサービス アカウントのメールアドレス。たとえば次のようなものです。
      • Compute Engine のデフォルトのサービス アカウント: PROJECT_NUMBER-compute@developer.gserviceaccount.com
      • 作成したサービス アカウント: SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com
    • PRINCIPAL: ユーザー ID。通常は、Google アカウントのメールアドレスです。
  9. ワーカープールをデプロイする

    サンプル ワーカープール コンテナをデプロイする手順は次のとおりです。

    1. Google Cloud コンソールで Cloud Run に移動します。

      Cloud Run に移動

    2. メニューから [ワーカープール] を選択し、[コンテナをデプロイ] をクリックして、[ワーカープールの作成] フォームを表示します。

    3. [サンプル コンテナでテスト] をクリックします。

    4. [作成] をクリックしてイメージを Cloud Run にデプロイし、デプロイの完了を待ちます。

    5. [ログ] タブをクリックして、ワーカープールによって書き込まれたログを表示します。ワーカープールは、ログメッセージ Cloud Run Worker Pool instance is running! を継続的に書き込みます。

    クリーンアップ

    サンプル ワーカープールはログを継続的に書き込みます。そのため、停止するにはワーカープールを削除する必要があります。

    ワーカープールを削除するには:

    1. Google Cloud コンソールで Cloud Run に移動します。

      Cloud Run に移動

    2. メニューから [ワーカープール] を選択し、削除するワーカープールを選択します。

    3. [削除] をクリックします。

    次のステップ

    ワーカープールの詳細については、以下をご覧ください。