Stopping or Deleting an Instance

This page describes how to stop or delete an instance.

You can stop an instance temporarily so you can come back to it at a later time. A stopped instance does not incur charges, but all of the resources that are attached to the instance will still be charged. Alternatively, if you are done using an instance, delete the instance and its resources to stop incurring charges.

Before you begin

Stopping an instance

Stopping an instance causes Compute Engine to send the ACPI Power Off signal to the instance. Modern guest operating systems are configured to perform a clean shutdown before powering off in response to the power off signal. Compute Engine waits a short time for the guest to finish shutting down and then transitions the instance to the TERMINATED state.

A stopped instance does not incur charges, but all of the resources that are attached to the instance will still be charged. For example, you are charged for persistent disks and external IP addresses according to the price sheet, even if an instance is stopped. To stop being charged for attached resources, you can reconfigure a stopped instance to not use those resources, and then delete the resources.

You cannot stop an instance that has a local SSD attached. Instead, you must migrate your critical data off of the local SSD to a persistent disk or to another instance before you delete the instance completely. Compute Engine does not prevent you from shutting down the guest operating system on an instance with a local SSD, so take extra precautions if you shut down the guest operating systems on your instances.

To stop an instance, use the Google Cloud Platform Console, the gcloud tool, or the API.

Console

  1. Go to the VM instances page in the Cloud Platform Console.

    Go to the VM instances page

  2. Select one or more instances that you want to stop.
  3. At the top of the VM instances page, click Stop.

gcloud

Use the instances stop command and specify one or more instances that you want to stop.

gcloud compute instances stop example-instance-1 example-instance-2

API

In the API, construct a POST request to stop an instance.

POST https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances/example-instance/stop

A TERMINATED instance still exists with its configuration settings and instance metadata but loses its in-memory data and virtual machine state. Any resources that are still attached to the terminated instance will remain attached until you manually detach those resources or delete the instance.

After the instance is in the TERMINATED state, you can restart the instance or delete it. You can also leave an instance in a TERMINATED state indefinitely. However, if you do not plan to restart the instance, delete it instead.

Stopping an instance through the operating system

Optionally, you can stop an instance through the guest operating system using the sudo shutdown -h now or sudo poweroff commands. Execute one of these commands while you are logged into the virtual machine:

me@example-instance:~$ sudo shutdown -h now
me@example-instance:~$ sudo poweroff

Billing for stopped instances

Instances that are in a TERMINATED state are not charged for per-minute running virtual machine usage and do not count towards your regional CPU quota, so you can choose to stop instances that you are not using, saving you from being charged for instances that aren't active. Once you are ready, you can come back and start the same instances again, with the same instance properties, metadata, and resources.

Your instances are not charged for per-minute usage charges in TERMINATED state but any resources attached to the virtual machine will be charged until they are deleted, such as static IPs and persistent disks.

State of resources for stopped instances

When you stop an instance, it has the following effects on the instance and on resources related to the instance:

Resource Effect
Persistent disks

Persistent disks are maintained when an instance is stopped, even persistent disks that are marked for auto-delete.

You will continue to be charged for persistent disks associated with stopped virtual machines, just like you would a persistent disk that is not associated with any virtual machines.

RAM and virtual machine state

Reset to power-on state, no data is saved.

GPUs

GPUs are not charged when an instance is stopped. A GPU attached to a stopped instance will not count against your project quota.

External ephemeral IPs

Ephemeral IPs are released when an instance is stopped, but a new ephemeral IP address is acquired when the instance is restarted.

External static IPs

Static external IPs are maintained.

Static IPs assigned to stopped instances are charged as if they are not attached to any instance. See pricing page for details.

Internal IPs / MAC address

Internal IPs and MAC addresses are maintained.

Billing

Stopped instances are not billed, but when a stopped instance is restarted, the 10 minute minimum billing duration will be enforced.

When an instance is stopped, you can still perform actions that can affect the stopped instance, such as:

  • Changing the machine type
  • Adding or removing attached disks
  • Updating a disk’s auto-delete setting
  • Modifying instance tags
  • Modifying custom instance metadata
  • Modifying project-wide metadata
  • Removing or setting a new static IP
  • Modifying the instance’s scheduling options

However, you cannot change an instance’s image.

Deleting an instance

You can permanently delete an instance to remove the instance and the associated resources from your project. If the instance is part of an instance group, the group might try to recreate the instance to maintain a certain group size. Resize the instance group or reconfigure the autoscaler instead.

Console

  1. Go to the VM Instances page in the Cloud Platform Console.

    Go to the VM Instances page

  2. Check the instances you want to delete.
  3. Click the Delete button.

gcloud

Use the gcloud compute instances delete command. When you delete an instance in this way, the instance shuts down and is removed from the list of instances, and all resources attached to the instance are released, such as persistent disks and any static IP addresses.

To delete an instance, use the following command:

gcloud compute instances delete example-instance [example-instance-2 example-instance-3..]

API

Use the delete method:

DELETE https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-f/instances/example-instance

Shutdown period

When you shut down or delete an instance, Compute Engine sends the ACPI Power Off signal to the instance and waits a short period of time for your instance to shut down cleanly. If your instance is still running after this grace period, Compute Engine forcefully terminates it even if your shutdown script is still running.

The length of the shutdown period depends on the type of your instance.

  • Normal instances have a shutdown period that usually lasts at least 90 seconds, but could be longer.
  • Preemptible instances have a shutdown period that lasts 30 seconds, which is the same length as the shutdown period that happens during the preemption process.

If you choose to run a shutdown script during this period, your shutdown script must finish running within this time period so that the operating system has time to complete its shutdown and flush buffers to disk.

What's next

Send feedback about...

Compute Engine Documentation