Question

Difficulty: MediumDeploying and Managing Compute Engine Virtual Machines

An infrastructure team is provisioning Compute Engine instances using the gcloud command-line tool. The workload consists of stateless batch processing tasks running on Spot VMs, and each VM requires execution of a local shell script during boot. Which TWO gcloud configuration practices are correct for this scenario?

  1. Set `--on-host-maintenance=TERMINATE` for the Spot VM instances because they do not support live migration.Answer
  2. Use `--metadata-from-file=startup-script=path/to/script.sh` to supply a startup script from a file on the local machine.Answer
  3. C
    Configure `--provisioning-model=SPOT` for stateful production web server instances to guarantee continuous availability at discounted rates.
  4. D
    Use `--metadata=startup-script=path/to/script.sh` to load and run a startup script stored on the local file system.

Answer

The two correct choices are to set the host maintenance policy to terminate for Spot VMs (`--on-host-maintenance=TERMINATE`) and to use `--metadata-from-file=startup-script=path/to/script.sh` to read and pass a local startup script.
Spot instances do not support live migration during host maintenance events and require setting the maintenance policy to terminate. Additionally, supplying a startup script located on the local filesystem requires using `--metadata-from-file` so gcloud reads the contents of the file before sending the request to the Compute Engine API.

Step-by-Step Solution

1
Evaluate availability and host maintenance requirements for Spot instances.
Spot VMs cannot undergo live migration during host updates and must be set to terminate on host maintenance.
Google Cloud rules prohibit live migration for pre-emptible and Spot instances.
2
Determine the proper gcloud flag for uploading a local startup script file during instance creation.
`--metadata-from-file=startup-script=path/to/script.sh` correctly reads file contents from the local disk.
Using `--metadata` only passes the path string literally, whereas `--metadata-from-file` extracts and attaches the file's text contents.

Key Concept

Compute Engine instance deployment flags, Spot VM maintenance policies, and metadata configuration via gcloud CLI.
Estimated Time:1m 30s
Rate this question