File size: 2,538 Bytes
e566277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Phase IV Helm Deploy Script
# Deploys the application using Helm

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
HELM_CHART="$PROJECT_ROOT/infra/helm/todo-app"
RELEASE_NAME="todo-app"
NAMESPACE="todo-app"

echo "========================================="
echo "Phase IV - Deploying with Helm"
echo "========================================="

# Check if helm is available
if ! command -v helm &> /dev/null; then
    echo "Error: helm not found. Please install helm first."
    exit 1
fi

# Check cluster connection
echo ""
echo "Checking cluster connection..."
if ! kubectl cluster-info &> /dev/null; then
    echo "Error: Cannot connect to Kubernetes cluster."
    exit 1
fi

echo "Cluster connected successfully."

# Create namespace if it doesn't exist
echo ""
echo "Ensuring namespace exists..."
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -

# Check if release exists
if helm release list -n "$NAMESPACE" 2>/dev/null | grep -q "$RELEASE_NAME"; then
    echo ""
    echo "Release '$RELEASE_NAME' exists. Upgrading..."
    helm upgrade "$RELEASE_NAME" "$HELM_CHART" --namespace "$NAMESPACE"
else
    echo ""
    echo "Installing new release..."
    helm install "$RELEASE_NAME" "$HELM_CHART" --namespace "$NAMESPACE"
fi

echo ""
echo "Waiting for deployments to be ready..."
kubectl wait --for=condition=ready pod -l app=postgres -n "$NAMESPACE" --timeout=60s || true
kubectl wait --for=condition=ready pod -l app=ollama -n "$NAMESPACE" --timeout=120s || true
kubectl wait --for=condition=ready pod -l app=backend -n "$NAMESPACE" --timeout=60s || true
kubectl wait --for=condition=ready pod -l app=chatbot -n "$NAMESPACE" --timeout=60s || true
kubectl wait --for=condition=ready pod -l app=frontend -n "$NAMESPACE" --timeout=60s || true

echo ""
echo "========================================="
echo "Deployment Complete!"
echo ""
echo "Helm Release:"
helm status "$RELEASE_NAME" -n "$NAMESPACE"

echo ""
echo "Pods:"
kubectl get pods -n "$NAMESPACE"

echo ""
echo "========================================="
echo "To access the application:"
echo "1. For local development, use port-forward:"
echo "   kubectl port-forward -n $NAMESPACE svc/frontend-service 3000:3000"
echo ""
echo "2. For production, configure an Ingress controller"
echo ""
echo "Upgrade: helm upgrade $RELEASE_NAME $HELM_CHART -n $NAMESPACE"
echo "Uninstall: helm uninstall $RELEASE_NAME -n $NAMESPACE"
echo "========================================="