zkt25/z2/start-app.sh

42 lines
1.3 KiB
Bash

#!/bin/bash
echo "Start Kubernetes objects "
# Apply Kubernetes resources
kubectl apply -f k8s/namespace.yaml
kubectl apply -f k8s/persistant-volume.yaml
kubectl apply -f k8s/persistant-volume-claim.yaml
kubectl apply -f k8s/postgres-service.yaml
kubectl apply -f k8s/statefulset.yaml
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
echo "Kubernetes objects are applied. Waiting for pods to be ready..."
# Wait for all pods in the namespace to be in Running state
namespace="travel-planner"
timeout=300 # Timeout in seconds
interval=5 # Interval between checks
for ((i=1; i<=$timeout; i+=$interval)); do
ready_pods=$(kubectl get pods -n $namespace --field-selector=status.phase=Running --no-headers | wc -l)
total_pods=$(kubectl get pods -n $namespace --no-headers | wc -l)
if [ "$ready_pods" -eq "$total_pods" ] && [ "$total_pods" -gt 0 ]; then
echo "All pods are ready!"
break
fi
echo "Waiting for pods to be ready... ($ready_pods/$total_pods)"
sleep $interval
done
if [ "$ready_pods" -ne "$total_pods" ]; then
echo "Timeout reached. Some pods are not ready."
kubectl get pods -n $namespace
exit 1
fi
echo "App is running."
echo "Go here to view the app"
minikube service travel-planner -n travel-planner --url