Question

Difficulty: EasyDeploying and Managing Compute Engine Virtual Machines

Place the following steps in the correct chronological sequence to deploy and verify a Compute Engine virtual machine configured with an automated web server startup script.

  1. 1Create a local bash script containing the commands to install and start the web server service.
  2. 2Run `gcloud compute instances create` with the `--metadata-from-file` flag specifying the startup script path.
  3. 3Execute `gcloud compute instances list` to retrieve the external IP address assigned to the new VM instance.
  4. 4Send a request to the external IP address in a web browser to confirm that the web server is responding.

Answer

The correct sequence is: Write the local startup script -> Execute gcloud compute instances create with --metadata-from-file -> Run gcloud compute instances list to get the external IP -> Access the external IP in a browser to verify deployment.
The standard deployment workflow starts with authoring the startup script locally. Next, the VM is created using `gcloud compute instances create` while passing `--metadata-from-file startup-script=...`. After creation, `gcloud compute instances list` is used to discover the instance's public IP address. Finally, navigating to the IP address validates that the script executed successfully and the web server is running.

Step-by-Step Solution

1
Prepare the startup script locally
A bash script file containing package installation commands is stored on disk.
The file must be present locally so gcloud can read its contents during provisioning.
2
Provision the Compute Engine virtual machine
Google Cloud creates the VM instance and executes the script during initial startup.
Using `gcloud compute instances create` with `--metadata-from-file startup-script=...` attaches the script to the instance metadata.
3
Retrieve network details
The public external IP address of the instance is identified.
The `gcloud compute instances list` command displays running instances and their allocated external IP addresses.
4
Verify application health
The web server response confirms successful provisioning and execution.
Testing the endpoint verifies end-to-end connectivity and verifies that the startup script completed.

Key Concept

Deploying Compute Engine virtual machines with startup scripts using the gcloud CLI
Rate this question