このページでは、予約に関する推奨事項を使用してアイドル状態のオンデマンド予約を特定して削除する方法について説明します。この目的は、使用していないリソースに対する料金請求を防ぐことです。
- 予約に関する推奨事項がどのように Compute Engine によって生成されるかについては、アイドル状態の予約と十分に活用されていない予約の検出の仕組みをご覧ください。
- 受け取る推奨事項の数を増やす、または減らすように予約 Recommender を構成する方法については、アイドル状態の予約に関する推奨事項を構成するまたは使用率が低い予約に関する推奨事項を構成するをご覧ください。
始める前に
- 制限事項を参照して、アイドル状態の予約に関する推奨事項がご自身の予約でサポートされているかどうかを確認してください。
-
まだ設定していない場合は、認証を設定します。認証とは、Google Cloud サービスと API にアクセスするために ID を確認するプロセスです。ローカル開発環境からコードまたはサンプルを実行するには、次のように Compute Engine に対する認証を行います。
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
REST
このページの REST API サンプルをローカル開発環境で使用するには、gcloud CLI に指定した認証情報を使用します。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
詳細については、 Google Cloud 認証ドキュメントの REST を使用して認証するをご覧ください。
-
アイドル状態の予約に関する推奨事項を表示する
アイドル状態の予約に関する推奨事項を表示するには、次のいずれかの方法を使用します。
このタスクに必要な権限
このタスクを行うには、次の権限が必要です。
- プロジェクトに対する
recommender.computeIdleResourceRecommendations.list
次のいずれかの方法でこのタスクを完了します。
Google Cloud コンソールで、FinOps ハブに移動します。
アイドル状態の予約に関する推奨事項を表示するには、gcloud recommender recommendations list
コマンドを --recommender=google.compute.IdleResourceRecommender
フラグとともに使用します。
gcloud recommender recommendations list \ --location=ZONE \ --recommender=google.compute.IdleResourceRecommender \ --format=yaml \ --project=PROJECT_ID
次のように置き換えます。
ZONE
は、推奨事項を参照したい予約が存在するゾーンに置き換えます。PROJECT_ID
はプロジェクトの ID に置き換えます。
次に例を示します。
gcloud recommender recommendations list \ --location=us-central1-c \ --recommender=google.compute.IdleResourceRecommender \ --format=yaml \ --project=my-project
ロケーションにアイドル状態の VM がない場合、レスポンスは空になります。それ以外の場合、レスポンスには推奨事項ごとに次のフィールドが含まれます。
operationGroups
: 推奨事項を適用する際に実行できるオペレーションのグループdescription
: 推奨事項の説明
---
associatedInsights:
- insight: projects/953727763714/locations/us-central1-f/insightTypes/google.compute.IdleResourceInsight/insights/ecf77776-4a2a-4e6e-aad2-b7f9c632e5f9
content:
operationGroups:
- operations:
- action: remove
path: /
resource: //compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation
resourceType: compute.googleapis.com/Reservation
overview:
currentReservation:
machineType: n1-standard-1
reservationName: test-reservation
reservedMachineCount: '1'
zone: us-central1-f
description: Save cost by deleting the idle reservation test-reservation
etag: '"aff724ab8e40e1ef"'
lastRefreshTime: '2024-06-10T07:00:00Z'
name: projects/953727763714/locations/us-central1-f/recommenders/google.compute.IdleResourceRecommender/recommendations/56f8ac5d-8380-4cb8-a76f-bbc270fb4b8e
primaryImpact:
category: COST
costProjection:
cost:
currencyCode: USD
nanos: -199820000
units: '-1072'
costInLocalCurrency:
currencyCode: USD
nanos: -199820000
units: '-1072'
duration: 2592000s
priority: P2
recommenderSubtype: DELETE_RESERVATION
stateInfo:
state: ACTIVE
targetResources:
- //compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation
Google Cloud CLI を使用した推奨事項の活用について詳しくは、gcloud の例をご覧ください。
アイドル状態の予約に関する推奨事項を表示するには、recommendations.list
メソッドに GET
リクエストを行い、次の推奨事項タイプを使用します。
- google.compute.IdleResourceRecommender
API 呼び出しは次のようになります。
GET https://recommender.googleapis.com/v1/projects/PROJECT_ID /locations/ZONE /recommenders/google.compute.IdleResourceRecommender/recommendations
次のように置き換えます。
PROJECT_ID
: プロジェクトの ID。ZONE
: 推奨事項を参照したいインスタンスが存在するゾーン。
次の例は、curl
を使用してリクエストを送信する方法と、関連するサンプル レスポンスを示しています。
PROJECT_ID=my-project ZONE=us-central1-c RECOMMENDER_ID=google.compute.IdleResourceRecommender curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-user-project: $PROJECT_ID" \ https://recommender.googleapis.com/v1/projects/$PROJECT_ID/locations/$ZONE/recommenders/$RECOMMENDER_ID/recommendations
アイドル状態の予約に関する推奨事項に対する JSON レスポンスの例:
{
"associatedInsights": [
{
"insight": "projects/9531234763714/locations/us-central1-f/insightTypes/google.compute.IdleResourceInsight/insights/ecf77776-4a2a-4e6e-aad2-b7f9c632e5f9"
}
],
"content": {
"operationGroups": [
{
"operations": [
{
"action": "remove",
"path": "/",
"resource": "//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation",
"resourceType": "compute.googleapis.com/Reservation"
}
]
}
],
"overview": {
"currentReservation": {
"machineType": "n1-standard-1",
"reservationName": "test-reservation",
"reservedMachineCount": "1",
"zone": "us-central1-f"
}
}
},
"description": "Save cost by deleting the idle reservation test-reservation",
"etag": "\"8d5603cac8fa9342\"",
"lastRefreshTime": "2024-06-11T07:00:00Z",
"name": "projects/9531234763714/locations/us-central1-f/recommenders/google.compute.IdleResourceRecommender/recommendations/56f8ac5d-8380-4cb8-a76f-bbc270fb4b8e",
"primaryImpact": {
"category": "COST",
"costProjection": {
"cost": {
"currencyCode": "USD",
"nanos": -199820000,
"units": "-1072"
},
"costInLocalCurrency": {
"currencyCode": "USD",
"nanos": -199820000,
"units": "-1072"
},
"duration": "2592000s"
}
},
"priority": "P2",
"recommenderSubtype": "DELETE_RESERVATION",
"stateInfo": {
"state": "ACTIVE"
},
"targetResources": [
"//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation"
]
}
各フィールドの詳細については、Recommender API のドキュメントをご覧ください。
推奨のレスポンスの解釈
gcloud CLI または REST を介して受信する各推奨には、推奨を適用するために連続して実行できるオペレーション グループが含まれています。アイドル状態の予約の場合、オペレーション グループには予約を削除する remove
オペレーションが含まれます。
{
"action": "remove",
"path": "/",
"resource": "//compute.googleapis.com/projects/committed-use-discount-test/zones/us-central1-f/reservations/test-reservation",
"resourceType": "compute.googleapis.com/Reservation"
}
アイドル状態の予約に関する推奨事項を適用する
アイドル状態の予約に関する推奨事項に基づいて、予約サイズを調整するか、不要になった場合は予約を削除します。
次のステップ
- Compute Engine の予約の仕組みに関する詳細を確認する。
- アイドル状態の VM に関する推奨事項を構成する方法を学習する。
- 使用率が低い予約に関する推奨事項を構成する方法を学習する。