#!/bin/bash # Setup script voor EveAI Dev Kind Cluster # File: setup-dev-cluster.sh set -e echo "🚀 Setting up EveAI Dev Kind Cluster..." # 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 required tools are installed check_prerequisites() { print_status "Checking prerequisites..." if ! command -v kind &> /dev/null; then print_error "kind is not installed. Please install kind first." echo "Install via: go install sigs.k8s.io/kind@latest" exit 1 fi if ! command -v kubectl &> /dev/null; then print_error "kubectl is not installed. Please install kubectl first." exit 1 fi if ! command -v podman &> /dev/null; then print_error "podman is not installed. Please install podman first." exit 1 fi if ! command -v envsubst &> /dev/null; then print_error "envsubst is not installed. Please install envsubst first" fi print_success "All prerequisites are installed" } # Create host directories for persistent volumes create_host_directories() { print_status "Creating host directories for persistent storage..." BASE_DIR="$HOME/k8s-data/dev" directories=( "$BASE_DIR/minio" "$BASE_DIR/redis" "$BASE_DIR/logs" "$BASE_DIR/prometheus" "$BASE_DIR/grafana" "$BASE_DIR/certs" ) for dir in "${directories[@]}"; do if [ ! -d "$dir" ]; then mkdir -p "$dir" print_status "Created directory: $dir" else print_status "Directory already exists: $dir" fi done # Set proper permissions chmod -R 755 "$BASE_DIR" print_success "Host directories created and configured" } # Create Kind cluster create_cluster() { print_status "Creating Kind cluster..." if kind get clusters | grep -q "eveai-dev-cluster"; then print_warning "Cluster 'eveai-dev-cluster' already exists" echo -n "Do you want to delete and recreate it? (y/N): " read -r response if [[ "$response" =~ ^[Yy]$ ]]; then print_status "Deleting existing cluster..." kind delete cluster --name eveai-dev-cluster else print_status "Using existing cluster" return 0 fi fi KIND_CONFIG="kind-dev-cluster.yaml" if [ ! -f "${KIND_CONFIG}" ]; then print_error "Config '${KIND_CONFIG}' niet gevonden in $(pwd)" exit 1 fi print_status "Creating new Kind cluster with configuration..." # Genereer expanded config met envsubst EXPANDED_CONFIG="$(mktemp --suffix=.yaml)" envsubst < "${KIND_CONFIG}" > "${EXPANDED_CONFIG}" # Voorkeursmethode: start in user-scope met expliciete delegatie if command -v systemd-run >/dev/null 2>&1; then systemd-run --scope --user -p "Delegate=yes" \ env KIND_EXPERIMENTAL_PROVIDER=podman \ kind create cluster --name "${CLUSTER_NAME}" --config "${EXPANDED_CONFIG}" else # Fallback print_warning "Start zonder systemd-run scope; kan mislukken bij ontbrekende delegatie." kind create cluster --name "${CLUSTER_NAME}" --config "${EXPANDED_CONFIG}" fi # Cleanup temporary config rm -f "${EXPANDED_CONFIG}" # Wait for cluster to be ready print_status "Waiting for cluster to be ready..." kubectl wait --for=condition=Ready nodes --all --timeout=300s # Update CA certificates in Kind node print_status "Updating CA certificates in cluster..." docker exec eveai-dev-cluster-control-plane update-ca-certificates docker exec eveai-dev-cluster-control-plane systemctl restart containerd print_success "Kind cluster created successfully" } # Apply Kubernetes manifests apply_manifests() { print_status "Applying Kubernetes manifests..." # Apply in correct order manifests=( "persistent-volumes.yaml" "config-secrets.yaml" ) for manifest in "${manifests[@]}"; do if [ -f "$manifest" ]; then print_status "Applying $manifest..." kubectl apply -f "$manifest" else print_warning "Manifest $manifest not found, skipping..." fi done print_success "Base manifests applied successfully" } # Verify cluster status verify_cluster() { print_status "Verifying cluster status..." # Check nodes print_status "Cluster nodes:" kubectl get nodes # Check namespaces print_status "Namespaces:" kubectl get namespaces # Check persistent volumes print_status "Persistent volumes:" kubectl get pv # Check if registry is accessible from cluster print_status "Testing registry connectivity..." if kubectl run test-registry --image=registry.ask-eve-ai-local.com/josakola/nginx:latest --dry-run=server &> /dev/null; then print_success "Registry is accessible from cluster" kubectl delete pod test-registry --ignore-not-found=true &> /dev/null || true else print_warning "Registry connectivity test failed - this might be expected if images aren't pushed yet" fi } # Main execution main() { echo "==================================================" echo "🏗️ EveAI Dev Kind Cluster Setup" echo "==================================================" check_prerequisites create_host_directories create_cluster apply_manifests verify_cluster echo "" echo "==================================================" print_success "EveAI Dev Kind Cluster setup completed!" echo "==================================================" echo "" echo "📋 Next steps:" echo "1. Deploy your application services using the service manifests" echo "2. Configure DNS entries for local development" echo "3. Access services via the mapped ports (3000-3999 range)" echo "" echo "🔧 Useful commands:" echo " kubectl config current-context # Verify you're using the right cluster" echo " kubectl get all -n eveai-dev # Check all resources in dev namespace" echo " kind delete cluster --name eveai-dev-cluster # Delete cluster when done" echo "" echo "📊 Port mappings:" echo " - Nginx: 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 " - MinIO Console: http://minty.ask-eve-ai-local.com:3009" echo " - Grafana: http://minty.ask-eve-ai-local.com:3012" } # Run main function main "$@"