Bird
Raised Fist0
GCPcloud~20 mins

Creating a VM instance in GCP - Practice Exercises

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
VM Instance Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
2:00remaining
Choosing the right machine type for a VM instance

You want to create a VM instance on Google Cloud Platform that will run a small web server with low traffic. Which machine type should you select to optimize cost without sacrificing necessary performance?

An1-ultramem-40 (40 vCPU, 961 GB RAM)
Bn1-standard-1 (1 vCPU, 3.75 GB RAM)
Cn1-highmem-2 (2 vCPU, 13 GB RAM)
Dn1-highcpu-4 (4 vCPU, 3.6 GB RAM)
Attempts:
2 left
💡 Hint

Think about the minimum resources needed for a low-traffic web server and cost efficiency.

Configuration
intermediate
2:00remaining
Specifying the boot disk image for a VM instance

You want to create a VM instance using the latest Debian 11 image from Google Cloud. Which of the following gcloud CLI commands correctly specifies the boot disk image?

Agcloud compute instances create my-vm --image-family=debian-11 --image-project=debian-cloud
Bgcloud compute instances create my-vm --image=debian-11 --image-project=debian-cloud
Cgcloud compute instances create my-vm --image-family=debian-10 --image-project=debian-cloud
Dgcloud compute instances create my-vm --image-family=debian-11
Attempts:
2 left
💡 Hint

Use the image family to get the latest image version automatically.

security
advanced
2:00remaining
Configuring firewall rules for VM instance access

You have created a VM instance that hosts a web application on port 8080. Which firewall rule configuration will allow external users to access the application securely?

AAllow egress TCP traffic on port 8080 to 0.0.0.0/0
BAllow ingress TCP traffic on port 22 from 0.0.0.0/0
CAllow ingress TCP traffic on port 8080 from 0.0.0.0/0
DDeny ingress TCP traffic on port 8080 from 0.0.0.0/0
Attempts:
2 left
💡 Hint

Think about which direction and port need to be open for users to reach your web app.

service_behavior
advanced
2:00remaining
Understanding VM instance startup behavior with startup scripts

You add a startup script to your VM instance metadata to install software on boot. What will happen if the script contains a command that fails?

AThe VM instance will continue booting, but the failed command will not complete.
BThe VM instance will fail to start and remain in a stopped state.
CThe VM instance will reboot automatically until the script succeeds.
DThe VM instance will ignore the startup script entirely.
Attempts:
2 left
💡 Hint

Consider how startup scripts run during boot and their impact on the VM state.

Best Practice
expert
3:00remaining
Designing VM instance deployment for high availability

You need to deploy a critical application on VM instances in Google Cloud that must remain available even if a zone fails. Which architecture best meets this requirement?

ADeploy multiple VM instances in a single zone behind a load balancer.
BDeploy VM instances in multiple projects to increase availability.
CDeploy a single VM instance with a large machine type in one zone.
DDeploy VM instances in multiple zones within a region behind a regional load balancer.
Attempts:
2 left
💡 Hint

Think about how to avoid a single zone failure affecting your application.

Practice

(1/5)
1. What does creating a VM instance in Google Cloud allow you to do?
easy
A. Create a database
B. Store files permanently
C. Run a virtual computer in the cloud
D. Send emails automatically

Solution

  1. Step 1: Understand VM instance purpose

    A VM instance is a virtual machine, like a computer inside the cloud.
  2. Step 2: Identify correct function

    Running a virtual computer matches the VM instance role, unlike storing files or sending emails.
  3. Final Answer:

    Run a virtual computer in the cloud -> Option C
  4. Quick Check:

    VM instance = virtual computer [OK]
Hint: VM means virtual machine, a computer in the cloud [OK]
Common Mistakes:
  • Confusing VM with storage service
  • Thinking VM creates databases directly
  • Assuming VM sends emails automatically
2. Which command correctly creates a VM instance named my-vm in zone us-central1-a with machine type e2-medium and image debian-11?
easy
A. gcloud create vm my-vm --zone us-central1-a --type e2-medium --image debian-11
B. gcloud compute vm create my-vm --zone=us-central1-a --machine-type=e2-medium --image debian-11
C. gcloud instances create --name my-vm --zone us-central1-a --machine e2-medium --image debian-11
D. gcloud compute instances create my-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud

