-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleanup_cluster.sh
38 lines (32 loc) · 1.1 KB
/
cleanup_cluster.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
35
36
37
38
#!/bin/bash
# Author: Jayden Kyaw Htet Aung
PROJECT_ID="helloworld041019"
region=$(gcloud config get-value compute/region)
#First we need to look for K8s services
command2=$(kubectl get services | awk 'NR ==2 {print $1;exist}')
export service=$(echo $command2)
#If serivices found, we'll start deleting
echo "Looking for services..."
if [ -z "$service" ]
then
echo "You don't have a service. Nothing to delete."
else
echo "Your have a k8s service called $service"
echo "Deleting service: $service"
kubectl delete service $service
echo "$service has been deleted"
fi
command1=$(gcloud container clusters list | awk 'NR ==2 {print $1;exist}')
export clustername=$(echo $command1)
echo "Looking for clusters..."
if [ -z "$clustername" ]
then
echo "You don't have a k8s cluster. Nothing to delete."
else
echo "Your have a GKE cluster called $clustername"
echo "Deleting GKE Cluster: $clustername"
gcloud container clusters delete $clustername --region $region
echo "$clustername has been deleted"
echo ".............................."
echo Deletion completed on `date`
fi