-
Notifications
You must be signed in to change notification settings - Fork 6
/
gke-destroy.sh
executable file
·32 lines (26 loc) · 1.47 KB
/
gke-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
starttime=$(date +%s)
. ./setenv.sh
echo '-------Deleting the GKE Cluster (typically in few mins)'
TEMP_PREFIX=$(echo $(whoami) | sed -e 's/\_//g' | sed -e 's/\.//g' | awk '{print tolower($0)}')
FIRST3=$(echo -n $TEMP_PREFIX | head -c3)
LAST3=$(echo -n $TEMP_PREFIX | tail -c3)
MY_PREFIX=$(echo $FIRST3$LAST3)
gkeclustername=$(gcloud container clusters list --format="value(name)" --filter="$MY_PREFIX-$MY_CLUSTER")
gcloud container clusters delete $gkeclustername --zone $MY_ZONE --quiet
findmydisk=$(echo $MY_PREFIX-$MY_CLUSTER | head -c 12)
echo '-------Deleting disks'
for i in $(gcloud compute disks list --format="value(name)" --filter="yong-postgresql");do echo $i;gcloud compute disks delete $i --zone=$MY_ZONE -q;done
echo '-------Deleting snapshots'
for i in $(gcloud compute snapshots list --format="value(name)" --filter="GCE-PD CSI Driver");do echo $i;gcloud compute snapshots delete $i -q;done
echo '-------Deleting the bucket'
myproject=$(gcloud config get-value core/project)
gsutil -m rm -r gs://$MY_PREFIX-$MY_BUCKET
echo '-------Deleting kubeconfig for this cluster'
kubectl config delete-context $(kubectl config get-contexts | grep $MY_PREFIX-$MY_CLUSTER | 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 he@yongkang.cloud"