Deleting a cluster
This page shows how to delete a cluster with everything in it: the VPC, the EKS cluster, the load balancers, the database, the file storage, the VPN and the alarms. The rest of the hosting, such as the users, the backups and the other clusters, stays.
Deleting a cluster deletes the databases and the uploaded files of every project on it, and AWS doesn't keep a final snapshot of the database. Only the backups in the S3 buckets backups.database.<hosted zone> and backups.files.<hosted zone> remain. Make sure they are recent, or move the projects to another cluster first.
Before you start
- You are in administrators in main.tf, with a session from hosty auth.
- You are connected to the VPN of the cluster, if it has VPN-only access.
- tofu plan shows no changes.
1. Delete the environments
List all environments on the cluster:
aws eks update-kubeconfig --name <cluster> --region <cluster region>
helm list --all-namespacesDelete every environment of every project, production ones included, as described in Deleting a project. This way each production environment gets its last backup, and the AWS Load Balancer Controller removes what it created for the environments in AWS. Leftovers like its security groups can stop OpenTofu from deleting the VPC.
2. Open the API of the cluster
The VPN is deleted together with the cluster, and OpenTofu loses the connection to the cluster halfway if it goes through the VPN. Disable VPN-only access first.
3. Turn off the deletion protection of the database
The database has deletion protection, so that nobody deletes it by mistake. In the AWS Console, in the region of the cluster:
- Open RDS > Databases and select the cluster <cluster>-database.
- Click Modify, clear Enable deletion protection and click Continue.
- Choose Apply immediately and click Modify cluster.
4. Delete the cluster
cd /src/terraform
tofu destroy -target=module.cluster_<cluster>For example, tofu destroy -target=module.cluster_phoenix. Check the list of resources and type yes to confirm. It takes a while, usually more than 15 minutes. Don't interrupt it.
5. Update main.tf
In terraform/main.tf:
- remove the module "cluster_<cluster>" block;
- remove the projects of this cluster from projects, or move them to another cluster;
- remove the import blocks that point to module.cluster_<cluster>, if there are any.
Then apply the changes:
tofu applyIf you removed projects, this deletes their IAM groups, ECR repositories and SSL certificates. After that, tofu plan should show no changes.