This page describes how to delete an instance. If you don't want to delete an instance but want to temporarily stop it, read Stopping and starting an instance or Suspending and resuming an instance.
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 an identical instance to maintain a certain group size. Resize the instance group or reconfigure the autoscaler instead.
Before you begin
-
If you haven't already, set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine as follows.
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
C#
To use the .NET samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
Go
To use the Go samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
Java
To use the Java samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
Node.js
To use the Node.js samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
PHP
To use the PHP samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
Python
To use the Python samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
Ruby
To use the Ruby samples on this page from a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create local authentication credentials for your Google Account:
gcloud auth application-default login
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
-
Delete an instance
Delete an instance using Google Cloud console , the Google Cloud CLI, or the API.
Console
- Go to the VM Instances page in the Google Cloud console.
- Check the instances you want to delete.
- 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..]
C#
Go
Java
Node.js
PHP
Python
Ruby
REST
Use the delete
method:
DELETE https://compute.googleapis.com/compute/v1/projects/example-project/zones/us-central1-f/instances/example-instance
Billing implications
After you delete a VM instance, you are no longer billed for that instance unless any of the following situations apply:
- If you delete a VM that is hosted on a sole-tenant node, you continue to pay for the sole-tenant node itself instead of the individual VMs hosted on the node.
- If you have a committed use contract, you continue to pay for the resources you committed to, whether or not you use those resources.
- If you retain any resources that were attached to the VM instance, you continue to be charged for those resources until you delete them, too. For example, if you delete the VM instance but keep its persistent disk, you continue to be charged for the persistent disk.
For more details on pricing information, see VM instances pricing.
Shutdown period
When you stop 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
- Learn about the instance life cycle.
- Stop an instance instead of deleting it permanently.
- Suspend an instance instead of deleting it permanently.
- Limit the runtime of a VM to schedule a VM to be automatically deleted instead of deleting a VM manually.