Deleting a virtual machine (VM) removes the VM and its associated resources from
your project. If you don't want to delete an instance, you can temporarily stop
it. See [Stop and start a VM](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vms/manage-vms/operations-and-lifecycle/start-and-stop-vm) for those instructions.

## Before you begin

To use `gdcloud` command-line interface (CLI) commands, ensure that you have downloaded, installed,
and configured the [`gdcloud` CLI](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/resources/gdcloud-overview).
All commands for GDC air-gapped appliance use the `gdcloud` or
`kubectl` CLI, and require an operating system (OS) environment.

### Get the kubeconfig file path

To run commands against the Management API server, ensure you have the following
resources:

1. Locate the Management API server name, or ask your Platform Administrator (PA)
   what the server name is.

2. [Sign in and generate](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/iam/sign-in#cli) the
   kubeconfig file for the Management API server if you don't have one.

3. Use the path to replace `MANAGEMENT_API_SERVER{"</var>"}}` in these instructions.

### Request permissions and access

To perform the tasks listed in this page, you must have the Project
VirtualMachine Admin role. Follow the steps to either
[verify](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vms/preparation#verify-user-access)
or have your Project IAM Admin
[assign](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vms/preparation#grant-user-access-vm-resources)
you the Project VirtualMachine Admin (`project-vm-admin`) role in the namespace
of the project where the VM resides.

For VM operations using the GDC console or the gdcloud CLI,
request your Project IAM Admin to assign you both the
Project VirtualMachine Admin role and the Project Viewer (`project-viewer`)
role.

## Delete a VM

Delete a VM by using the GDC console or `kubectl`. The VM must not be
in a terminating or unknown state.

### Console

1. In the navigation menu, click **Virtual Machines \> Instances**.

2. In the list of VMs, select the checkbox for the VM that you want to delete.

3. Click **Delete**.

4. In the confirmation dialog, click **Delete**.

### gdcloud

To delete a VM:

    gdcloud compute instances delete VM_NAME --project PROJECT

- Replace `VM_NAME` with the name of the VM.
- Replace `PROJECT` with the name of the GDC project in which the VM lives.

### kubectl

1. Delete the VM:

       kubectl --kubeconfig MANAGEMENT_API_SERVER delete virtualmachines.virtualmachine.gdc.goog VM_NAME -n NAMESPACE_NAME

2. Replace `VM_NAME` and `NAMESPACE_NAME`
   with the name and namespace, respectively, of the VM.

3. Verify that you've deleted the VM:

       kubectl --kubeconfig MANAGEMENT_API_SERVER get virtualmachines.virtualmachine.gdc.goog VM_NAME -n PROJECT

   Replace <var translate="no">`PROJECT`</var> with the VM project name.