zkt25/z2/stop-app.sh

47 lines
1.2 KiB
Bash

#!/bin/bash
echo "Stopping Kubernetes objects..."
# Namespace variable
namespace="travel-planner"
# Delete resources in the namespace
kubectl delete -f k8s/service.yaml -n $namespace
kubectl delete -f k8s/deployment.yaml -n $namespace
kubectl delete -f k8s/postgres-service.yaml -n $namespace
kubectl delete -f k8s/persistant-volume-claim.yaml -n $namespace
kubectl delete -f k8s/persistant-volume.yaml -n $namespace
kubectl delete -f k8s/statefulset.yaml -n $namespace
# Delete namespace last
kubectl delete -f k8s/namespace.yaml
# Check if namespace is fully deleted
timeout=60
for ((i=1; i<=$timeout; i++)); do
if ! kubectl get namespace $namespace &> /dev/null; then
echo "Namespace $namespace successfully deleted."
break
fi
echo "Waiting for namespace $namespace to be deleted..."
sleep 1
done
if kubectl get namespace $namespace &> /dev/null; then
echo "Error: Namespace $namespace was not deleted within the timeout."
exit 1
fi
echo "All Kubernetes objects have been deleted."
# Stop Minikube
echo "Stopping Minikube..."
minikube stop
if [ $? -eq 0 ]; then
echo "Minikube stopped successfully."
else
echo "Error: Failed to stop Minikube."
exit 1
fi
echo "Application and Minikube stopped successfully."