Clean up resources

To avoid unexpected costs after completing the lab, you need to clean up resources in the following order:

1. Delete CI/CD resources (Eks-stack)

  1. Open the AWS CloudFormation console
  2. On the Stacks page, select the Eks-stack stack (or the stack name you configured in the previous step).
  3. Select Delete and confirm deletion to clean up CodePipeline, CodeBuild.

2. Delete ECR Repository

  1. Open the Amazon ECR console page
  2. On the navigation bar, select the Region containing your repository.
  3. Select Private registry, then select Repositories.
  4. Select the Repository you created (e.g., 000062-websource) and click Delete.
  5. Type delete to verify and select Delete.

3. Delete Artifact Storage S3 Bucket

  1. Open the Amazon S3 console page.
  2. Find the bucket you created in section 4.1 (name format eks-[Account_ID]-codepipeline-artifacts).
  3. Select that bucket and click Empty to delete all artifact files inside. Type permanently delete to confirm.
  4. After the bucket is empty, go back to the list, select that bucket and click Delete, type the bucket name to confirm deletion.

4. Delete LoadBalancer Service and EKS Security Group

The LoadBalancer created by EKS will not be automatically deleted by CloudFormation and will cause errors when deleting the VPC. You must delete it first:

  1. Run the following command in the VS Code terminal:
kubectl delete svc fcj-workshop
  1. (If the EKS Cluster has encountered an error and cannot run the above command): You must go to the EC2 Console interface, find the Load Balancers section, select the Load Balancer of EKS and click Delete. Then, go to the Security Groups section, find the Security Group containing k8s-elb in its name (belonging to the just deleted Load Balancer) and click Delete security groups. This helps to completely release the VPC network, avoiding DELETE_FAILED errors on CloudFormation.

5. Delete EKS Cluster

To completely delete the EKS Cluster, we will delete the stacks that eksctl has created:

  1. Go back to the AWS CloudFormation page.
  2. Find and select the Node Group stack (e.g., eksctl-k8s-demo-nodegroup-k8s-demo), click Delete. Wait until the status reports DELETE_COMPLETE.
  3. After the Node Group has been deleted, continue to select the Cluster stack (e.g., eksctl-k8s-demo-cluster) and click Delete.

(Alternatively, you can run the command eksctl delete cluster --name k8s-demo from the terminal if the Workspace machine is still open).

6. Delete EC2 Workspace instance

Perform this step last because it will disconnect your VS Code:

  1. On the CloudFormation Console interface.
  2. Select the ekscicd-workspace stack (the stack that provisioned EC2 in the prerequisite section).
  3. Select Delete and confirm deleting the stack. This operation will completely clean up the EC2 instance and its associated Security Group.