Files
eveAI/k8s/dev/deploy-all-services.sh

242 lines
6.9 KiB
Bash
Executable File

#!/bin/bash
# Deploy All EveAI Dev Services Script
# File: deploy-all-services.sh
set -e
# Colors voor output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function voor colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if kubectl is pointing to the right cluster
check_cluster_context() {
print_status "Checking cluster context..."
CURRENT_CONTEXT=$(kubectl config current-context)
if [[ "$CURRENT_CONTEXT" != "kind-eveai-dev-cluster" ]]; then
print_error "Wrong cluster context: $CURRENT_CONTEXT"
print_error "Expected: kind-eveai-dev-cluster"
echo "Switch context with: kubectl config use-context kind-eveai-dev-cluster"
exit 1
fi
print_success "Using correct cluster context: $CURRENT_CONTEXT"
}
# Wait for pods to be ready
wait_for_pods() {
local namespace=$1
local app_label=$2
local timeout=${3:-300}
print_status "Waiting for $app_label pods to be ready..."
if kubectl wait --for=condition=Ready pods -l app=$app_label -n $namespace --timeout=${timeout}s; then
print_success "$app_label pods are ready"
return 0
else
print_error "$app_label pods failed to become ready within ${timeout}s"
return 1
fi
}
# Deploy services in correct order
deploy_infrastructure() {
print_status "Deploying infrastructure services (Redis, MinIO)..."
if kubectl apply -f redis-minio-services.yaml; then
print_success "Infrastructure services deployed"
else
print_error "Failed to deploy infrastructure services"
exit 1
fi
# Wait for infrastructure to be ready
wait_for_pods "eveai-dev" "redis" 180
wait_for_pods "eveai-dev" "minio" 300
}
deploy_application_services() {
print_status "Deploying EveAI application services..."
if kubectl apply -f eveai-services.yaml; then
print_success "Application services deployed"
else
print_error "Failed to deploy application services"
exit 1
fi
# Wait for key services to be ready
wait_for_pods "eveai-dev" "eveai-app" 180
wait_for_pods "eveai-dev" "eveai-api" 180
wait_for_pods "eveai-dev" "eveai-chat-client" 180
}
deploy_nginx_monitoring() {
print_status "Deploying Nginx and monitoring services..."
if kubectl apply -f nginx-monitoring-services.yaml; then
print_success "Nginx and monitoring services deployed"
else
print_error "Failed to deploy Nginx and monitoring services"
exit 1
fi
# Wait for nginx and monitoring to be ready
wait_for_pods "eveai-dev" "nginx" 120
wait_for_pods "eveai-dev" "prometheus" 180
wait_for_pods "eveai-dev" "grafana" 180
}
# Check service status
check_services() {
print_status "Checking service status..."
echo ""
print_status "Pods status:"
kubectl get pods -n eveai-dev
echo ""
print_status "Services status:"
kubectl get services -n eveai-dev
echo ""
print_status "Persistent Volume Claims:"
kubectl get pvc -n eveai-dev
}
# Test service connectivity
test_connectivity() {
print_status "Testing service connectivity..."
# Test endpoints that should respond
endpoints=(
"http://localhost:3080" # Nginx
"http://localhost:3001/healthz/ready" # EveAI App
"http://localhost:3003/healthz/ready" # EveAI API
"http://localhost:3004/healthz/ready" # Chat Client
"http://localhost:3009" # MinIO Console
"http://localhost:3010" # Prometheus
"http://localhost:3012" # Grafana
)
for endpoint in "${endpoints[@]}"; do
print_status "Testing $endpoint..."
if curl -f -s --max-time 10 "$endpoint" > /dev/null; then
print_success "$endpoint is responding"
else
print_warning "$endpoint is not responding (may still be starting up)"
fi
done
}
# Show connection information
show_connection_info() {
echo ""
echo "=================================================="
print_success "EveAI Dev Cluster deployed successfully!"
echo "=================================================="
echo ""
echo "🌐 Service URLs:"
echo " Main Application:"
echo " • Nginx Proxy: http://minty.ask-eve-ai-local.com:3080"
echo " • EveAI App: http://minty.ask-eve-ai-local.com:3001"
echo " • EveAI API: http://minty.ask-eve-ai-local.com:3003"
echo " • Chat Client: http://minty.ask-eve-ai-local.com:3004"
echo ""
echo " Infrastructure:"
echo " • Redis: redis://minty.ask-eve-ai-local.com:3006"
echo " • MinIO S3: http://minty.ask-eve-ai-local.com:3008"
echo " • MinIO Console: http://minty.ask-eve-ai-local.com:3009"
echo ""
echo " Monitoring:"
echo " • Flower (Celery): http://minty.ask-eve-ai-local.com:3007"
echo " • Prometheus: http://minty.ask-eve-ai-local.com:3010"
echo " • Grafana: http://minty.ask-eve-ai-local.com:3012"
echo ""
echo "🔑 Default Credentials:"
echo " • MinIO: minioadmin / minioadmin"
echo " • Grafana: admin / admin"
echo " • Flower: Felucia / Jungles"
echo ""
echo "🛠️ Management Commands:"
echo " • kubectl get all -n eveai-dev"
echo " • kubectl logs -f deployment/eveai-app -n eveai-dev"
echo " • kubectl describe pod <pod-name> -n eveai-dev"
echo ""
echo "🗂️ Data Persistence:"
echo " • Host data path: $HOME/k8s-data/dev/"
echo " • Logs path: $HOME/k8s-data/dev/logs/"
}
# Main execution
main() {
echo "=================================================="
echo "🚀 Deploying EveAI Dev Services to Kind Cluster"
echo "=================================================="
check_cluster_context
# Deploy in stages
deploy_infrastructure
print_status "Infrastructure deployment completed, proceeding with applications..."
sleep 5
deploy_application_services
print_status "Application deployment completed, proceeding with Nginx and monitoring..."
sleep 5
deploy_nginx_monitoring
print_status "All services deployed, running final checks..."
sleep 10
check_services
test_connectivity
show_connection_info
}
# Check for command line options
case "${1:-}" in
"infrastructure")
check_cluster_context
deploy_infrastructure
;;
"apps")
check_cluster_context
deploy_application_services
;;
"monitoring")
check_cluster_context
deploy_nginx_monitoring
;;
"status")
check_cluster_context
check_services
;;
"test")
test_connectivity
;;
*)
main "$@"
;;
esac