Soru

Zorluk: ZorDeploying and Managing Compute Engine Virtual Machines

A DevOps engineer is configuring an automated script to deploy a fault-tolerant batch processing Virtual Machine on Compute Engine using the gcloud CLI. The instance must run as a Spot VM to reduce compute costs, automatically terminate during host maintenance events, attach an existing custom service account named [email protected] with full Cloud Storage permissions, and execute a local shell script located at /scripts/setup.sh upon startup. Which gcloud compute instances create command correctly fulfills all these requirements?

  1. gcloud compute instances create batch-node-01 --zone=us-central1-a --provisioning-model=SPOT --on-host-maintenance=TERMINATE --service-account=batch-processor@my-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.full_control --metadata-from-file=startup-script=/scripts/setup.shCevap
  2. B
    gcloud compute instances create batch-node-01 --zone=us-central1-a --provisioning-model=SPOT --on-host-maintenance=MIGRATE --service-account=batch-processor@my-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.full_control --metadata-from-file=startup-script=/scripts/setup.sh
  3. C
    gcloud compute instances create batch-node-01 --zone=us-central1-a --provisioning-model=SPOT --on-host-maintenance=TERMINATE --service-account=batch-processor@my-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.full_control --metadata=startup-script=/scripts/setup.sh
  4. D
    gcloud compute instances create batch-node-01 --zone=us-central1-a --provisioning-model=SPOT --on-host-maintenance=TERMINATE [email protected],storage-full --metadata-from-file=startup-script=/scripts/setup.sh

Cevap

The command specifying `--provisioning-model=SPOT`, `--on-host-maintenance=TERMINATE`, `--service-account=batch-processor@my-project.iam.gserviceaccount.com`, `--scopes=https://www.googleapis.com/auth/devstorage.full_control`, and `--metadata-from-file=startup-script=/scripts/setup.sh` correctly provisions the instance.
The correct option specifies `--provisioning-model=SPOT` combined with `--on-host-maintenance=TERMINATE`, as Spot instances cannot be live-migrated during infrastructure maintenance. It uses `--service-account` to assign the custom IAM service account email and `--scopes` for API permissions. Lastly, it utilizes `--metadata-from-file=startup-script=...` to properly read and upload the local file contents as the VM startup script.

Adım Adım Çözüm

1
Configure the VM provisioning model and host maintenance behavior.
Set `--provisioning-model=SPOT`. Compute Engine requires Spot instances to use `--on-host-maintenance=TERMINATE` because live migration is not supported for Spot or preemptible instances.
Spot instances are transient and cannot undergo live migration during host infrastructure maintenance.
2
Attach the custom IAM service account identity and define access scopes.
Pass the service account email using `--service-account=batch-processor@my-project.iam.gserviceaccount.com` and define storage permissions using `--scopes=https://www.googleapis.com/auth/devstorage.full_control`.
The `--service-account` flag attaches the identity, while `--scopes` defines the maximum allowed API access level for legacy scope filtering.
3
Supply the startup script from a local file path.
Use `--metadata-from-file=startup-script=/scripts/setup.sh`.
`--metadata-from-file` reads the actual contents of the local file and populates the `startup-script` metadata key, whereas `--metadata` only assigns literal string values.

Anahtar Kavram

Deploying Compute Engine instances with custom service accounts, Spot VM availability policies, and startup script file metadata via gcloud CLI.
Bu soruyu puanla