イメージ ファミリーを使用して、イメージのバージョニングを簡略化します。イメージをイメージ ファミリーに追加し、最新のイメージ バージョンとして設定します。イメージ ファミリーを以前のイメージ バージョンにロールバックする必要があると判断した場合は、ファミリー内の最新のイメージの使用を中止します。
イメージ ファミリーを操作する際のベスト プラクティスについては、イメージ ファミリーのベスト プラクティスをご覧ください。
Google Cloud コンソール、gcloud compute images create
コマンドと --storage-location
フラグ、images().insert
メソッドを使用すると、イメージの保存先を指定できます。
始める前に
- Images ドキュメントを確認します。
-
まだ設定していない場合は、認証を設定します。認証とは、サービスと API にアクセスするために ID を確認するプロセスです。 Google Cloud ローカル開発環境からコードまたはサンプルを実行するには、次のいずれかのオプションを選択して 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 を使用して認証するをご覧ください。
-
イメージ ファミリーでイメージ バージョンを設定する
Google Cloud コンソールで、[イメージの作成] ページに移動します。
イメージの [名前] を指定します。例:
image-v1
イメージ作成元の [ソース] を指定します。永続ディスク、スナップショット、別のイメージまたは Cloud Storage 内の disk.raw ファイルが指定できます
実行中の VM にアタッチされたディスクからイメージを作成する場合、[インスタンスを実行し続ける] をオンにして、VM の実行中にイメージを作成することを確認します。イメージを作成する前に VM を準備できます。
[ソースディスクのロケーションに基づく(デフォルト)] プルダウン リストで、イメージを保存するロケーションを指定します。たとえば、イメージを
us
マルチリージョンに保存するにはus
を指定し、us-central1
リージョンに保存するにはus-central1
を指定します。選択しない場合、Compute Engine はイメージのソースのロケーションに最も近いマルチリージョンにイメージを保存します。新しいイメージの、イメージ ファミリーを指定します。たとえば、
my-image-family
を追加してイメージ ファミリーの一部としてイメージを管理します。省略可: 他のイメージ プロパティを指定します。
- 説明: カスタム イメージの説明。
- ラベル: リソースをグループ化するラベル。
暗号鍵を指定します。 Google-owned and Google-managed encryption key、Cloud Key Management Service(Cloud KMS)鍵、顧客指定の暗号鍵(CSEK)のいずれかを選択できます。暗号鍵が指定されていない場合、イメージは Google-owned and Google-managed encryption keyを使用して暗号化されます。
[作成] をクリックしてイメージを作成します。
gcloud compute images create image-v1 \ --source-disk disk-1 \ --source-disk-zone us-central1-f \ --family my-image-family
イメージ ファミリーは image-v1
をポイントします。2 つ目のイメージをファミリーに追加します。
gcloud compute images create image-v2 \ --source-disk disk-2 \ --source-disk-zone us-central1-f \ --family my-image-family
images().insert
メソッドに POST
リクエストを送信します。リクエストの本文にイメージ ファミリーを指定します。
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID /global/images { "name": "image-v2", "sourceDisk": "/zones/us-central1-f/disks/disk-2", "family":"my-image-family", }
image-v2
はイメージ ファミリーに追加した最新のイメージであるため、イメージ ファミリーではこのイメージがポイントされます。
gcloud compute images describe-from-family
コマンドを実行して、ファミリーでどのイメージがポイントされるかを確認できます。
次に例を示します。
gcloud compute images describe-from-family my-image-family
family: my-image-family
id: '8904691942610171306'
kind: compute#image
name: image-v2
selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/global/images/image-v2
sourceDisk: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-f/disks/disk-v2
sourceDiskId: '1677449456001963379'
sourceType: RAW
status: READY
images().getFromFamily
メソッドに GET
リクエストを送信します。リクエストの本文にイメージ ファミリーを指定します。
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID /global/images/family { "resourceId":"my-image-family", }
イメージ ファミリーをロールバックして image-v2
をポイントしなくなるようにする必要があると判断した場合は、image-v2
を使用中止にすると、ファミリーは再び image-v1
をポイントします。
gcloud compute images deprecate image-v2 \ --state DEPRECATED \ --replacement image-v1
イメージ ファミリーが image-v1
をポイントしていることを確認します。
gcloud compute images describe-from-family my-image-family
family: my-image-family
id: '2741732787056801255'
kind: compute#image
name: image-v1
selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/global/images/image-v1
sourceDisk: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-f/disks/disk-v1
sourceDiskId: '1677449456001963379'
sourceType: RAW
status: READY