0
0
GcpHow-ToBeginner · 3 min read

How to Stop a VM in Google Cloud Platform (GCP)

To stop a VM in GCP, use the gcloud compute instances stop [INSTANCE_NAME] --zone=[ZONE] command or stop it via the Google Cloud Console by selecting the VM and clicking the Stop button. Stopping a VM shuts it down but keeps its resources reserved.
📐

Syntax

The basic command to stop a VM in GCP using the command line is:

  • gcloud compute instances stop [INSTANCE_NAME] --zone=[ZONE]

Here:

  • [INSTANCE_NAME] is the name of your VM.
  • [ZONE] is the zone where your VM is running, like us-central1-a.
bash
gcloud compute instances stop INSTANCE_NAME --zone=ZONE
💻

Example

This example stops a VM named my-vm running in zone us-central1-a. It shows the command and the expected output.

bash
gcloud compute instances stop my-vm --zone=us-central1-a
Output
Stopping instance [my-vm] in zone [us-central1-a]... Stopped [my-vm].
⚠️

Common Pitfalls

Common mistakes when stopping VMs include:

  • Not specifying the correct --zone, which causes errors because the command can't find the VM.
  • Trying to stop a VM that is already stopped, which will show a message that the VM is not running.
  • Confusing stop with delete. Stopping keeps the VM and its disk, deleting removes it permanently.
bash
Wrong: gcloud compute instances stop my-vm
Right: gcloud compute instances stop my-vm --zone=us-central1-a
📊

Quick Reference

Tips for stopping VMs in GCP:

  • Always specify the correct zone with --zone.
  • Use the Google Cloud Console for a visual way to stop VMs by selecting the VM and clicking Stop.
  • Stopping a VM saves costs on compute but keeps storage charges for disks.

Key Takeaways

Use gcloud compute instances stop [INSTANCE_NAME] --zone=[ZONE] to stop a VM from the command line.
Always specify the correct zone to avoid errors.
Stopping a VM shuts it down but keeps its disk and configuration intact.
You can also stop VMs via the Google Cloud Console by selecting the VM and clicking the Stop button.
Stopping VMs saves compute costs but storage costs for disks continue.