API タブへの drest 出力の追加

このガイドでは、例を使用して [API] タブに drest 出力を追加する方法を説明します。

クライアント VM の作成

この例では、クライアント VM(vm-client)を、バックエンド(サーバー)VM と同じリージョンに作成します。クライアントを使用するのは、ロードバランサの構成を検証し、テストセクションで説明されている想定される動作を示すためです。

コンソール

  1. Google Cloud コンソールの [VM インスタンス] ページに移動します。
    [VM インスタンス] ページに移動
  2. [インスタンスを作成] をクリックします。
  3. [名前] を vm-client に設定します。
  4. [ゾーン] を us-west1-a に設定します。
  5. [管理、セキュリティ、ディスク、ネットワーク、単一テナンシー] をクリックして、次のように変更します。
    • [ネットワーキング] をクリックして allow-sshネットワーク タグに追加します。
    • [ネットワーク インターフェース] にある編集ボタンをクリックして、次の変更を行い、[完了] をクリックします。
      • ネットワーク: lb-network
      • サブネット: lb-subnet
      • プライマリ内部 IP: エフェメラル(自動)
      • 外部 IP: エフェメラル
  6. [作成] をクリックします。

gcloud

クライアント VM はロードバランサと同じリージョン内の任意のゾーンにあり、そのリージョン内の任意のサブネットを使用できます。この例では、クライアントは us-west1-a ゾーンにあり、バックエンド VM と同じサブネットを使用しています。

gcloud compute instances create vm-client \
    --zone=us-west1-a \
    --image-family=debian-10 \
    --image-project=debian-cloud \
    --tags=allow-ssh \
    --subnet=lb-subnet

api

instances.insert メソッドに POST リクエストを送信します。

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: プロジェクト ID
  • ZONE: us-west1-a
  • NETWORK: lb-network
  • SUBNET: lb-subnet

HTTP メソッドと URL:

POST https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/instances

JSON 本文のリクエスト:

{
  "kind": "compute#instance",
  "name": "`VM_NAME`",
  "zone": "projects/`PROJECT_ID`/zones/`ZONE`",
  "machineType": "projects/`PROJECT_ID`/zones/`ZONE`/machineTypes/n1-standard-1",
  "displayDevice": {
    "enableDisplay": false
  },
  "metadata": {
    "kind": "compute#metadata",
    "items": []
  },
  "tags": {
    "items": []
  },
  "disks": [
    {
      "kind": "compute#attachedDisk",
      "type": "PERSISTENT",
      "boot": true,
      "mode": "READ_WRITE",
      "autoDelete": true,
      "deviceName": "`VM_NAME`",
      "initializeParams": {
        "sourceImage": "projects/debian-cloud/global/images/debian-10-buster-v20220719",
        "diskType": "projects/`PROJECT_ID`/zones/`ZONE`/diskTypes/pd-standard",
        "diskSizeGb": "10"
      },
      "diskEncryptionKey": {}
    }
  ],
  "canIpForward": false,
  "networkInterfaces": [
    {
      "kind": "compute#networkInterface",
      "subnetwork": "projects/`PROJECT_ID`/regions/us-central1/subnetworks/`SUBNET`",
      "accessConfigs": [
        {
          "kind": "compute#accessConfig",
          "name": "External NAT",
          "type": "ONE_TO_ONE_NAT",
          "networkTier": "PREMIUM"
        }
      ],
      "aliasIpRanges": []
    }
  ],
  "description": "",
  "labels": {},
  "scheduling": {
    "preemptible": false,
    "onHostMaintenance": "MIGRATE",
    "automaticRestart": true,
    "nodeAffinities": []
  },
  "deletionProtection": false,
  "reservationAffinity": {
    "consumeReservationType": "ANY_RESERVATION"
  },
  "serviceAccounts": [
    {
      "email": "893700239234-compute@developer.gserviceaccount.com",
      "scopes": [
        "https://www.googleapis.com/auth/devstorage.read_only",
        "https://www.googleapis.com/auth/logging.write",
        "https://www.googleapis.com/auth/monitoring.write",
        "https://www.googleapis.com/auth/servicecontrol",
        "https://www.googleapis.com/auth/service.management.readonly",
        "https://www.googleapis.com/auth/trace.append"
      ]
    }
  ]
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
 "id": "8061072881391620712",
 "name": "operation-1565289606387-58f9f62f5989c-e582f586-6d22f38d",
 "zone": "https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`",
 "operationType": "insert",
 "targetLink": "https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/instances/`VM_NAME`",
 "targetId": "2977231178150564457",
 "status": "RUNNING",
 "user": "betsyl@google.com",
 "progress": 0,
 "insertTime": "2019-08-08T11:40:07.728-07:00",
 "startTime": "2019-08-08T11:40:07.731-07:00",
 "selfLink": "https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/operations/operation-1565289606387-58f9f62f5989c-e582f586-6d22f38d",
 "kind": "compute#operation"
}

次のステップ

  • drest を使い始める:)