-
Notifications
You must be signed in to change notification settings - Fork 16
/
ee-eks-destroy.sh
executable file
·34 lines (27 loc) · 1.89 KB
/
ee-eks-destroy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
starttime=$(date +%s)
. ./setenv.sh
echo '-------Deleting the EKS Cluster (typically in ~ 10 mins)'
echo '-------Deleting AWS IAM role and policy'
aws iam delete-role-policy --role-name k10-iam-role4yong1 --policy-name k10-iam-policy4yong1
aws iam delete-role --role-name k10-iam-role4yong1
clusterid=$(kubectl get namespace default -ojsonpath="{.metadata.uid}{'\n'}")
eksctl delete cluster --name $(cat k10_eks_clustername) --region $AWS_REGION
echo '-------Deleting EBS Volumes'
aws ec2 describe-volumes --region $AWS_REGION --query "Volumes[*].{ID:VolumeId}" --filters Name=tag:eks:cluster-name,Values=$(cat k10_eks_clustername) | grep ID | awk '{print $2}' > ebs.list
aws ec2 describe-volumes --region $AWS_REGION --query "Volumes[*].{ID:VolumeId}" --filters Name=tag:kubernetes.io/cluster/$(cat k10_eks_clustername),Values=owned | grep ID | awk '{print $2}' >> ebs.list
for i in $(sed 's/\"//g' ebs.list);do echo $i;aws ec2 delete-volume --volume-id $i --region $AWS_REGION;done
echo '-------Deleting snapshots'
aws ec2 describe-snapshots --owner self --query "Snapshots[*].{ID:SnapshotId}" --filters Name=tag:kanister.io/clustername,Values=$clusterid --region $AWS_REGION | grep ID | awk '{print $2}' > ebssnap.list
for i in $(sed 's/\"//g' ebssnap.list);do echo $i;aws ec2 delete-snapshot --snapshot-id $i --region $AWS_REGION;done
echo '-------Deleting objects from the bucket'
aws s3 rb s3://$(cat k10_eks_bucketname) --force
echo '-------Deleting kubeconfig for this cluster'
kubectl config delete-context $(kubectl config get-contexts | grep $(cat k10_eks_clustername) | awk '{print $2}')
echo "" | awk '{print $1}'
endtime=$(date +%s)
duration=$(( $endtime - $starttime ))
echo "-------Total time is $(($duration / 60)) minutes $(($duration % 60)) seconds."
echo "" | awk '{print $1}'
echo "-------Created by Yongkang"
echo "-------Email me if any suggestions or issues [email protected]"
echo "" | awk '{print $1}'