Soru

Zorluk: OrtaDeploying and Managing Compute Engine Virtual Machines

A cloud engineer needs to provision a single Compute Engine instance named `analytics-worker` in zone `us-east1-b`. The virtual machine must use the `e2-standard-4` machine type, must not have a public IP address assigned, and must execute a local provisioning script stored on the engineer's workstation at `/scripts/bootstrap.sh` when the instance boots up. Which `gcloud` command should the engineer run to deploy this instance?

  1. gcloud compute instances create analytics-worker --zone=us-east1-b --machine-type=e2-standard-4 --metadata-from-file=startup-script=/scripts/bootstrap.sh --no-addressCevap
  2. B
    gcloud compute instances create analytics-worker --zone=us-east1-b --machine-type=e2-standard-4 --metadata=startup-script=/scripts/bootstrap.sh --no-address
  3. C
    gcloud compute instances create analytics-worker --region=us-east1-b --machine-type=e2-standard-4 --startup-script-file=/scripts/bootstrap.sh --no-address
  4. D
    gcloud compute instances create analytics-worker --zone=us-east1-b --machine-type=e2-standard-4 --metadata-from-file=startup-script=/scripts/bootstrap.sh --scopes=owner

Cevap

The command 'gcloud compute instances create analytics-worker --zone=us-east1-b --machine-type=e2-standard-4 --metadata-from-file=startup-script=/scripts/bootstrap.sh --no-address' correctly provisions the Compute Engine instance with the required configuration.
The correct command provisions a zonal Compute Engine instance using '--zone=us-east1-b', sets the machine type to 'e2-standard-4', uses '--no-address' to prevent public IP allocation, and uses '--metadata-from-file=startup-script=/scripts/bootstrap.sh' to properly upload and execute the local bootstrap script during instance startup.

Adım Adım Çözüm

1
Identify the proper metadata flag for local file contents.
Use '--metadata-from-file=startup-script=/scripts/bootstrap.sh' to read and upload the local script file on instance creation.
The standard '--metadata' flag treats values as literal strings, whereas '--metadata-from-file' reads the file from local disk.
2
Verify network configuration flags for external IP restriction.
Include '--no-address' to prevent assigning an external public IP address.
By default, Compute Engine assigns an ephemeral external IP unless explicitly disabled with '--no-address'.
3
Confirm proper location scope flag.
Specify '--zone=us-east1-b' rather than '--region'.
Compute Engine instances are zonal resources and require a zone parameter during creation.

Anahtar Kavram

Deploying Compute Engine VMs with custom startup scripts using gcloud CLI metadata flags
Tahmini Süre:1m 30s
Bu soruyu puanla