Skip to main content

Delete a cluster

This page covers the various available methods for deleting a cloud platform test cluster.

In most cases, it is recommended to pass responsibility for deleting a test cluster off to Concourse. It’s easy to make a mistake locally and end up deleting something you shouldn’t e.g. switching context to live whilst running a delete cluster in another terminal

Delete the cluster with Concourse delete-cluster pipeline

We have a dedicated pipeline for deleting test clusters. You can configure and trigger this pipeline against your test cluster for removal by utilising the associated cloud-platform cli pipeline delete-cluster command.

In order to use this command, ensure you have the following installed:

Execute the following command, providing the name of the cluster you wish to delete:

cloud-platform pipeline delete-cluster --cluster-name <cluster-name>

You’ll be prompted to authenticate to Concourse:

logging in to team 'main'
navigate to the following URL in your browser:
https://concourse.cloud-platform.service.justice.gov.uk/login?fly_port=12345

Once you click the link, fly will render the delete-cluster pipeline with your cluster name:

-       CLUSTER_NAME: ((cluster_name))
+       CLUSTER_NAME: <cluster-name>

And will then trigger the job:

configuration updated
started delete-cluster/delete #123

Additionally, if you’ve made changes in your infrastructure branch that render a destroy from the main branch impossible, you can optionally pass your branch name to use that terraform source instead:

cloud-platform pipeline delete-cluster --cluster-name <cluster-name> --branch-name <your-branch-name>

Delete an EKS cluster manually

Follow these steps, to delete the EKS cluster.

First, set the kubectl context for the EKS cluster you are deleting. The easiest way to do this is with aws command:

$ export KUBECONFIG=~/.kube/config
$ export cluster=<cluster-name>
$ aws eks --region eu-west-2 update-kubeconfig --name ${cluster}

You should see this output:

Added new context arn:aws:eks:eu-west-2:754256621582:cluster/<cluster-name> to .kube/config

Then, from the root of a checkout of the cloud-platform-infrastructure repository, run these commands to destroy all cluster components, and delete the terraform workspace:

$ cd terraform/aws-accounts/cloud-platform-aws/vpc/eks/components
$ terraform init
$ terraform workspace select ${cluster}
$ terraform destroy

The destroy process often gets stuck on prometheus operator. If that happens, running this in a separate window usually works: kubectl -n monitoring delete job prometheus-operator-operator-cleanup

$ terraform workspace select default
$ terraform workspace delete ${cluster}

Change directories and perform the following to destroy the EKS cluster, and delete the terraform workspace.

$ cd .. # working dir is now `eks`
$ terraform init
$ terraform workspace select ${cluster}
$ terraform destroy
$ terraform workspace select default
$ terraform workspace delete ${cluster}

Change directories and perform the following to destroy the cluster VPC, and delete the terraform workspace.

$ cd .. # working dir is now `vpc`
$ terraform init
$ terraform workspace select ${cluster}
$ terraform destroy
$ terraform workspace select default
$ terraform workspace delete ${cluster}
This page was last reviewed on 16 January 2024. It needs to be reviewed again on 16 July 2024 by the page owner #cloud-platform .
This page was set to be reviewed before 16 July 2024 by the page owner #cloud-platform. This might mean the content is out of date.