Cloud Run でジョブを作成して実行する

このページでは、サンプル コンテナを使用して 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  4. Verify that billing is enabled for your Google Cloud project.

  5. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. 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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  8. Verify that billing is enabled for your Google Cloud project.

  9. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  10. Cloud Run の料金を確認するか、料金計算ツールで費用を見積もります。
  11. 必要なロール

    このクイックスタートを完了するために必要な権限を取得するには、管理者に次の IAM ロールを付与するよう依頼してください。

    ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

    必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

    ジョブを作成する

    ジョブを作成するには:

    1. Google Cloud コンソールで、[Cloud Run] ページに移動します。

      Cloud Run に移動

    2. Cloud Run ナビゲーション メニューから [ジョブ] を選択し、[コンテナをデプロイ] をクリックして、[ジョブの作成] フォームを開きます。

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

    4. [リージョン] プルダウン メニューで、ジョブを実行するリージョンを選択します。

    5. [作成] をクリックしてジョブを作成します。

    ジョブが作成され、実行できるようになります。

    ジョブの実行

    ジョブを作成したら、実行できます。

    1. [ジョブ] ページで、作成したジョブをクリックして [ジョブの詳細] ページを開きます。

    2. [実行] をクリックします。

    3. ジョブのログは、ジョブ実行が開始するとすぐに利用できるようになります。[ログ] タブをクリックして、ジョブのログを表示します。

    Cloud Run のロケーション

    Cloud Run はリージョナルです。つまり、Cloud Run サービスを実行するインフラストラクチャは特定のリージョンに配置され、そのリージョン内のすべてのゾーンで冗長的に利用できるように Google によって管理されます。

    レイテンシ、可用性、耐久性の要件を満たしていることが、Cloud Run サービスを実行するリージョンを選択する際の主な判断材料になります。一般的には、ユーザーに最も近いリージョンを選択できますが、Cloud Run サービスで使用されている他の Google Cloudプロダクトのロケーションも考慮する必要があります。 Google Cloud プロダクトを複数のロケーションで使用すると、サービスのレイテンシだけでなく、コストにも影響を及ぼす可能性があります。

    Cloud Run は、次のリージョンで利用できます。

    ティア 1 料金を適用

    • asia-east1(台湾)
    • asia-northeast1(東京)
    • asia-northeast2(大阪)
    • asia-south1(ムンバイ、インド)
    • europe-north1(フィンランド) リーフアイコン 低 CO2
    • europe-north2(ストックホルム) リーフアイコン 低 CO2
    • europe-southwest1(マドリッド) リーフアイコン 低 CO2
    • europe-west1(ベルギー) リーフアイコン 低 CO2
    • europe-west4(オランダ) リーフアイコン 低 CO2
    • europe-west8(ミラノ)
    • europe-west9(パリ) リーフアイコン 低 CO2
    • me-west1(テルアビブ)
    • northamerica-south1(メキシコ)
    • us-central1(アイオワ) リーフアイコン 低 CO2
    • us-east1(サウスカロライナ)
    • us-east4(北バージニア)
    • us-east5(コロンバス)
    • us-south1(ダラス) リーフアイコン 低 CO2
    • us-west1(オレゴン) リーフアイコン 低 CO2

    ティア 2 料金を適用

    • africa-south1(ヨハネスブルグ)
    • asia-east2(香港)
    • asia-northeast3(ソウル、韓国)
    • asia-southeast1(シンガポール)
    • asia-southeast2 (ジャカルタ)
    • asia-south2(デリー、インド)
    • australia-southeast1(シドニー)
    • australia-southeast2(メルボルン)
    • europe-central2(ワルシャワ、ポーランド)
    • europe-west10(ベルリン)
    • europe-west12(トリノ)
    • europe-west2(ロンドン、イギリス) リーフアイコン 低 CO2
    • europe-west3(フランクフルト、ドイツ)
    • europe-west6(チューリッヒ、スイス) リーフアイコン 低 CO2
    • me-central1(ドーハ)
    • me-central2(ダンマーム)
    • northamerica-northeast1(モントリオール) リーフアイコン 低 CO2
    • northamerica-northeast2(トロント) リーフアイコン 低 CO2
    • southamerica-east1(サンパウロ、ブラジル) リーフアイコン 低 CO2
    • southamerica-west1(サンティアゴ、チリ) リーフアイコン 低 CO2
    • us-west2(ロサンゼルス)
    • us-west3(ソルトレイクシティ)
    • us-west4(ラスベガス)

    Cloud Run サービスをすでに作成している場合は、Google Cloud コンソールの Cloud Run ダッシュボードにリージョンが表示されます。

    クリーンアップ

    Google Cloud アカウントで追加料金が発生しないようにするには、このクイックスタートでデプロイしたすべてのリソースを削除します。

    リポジトリを削除する

    Cloud Run では、ジョブの実行時間に対してのみ料金が発生します。ただし、コンテナ イメージを Artifact Registry に保存した場合にも料金が発生する可能性があります。Artifact Registry リポジトリを削除するには、Artifact Registry ドキュメントのリポジトリを削除するの手順を行います。

    ジョブを削除する

    Cloud Run ジョブでは、ジョブタスクの実行時にのみ料金が発生します。Cloud Run ジョブを削除するには、次のいずれかの操作を行います。

    コンソール

    ジョブを削除するには:

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

      Cloud Run に移動

    2. 削除するジョブをジョブリストで探し、そのチェックボックスをクリックして選択します。

    3. [削除] をクリックします。これにより、進行中のすべてのジョブ実行と実行中のすべてのコンテナ インスタンスが終了します。

    gcloud

    ジョブを削除するには、次のコマンドを実行します。

    gcloud run jobs delete JOB_NAME

    JOB_NAME は、ジョブ名に置き換えます。

    テスト プロジェクトを削除する

    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.

    次のステップ