Solution

  1. Step 1: Check correct command structure

    The correct command starts with 'gcloud compute instances create' followed by the instance name.
  2. Step 2: Verify flags and parameters

    Flags like '--zone', '--machine-type', '--image-family', and '--image-project' must be exact and use '=' sign.
  3. Final Answer:

    gcloud compute instances create my-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud -> Option D
  4. Quick Check:

    Correct gcloud syntax = gcloud compute instances create my-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud [OK]
Hint: Use 'gcloud compute instances create' with exact flags [OK]
Common Mistakes:
  • Using wrong command verbs like 'create vm'
  • Missing '=' in flags
  • Wrong flag names like '--machine' instead of '--machine-type'
3. What will happen if you run this command?
gcloud compute instances create test-vm --zone=us-east1-b --machine-type=n1-standard-1 --image-family=ubuntu-2004-lts --image-project=ubuntu-os-cloud
medium
A. The command will fail due to missing machine type
B. A VM named test-vm will be created in zone us-east1-b with Ubuntu 20.04 OS
C. A VM will be created but with default image, not Ubuntu
D. The VM will be created in the wrong zone

Solution

  1. Step 1: Analyze command parameters

    The command specifies instance name, zone, machine type, image family, and image project correctly.
  2. Step 2: Understand image selection

    Using '--image-family=ubuntu-2004-lts' with '--image-project=ubuntu-os-cloud' selects Ubuntu 20.04 LTS image.
  3. Final Answer:

    A VM named test-vm will be created in zone us-east1-b with Ubuntu 20.04 OS -> Option B
  4. Quick Check:

    Correct flags create VM with specified OS [OK]
Hint: Image family + project picks correct OS image [OK]
Common Mistakes:
  • Confusing image-family with image name
  • Omitting image-project causes errors
  • Wrong zone spelling
4. You tried to create a VM with:
gcloud compute instances create vm1 --zone=us-west1-c --machine-type=e2-small --image=debian-10

The command failed with an error about the image. What is the likely cause?
medium
A. The image name 'debian-10' is incorrect or deprecated
B. The zone 'us-west1-c' does not exist
C. The machine type 'e2-small' is invalid
D. You forgot to specify the project

Solution

  1. Step 1: Check image parameter validity

    Using '--image=debian-10' is often invalid because images require full name or image family with project.
  2. Step 2: Understand error cause

    Image errors usually mean the image name is wrong or deprecated, not zone or machine type.
  3. Final Answer:

    The image name 'debian-10' is incorrect or deprecated -> Option A
  4. Quick Check:

    Image errors = wrong image name [OK]
Hint: Use image family and project, not just image name [OK]
Common Mistakes:
  • Assuming zone or machine type caused image error
  • Not specifying image project with image family
  • Using outdated image names
5. You want to create a VM instance that automatically allows HTTP traffic and uses a custom startup script to install software. Which command correctly achieves this?
hard
A. gcloud compute instances create web-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud --tags=http-server --metadata=startup-script='sudo apt-get update && sudo apt-get install -y nginx'
B. gcloud compute instances create web-vm --zone=us-central1-a --machine-type=e2-medium --image=debian-11 --allow-http --script='install nginx'
C. gcloud compute instances create web-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud --firewall=http --startup='apt-get install nginx'
D. gcloud compute instances create web-vm --zone=us-central1-a --machine-type=e2-medium --image=debian-11 --http --metadata=startup='install nginx'

Solution

  1. Step 1: Enable HTTP traffic with tags

    Using '--tags=http-server' allows HTTP traffic via firewall rules.
  2. Step 2: Add startup script correctly

    '--metadata=startup-script=' followed by the script installs nginx on startup.
  3. Step 3: Verify image and machine type

    Using '--image-family=debian-11' and '--image-project=debian-cloud' is correct for Debian 11.
  4. Final Answer:

    gcloud compute instances create web-vm --zone=us-central1-a --machine-type=e2-medium --image-family=debian-11 --image-project=debian-cloud --tags=http-server --metadata=startup-script='sudo apt-get update && sudo apt-get install -y nginx' -> Option A
  5. Quick Check:

    Tags + metadata=startup-script = correct setup [OK]
Hint: Use --tags for HTTP and --metadata for startup script [OK]
Common Mistakes:
  • Using wrong flags like --allow-http or --http
  • Incorrect metadata key name
  • Not specifying image project with image family