This guide uses an example to teach how to add drest output to an API tab.
Creating a client VM
This example creates a client VM (vm-client
) in the same region as the backend
(server) VMs. The client is used to validate the load balancer's configuration
and demonstrate expected behavior as described in the
testing section.
Console
- Go to the VM instances page in the Google Cloud Console.
Go to the VM instances page - Click Create instance.
- Set the Name to
vm-client
. - Set the Zone to
us-west1-a
. - Click Management, security, disks, networking, sole tenancy and make
the following changes:
- Click Networking and add the
allow-ssh
to Network tags. - Click the edit button under Network interfaces and make the
following changes then click Done:
- Network:
lb-network
- Subnet:
lb-subnet
- Primary internal IP: Ephemeral (automatic)
- External IP: Ephemeral
- Network:
- Click Networking and add the
- Click Create.
gcloud
The client VM can be in any zone in the same region as the
load balancer, and it can use any subnet in that region. In this example,
the client is in the us-west1-a
zone, and it uses the same
subnet as the backend VMs.
gcloud compute instances create vm-client \ --zone=us-west1-a \ --image-family=debian-9 \ --image-project=debian-cloud \ --tags=allow-ssh \ --subnet=lb-subnet
api
Make a POST
request to the
instances.insert
method.
Before using any of the request data below, make the following replacements:
- `PROJECT_ID`: Your project ID
- `ZONE`: us-west1-a
- `NETWORK`: lb-network
- `SUBNET`: lb-subnet
HTTP method and URL:
POST https://www.googleapis.com/compute/v1/projects/`PROJECT_ID`/zones/`ZONE`/instances
Request JSON body:
{ "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/eip-images/global/images/debian-9-drawfork-v20190702", "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" ] } ] }
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{ "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" }
What's next
- Start using drest! :)