Amazon EKS — Cleanup Cluster

2 minute read

Cleanup Cluster

This is the most important page in this chapter. Forgetting to delete your EKS cluster is the #1 reason for unexpected AWS bills. A minimal cluster costs ~$170/month if left running.


Delete the Entire Cluster

$ eksctl delete cluster --name demo --region us-east-1

Expected output:

2024-01-15 11:00:00 [ℹ]  deleting EKS cluster "demo"
2024-01-15 11:00:01 [ℹ]  will drain 0 unmanaged nodegroup(s) in cluster "demo"
2024-01-15 11:00:01 [ℹ]  deleted 0 Fargate profile(s)
2024-01-15 11:00:02 [✔]  kubeconfig has been updated
2024-01-15 11:00:02 [ℹ]  cleaning up AWS load balancers created by Kubernetes objects of type Service or Ingress
2024-01-15 11:02:30 [ℹ]  2 sequential tasks: { delete nodegroup "demo-nodes", delete cluster control plane "demo" }
2024-01-15 11:02:30 [ℹ]  will delete stack "eksctl-demo-nodegroup-demo-nodes"
2024-01-15 11:05:00 [ℹ]  will delete stack "eksctl-demo-cluster"
2024-01-15 11:10:00 [✔]  all cluster resources were deleted

This takes ~10 minutes and deletes:

  • Worker nodes (EC2 instances)
  • Node group
  • EKS cluster
  • IAM roles
  • Security groups
  • NAT Gateways
  • VPC and subnets
  • CloudFormation stacks

Verify Deletion

# Should return empty or "not found"
$ aws eks describe-cluster --name demo --region us-east-1
An error occurred (ResourceNotFoundException) when calling the DescribeCluster operation: No cluster found for name: demo.

# Check for lingering CloudFormation stacks
$ aws cloudformation list-stacks \
    --query "StackSummaries[?contains(StackName, 'eksctl-demo') && StackStatus!='DELETE_COMPLETE']"
[]

What If Delete Gets Stuck?

Sometimes eksctl delete cluster hangs because of leftover resources:

Check for Leftover Load Balancers

# List load balancers in the VPC
$ aws elbv2 describe-load-balancers --query 'LoadBalancers[?VpcId==`vpc-xxxx`]'

# Delete manually if found
$ aws elbv2 delete-load-balancer --load-balancer-arn <arn>

Check for Leftover ENIs

# Find ENIs in the VPC
$ aws ec2 describe-network-interfaces --filters "Name=vpc-id,Values=vpc-xxxx"

Force Delete CloudFormation Stack

$ aws cloudformation delete-stack --stack-name eksctl-demo-cluster

Cost-Saving Tips

Strategy Savings
Delete clusters after each practice session 100% when not in use
Use a single NAT Gateway for dev ~$64/month
Use Spot instances 60-90% on compute
Set a billing alarm Early warning before surprise bill

Set a Billing Alarm

$ aws cloudwatch put-metric-alarm \
    --alarm-name "EKS-Billing-Alarm" \
    --metric-name EstimatedCharges \
    --namespace AWS/Billing \
    --statistic Maximum \
    --period 21600 \
    --threshold 50 \
    --comparison-operator GreaterThanThreshold \
    --evaluation-periods 1 \
    --alarm-actions arn:aws:sns:us-east-1:123456789012:billing-alerts \
    --dimensions Name=Currency,Value=USD

Common Mistakes

Mistake Impact
Forgetting to delete test clusters $170+/month per cluster
Deleting cluster but not LBs/EBS Orphaned resources keep charging
Deleting from wrong region Cluster still runs in correct region
Not checking CloudFormation stacks Failed delete leaves partial resources

Quick Reference

# Delete cluster
$ eksctl delete cluster --name demo --region us-east-1

# Verify deletion
$ aws eks describe-cluster --name demo --region us-east-1

# Check for orphaned resources
$ aws cloudformation list-stacks --query "StackSummaries[?contains(StackName, 'eksctl-demo')]"

# List EKS clusters (should not show demo)
$ aws eks list-clusters --region us-east-1

What’s Next?

Try the First Cluster Exercises to solidify your skills. Then move on to Chapter 4 — Architecture Deep Dive.