This topic describes how to uninstall GKE on AWS.

## Before you begin

To perform these steps,
[authenticate to your GKE on AWS management service](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management.md.txt#connect).

To connect to your GKE on AWS resources, perform the following
steps. Select if you have an existing AWS VPC (or direct connection to
your VPC) or created a dedicated VPC when creating your management service.

### Existing VPC

If you have a direct or VPN connection to an existing VPC, omit the line
`env HTTP_PROXY=http://localhost:8118` from commands in this topic.

### Dedicated VPC

When you create a management service in a dedicated VPC,
GKE on AWS includes a
[bastion](https://en.wikipedia.org/wiki/Bastion_host) host in a
public subnet.

> [!IMPORTANT]
> **Important:** If you restart your terminal session or the SSH connection is lost, you need to re-launch the `bastion-tunnel.sh` script.

To connect to your management service, perform the following steps:

1. Change to the directory with your GKE on AWS configuration.
   You created this directory when
   [Installing the management service](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management.md.txt).

   ```sh
   cd anthos-aws
   ```

   <br />

2. To open the tunnel, run the `bastion-tunnel.sh` script. The tunnel forwards
   to `localhost:8118`.

   To open a tunnel to the bastion host, run the following command:

   ```bash
   ./bastion-tunnel.sh -N
   ```

   Messages from the SSH tunnel appear in this window. When you are ready to
   close the connection, stop the process by using <kbd>Control+C</kbd> or
   closing the window.
3. Open a new terminal and change into your `anthos-aws` directory.

   ```sh
   cd anthos-aws
   ```
4. Check that you're able to connect to the cluster with `kubectl`.

   ```bash
   env HTTPS_PROXY=http://localhost:8118 \
   kubectl cluster-info
   ```

   The output includes the URL for the management service API server.

## Deleting user clusters

You use `kubectl` to delete user clusters. GKE on AWS gracefully
shuts down all nodes. Pods receive a `SIGTERM` and then, after a grace period, a
`SIGKILL`. After the pods stop, the management service starts removing AWS
resources.

> [!IMPORTANT]
> **Important:** If you do not delete all your user clusters and their associated resources, you cannot use `anthos-gke` to [remove the management service](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/uninstalling.md.txt#removing_a_management_service).

To delete a user cluster, perform the following steps:

1. From your `anthos-aws` directory, use
   `anthos-gke` to switch context to your user cluster.

   ```sh
   cd anthos-aws
   env HTTPS_PROXY=http://localhost:8118 \
     anthos-gke aws clusters get-credentials CLUSTER_NAME
   ```
   Replace <var translate="no">CLUSTER_NAME</var> with your user cluster name.

   <br />

2. Delete any [Load balancers](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/loadbalancer.md.txt)
   [Ingress](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/ingress.md.txt), or
   [PersistentVolumeClaim](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#lifecycle-of-a-volume-and-claim)
   resources you created.

   1. Use the following `kubectl` command to check if there are any remaining
      load balancer Services on your user cluster:

      ```bash
      env HTTPS_PROXY=http://localhost:8118 \
        kubectl get services
      ```
   2. Use the following `kubectl` command to check if there are any remaining
      PersistentVolumeClaims on your user cluster:

      ```bash
      env HTTPS_PROXY=http://localhost:8118 \
        kubectl get persistentvolumeclaim
      ```
   3. Use `kubectl delete` to delete any remaining Services or
      PersistentVolumeClaims you created. For example, to delete the
      LoadBalancer `my-lb-service`, run the following command:

      ```bash
      env HTTPS_PROXY=http://localhost:8118 \
        kubectl delete service my-lb-service
      ```

      For example, to delete the
      PersistentVolumeClaims `my-pvc`, run the following command:

      ```bash
      env HTTPS_PROXY=http://localhost:8118 \
      kubectl delete persistentvolumeclaim my-pvc
      ```
3. From your `anthos-aws` directory, use
   `anthos-gke` to switch context to your management service.

   ```sh
   cd anthos-aws
   anthos-gke aws management get-credentials
   ```

   > [!NOTE]
   > **Note:** `anthos-gke` uses the credentials you specified when you ran `aws configure`.

   <br />

4. Delete all AWSNodePools with `kubectl`.

   ```bash
   env HTTPS_PROXY=http://localhost:8118 \
     kubectl delete AWSNodePool --all
   ```
5. Delete all AWSCluster with `kubectl`.

   ```bash
   env HTTPS_PROXY=http://localhost:8118 \
     kubectl delete AWSCluster --all
   ```

## Removing a management service

You use `anthos-gke` to delete the management service.

1. Change directory to the folder you created
   during [installation](https://docs.cloud.google.com/kubernetes-engine/multi-cloud/docs/aws/previous-generation/how-to/installing-management.md.txt#configure).

2. Use `anthos-gke` to delete resources for the management service.

   ```bash
   env HTTP_PROXY=http://localhost:8118 \
     anthos-gke aws management delete
   ```

   > [!NOTE]
   > **Note:** The previous command uses the `HTTP_PROXY` environment variable instead of `HTTPS_PROXY`. The uninstallation process doesn't complete when using the `HTTPS_PROXY` environment variable.

## Removing the AWS S3 bucket

When you create a management service, `anthos-gke` creates an S3 bucket on AWS
with binaries for cluster creation. The bucket is reused when you create new
user clusters. If you are no longer using GKE on AWS, you can
remove the bucket after you delete your management service.

To delete the GKE on AWS S3 bucket, perform the following steps:

1. To find the bucket's name, find the value of `gcs_download_bucket` in
   `terraform-workspace/terraform.tfvars.json` with `grep`.

   ```bash
   grep agent_s3_bucket terraform.tfvars.json
   ```
2. Delete this s3 bucket and its contents with the `aws` command, replacing
   <var translate="no">bucket-name</var> with the name of your bucket from the previous
   command.

   ```bash
   aws s3 rb s3://bucket-name --force
   ```