A DevOps team is automating the deployment of a Compute Engine instance named `analytics-worker` in zone `us-central1-a` using the Google Cloud CLI. The VM requires a local file `/opt/scripts/init.sh` to run as a startup script during boot. Additionally, the VM must have custom metadata configured with a key of `environment` set to `production`, attach a custom service account `[email protected]`, and be granted read-only access to Cloud Storage via API access scopes. Which `gcloud compute instances create` command correctly provisions this virtual machine according to all requirements?
- gcloud compute instances create analytics-worker --zone=us-central1-a --metadata-from-file=startup-script=/opt/scripts/init.sh --metadata=environment=production --service-account=sa-analytics@my-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_onlyCevap
- Bgcloud compute instances create analytics-worker --zone=us-central1-a --metadata=startup-script-file=/opt/scripts/init.sh,environment=production --service-account=sa-analytics@my-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only
- Cgcloud compute instances create analytics-worker --zone=us-central1-a --metadata-from-file=startup-script=/opt/scripts/init.sh --metadata=environment=production --service-account=sa-analytics@my-project.iam.gserviceaccount.com --scopes=roles/storage.objectViewer
- Dgcloud compute instances create analytics-worker --zone=us-central1-a --metadata-from-file=startup-script=/opt/scripts/init.sh --metadata=environment=production --service-account=sa-analytics@my-project.iam.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only --preemptible --provisioning-model=SPOT
Cevap
The correct command is the one that uses `--metadata-from-file=startup-script=/opt/scripts/init.sh` alongside `--metadata=environment=production`, `--service-account=sa-analytics@my-project.iam.gserviceaccount.com`, and `--scopes=https://www.googleapis.com/auth/devstorage.read_only`.
The correct command properly distinguishes between string metadata and file-based metadata by employing `--metadata-from-file=startup-script=/opt/scripts/init.sh` and `--metadata=environment=production`. It also correctly specifies a valid OAuth scope URI (`https://www.googleapis.com/auth/devstorage.read_only`) alongside the custom service account email address.
Adım Adım Çözüm
Anahtar Kavram
Deploying Compute Engine VMs with startup scripts, custom metadata, custom service accounts, and API scopes via gcloud CLI