Cloud Run でジョブを作成して実行する
このページでは、サンプル コンテナを使用して Cloud Run でジョブを作成して実行する方法と、ジョブのログを表示する方法について説明します。
始める前に
- 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.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Run Admin API.
-
Make sure that you have the following role or roles on the project: 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.
IAM に移動 - プロジェクトを選択します。
- [ アクセスを許可] をクリックします。
-
[新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。
- [ロールを選択] リストでロールを選択します。
- 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
- [保存] をクリックします。
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Run Admin API.
-
Make sure that you have the following role or roles on the project: 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.
IAM に移動 - プロジェクトを選択します。
- [ アクセスを許可] をクリックします。
-
[新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。
- [ロールを選択] リストでロールを選択します。
- 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
- [保存] をクリックします。
-
-
サービス 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
- Compute Engine のデフォルトのサービス アカウント:
- PRINCIPAL: ユーザー ID。通常は、Google アカウントのメールアドレスです。
- SERVICE_ACCOUNT_EMAIL: サービス ID として使用しているサービス アカウントのメールアドレス。たとえば次のようなものです。
Google Cloud コンソールで、[Cloud Run] ページに移動します。
メニューから [ジョブ] を選択し、[コンテナをデプロイ] をクリックして、[ジョブの作成] フォームを開きます。
[サンプル コンテナでテスト] をクリックします。
[リージョン] プルダウン メニューで、ジョブを実行するリージョンを選択します。
[作成] をクリックしてジョブを作成します。
[ジョブ] ページで、作成したジョブをクリックして [ジョブの詳細] ページを開きます。
[実行] をクリックします。
ジョブのログは、ジョブ実行が開始するとすぐに利用できるようになります。[ログ] タブをクリックして、ジョブのログを表示します。
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
africa-south1
(ヨハネスブルグ)asia-east2
(香港)asia-northeast3
(ソウル、韓国)asia-southeast1
(シンガポール)asia-southeast2
(ジャカルタ)asia-south2
(デリー、インド)australia-southeast1
(シドニー)australia-southeast2
(メルボルン)europe-central2
(ワルシャワ、ポーランド)europe-west10
(ベルリン)低 CO2
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 のロケーション
Cloud Run はリージョナルです。つまり、Cloud Run サービスを実行するインフラストラクチャは特定のリージョンに配置され、そのリージョン内のすべてのゾーンで冗長的に利用できるように Google によって管理されます。
レイテンシ、可用性、耐久性の要件を満たしていることが、Cloud Run サービスを実行するリージョンを選択する際の主な判断材料になります。一般的には、ユーザーに最も近いリージョンを選択できますが、Cloud Run サービスで使用されている他の Google Cloudプロダクトのロケーションも考慮する必要があります。 Google Cloud プロダクトを複数のロケーションで使用すると、サービスのレイテンシだけでなく、コストにも影響を及ぼす可能性があります。
Cloud Run は、次のリージョンで利用できます。
ティア 1 料金を適用
ティア 2 料金を適用
Cloud Run サービスをすでに作成している場合は、Google Cloud コンソールの Cloud Run ダッシュボードにリージョンが表示されます。