Question

Difficulty: Very hardDeploying and Managing Compute Engine Virtual Machines

A cloud engineer is configuring an automated script using the Google Cloud CLI (gcloud) to provision worker virtual machines on Compute Engine for batch data processing. The deployment must fulfill three strict technical requirements:
1. The VM instances must be provisioned as Spot VMs to optimize infrastructure cost.
2. The instances must execute a startup script stored in a Cloud Storage bucket at gs://prod-initializer-bucket/setup.sh upon initial boot.
3. The instances must be configured with a user-managed service account named [email protected] without relying on legacy default compute service account permissions.

Which TWO gcloud compute instances create flag options must be included in the command to correctly satisfy these requirements?

  1. --provisioning-model=SPOT --instance-termination-action=STOPAnswer
  2. --metadata=startup-script-url=gs://prod-initializer-bucket/setup.shAnswer
  3. C
    --scopes=roles/editor [email protected]
  4. D
    --startup-script=gs://prod-initializer-bucket/setup.sh --maintenance-policy=MIGRATE

Answer

The correct options are the flags configuring '--provisioning-model=SPOT --instance-termination-action=STOP' and '--metadata=startup-script-url=gs://prod-initializer-bucket/setup.sh'.
Provisioning Spot VMs via the gcloud CLI requires setting '--provisioning-model=SPOT' alongside an instance termination action such as '--instance-termination-action=STOP'. Furthermore, executing a remote startup script hosted in Google Cloud Storage requires specifying the metadata key 'startup-script-url' within the metadata flag ('--metadata=startup-script-url=gs://...'). Together, these options fulfill the deployment requirements correctly.

Step-by-Step Solution

1
Identify the proper gcloud CLI flag for provisioning Spot VM capacity.
The current standard flag syntax for Spot instances is '--provisioning-model=SPOT', accompanied by a termination action such as '--instance-termination-action=STOP' or 'DELETE'.
Legacy preemptible VMs used '--preemptible', but '--provisioning-model=SPOT' is the current model for Spot VM creation on Compute Engine.
2
Determine the correct gcloud metadata parameter for referencing a Cloud Storage startup script.
Passing a remote script URL requires using key-value pair formatting under metadata: '--metadata=startup-script-url=gs://bucket/script.sh'.
Direct flags like '--startup-script' are invalid syntax in gcloud compute instances create when referencing Cloud Storage bucket paths.
3
Evaluate and eliminate incorrect flag combinations.
Passing IAM role identifiers into the '--scopes' parameter causes a CLI syntax error because scopes accept URI endpoints, not IAM roles. Additionally, setting host maintenance to MIGRATE conflicts with Spot VM operational constraints.
IAM permissions must be granted to the attached service account separately via IAM policies, while Spot instances require host termination on maintenance.

Key Concept

Compute Engine gcloud CLI Provisioning and Configuration Flags
Estimated Time:2m 0s
Rate this question