zkt26/z2/start-app.sh

68 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# =============================================================================
# start-app.sh — Deploy all Kubernetes objects for the Task Manager
#
# Applies manifests in the correct dependency order:
# 1. Namespace
# 2. Secret + ConfigMap
# 3. PersistentVolumes + PersistentVolumeClaims (inside StatefulSet file)
# 4. StatefulSets (postgres, redis)
# 5. Deployments (api, frontend, adminer)
# 6. Services
#
# The script waits for the StatefulSets to be Ready before continuing so
# the API does not fail its readiness probe immediately.
# =============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NS="taskmanager"
echo "============================================="
echo " Starting Task Manager on Kubernetes..."
echo "============================================="
echo ""
echo "[1/6] Creating Namespace..."
kubectl apply -f "$SCRIPT_DIR/namespace.yaml"
echo "[2/6] Applying Secrets and ConfigMaps..."
kubectl apply -f "$SCRIPT_DIR/configmap-secret.yaml"
echo "[3/6] Applying PersistentVolumes, PVCs and StatefulSets..."
kubectl apply -f "$SCRIPT_DIR/statefulset.yaml"
echo "[4/6] Waiting for postgres StatefulSet to be Ready..."
kubectl rollout status statefulset/postgres -n $NS --timeout=120s
echo " Waiting for redis StatefulSet to be Ready..."
kubectl rollout status statefulset/redis -n $NS --timeout=60s
echo "[5/6] Applying Deployments..."
kubectl apply -f "$SCRIPT_DIR/deployment.yaml"
echo "[6/6] Applying Services..."
kubectl apply -f "$SCRIPT_DIR/service.yaml"
echo ""
echo "Waiting for API deployment to be ready..."
kubectl rollout status deployment/taskmanager-api -n $NS --timeout=120s
# Determine the node IP for NodePort access
NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}' 2>/dev/null || echo "localhost")
echo ""
echo "============================================="
echo " ✓ Task Manager is running!"
echo ""
echo " 🌐 Task Manager: http://${NODE_IP}:30080"
echo " 🗄️ Adminer (DB): http://${NODE_IP}:30081"
echo ""
echo " Adminer login:"
echo " System: PostgreSQL"
echo " Server: postgres"
echo " Username: taskuser"
echo " Password: taskpass"
echo " Database: taskmanager"
echo "============================================="