-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·115 lines (91 loc) · 3.71 KB
/
deploy.sh
File metadata and controls
executable file
·115 lines (91 loc) · 3.71 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Build and deploy all initial services to minikube
set -e
echo "🚀 Building and deploying nginx cookie routing system..."
# Use specific profile for this project
PROFILE="nginx-cookie-routing"
# Clean start - run cleanup script for fresh environment
echo "🧹 Running cleanup for fresh start..."
./cleanup.sh
echo "Starting fresh minikube cluster with profile: $PROFILE..."
minikube start -p $PROFILE
echo "Enabling ingress addon..."
minikube addons enable ingress -p $PROFILE
echo "⏳ Waiting for ingress controller to be ready..."
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=300s
echo "Waiting for ingress controller webhook to be available..."
kubectl wait --namespace ingress-nginx \
--for=condition=available deployment/ingress-nginx-controller \
--timeout=300s
# Additional check: verify the webhook service is reachable
echo "Verifying ingress controller webhook service..."
kubectl get service -n ingress-nginx ingress-nginx-controller-admission
if [ $? -ne 0 ]; then
echo "⚠️ Warning: Ingress controller admission service not found"
echo "Waiting additional 30 seconds for ingress controller to stabilize..."
sleep 30
fi
# Set docker environment to use minikube's docker daemon
eval $(minikube docker-env -p $PROFILE)
echo "📦 Building Docker images..."
# Build Express server image
echo "Building Express server image..."
cd express
docker build -t express-server:latest .
cd ..
# Build Nginx router image
echo "Building Nginx router image..."
cd nginx
docker build -t nginx-cookie-router:latest .
cd ..
echo "🔧 Deploying to Kubernetes..."
# Deploy namespaces first
kubectl apply -f k8s/namespaces.yaml
# Deploy RBAC resources
kubectl apply -f k8s/rbac.yaml
# Deploy services
kubectl apply -f k8s/services.yaml
# Deploy main components
kubectl apply -f k8s/deployments.yaml
# Deploy ingress
kubectl apply -f k8s/ingress.yaml
echo "⏳ Waiting for deployments to be ready..."
kubectl wait --for=condition=available --timeout=300s deployment/nginx-router -n nginx-namespace
kubectl wait --for=condition=available --timeout=300s deployment/express-server-main -n main-namespace
echo "🎉 Deployment completed!"
echo ""
echo "🌐 To access the application:"
echo " minikube tunnel (in a separate terminal)"
echo " or"
echo " kubectl port-forward service/nginx-service 8080:80 -n nginx-namespace"
echo ""
echo "🧪 Test URLs:"
echo " # Default routing (no cookie):"
echo " curl http://localhost:8080/"
echo ""
echo " # tag-specific routing (if ephemeral instances were deployed):"
echo " curl -H 'Cookie: deployment_tag_cookie=a' http://localhost:8080/"
echo " curl -H 'Cookie: deployment_tag_cookie=b' http://localhost:8080/"
echo " curl -H 'Cookie: deployment_tag_cookie=c' http://localhost:8080/"
echo ""
echo "🚀 Create ephemeral deployments:"
echo " ./ephemeral.sh --tag=<tag> # Deploy ephemeral instance"
echo " ./ephemeral.sh --tag=<tag> --delete # Delete ephemeral instance"
echo ""
echo "📊 Check status:"
echo " kubectl get pods"
echo " kubectl get services"
# Check if port-forward is already running on port 8080
PORT_FORWARD_PID=$(ps aux | grep "kubectl port-forward.*nginx-service.*8080:80" | grep -v grep | awk '{print $2}')
if [ -n "$PORT_FORWARD_PID" ]; then
echo "✅ Port-forward to nginx-namespace already running (PID: $PORT_FORWARD_PID)"
echo " Application accessible at: http://localhost:8080"
else
echo "🔗 Starting port-forward to nginx-namespace..."
echo " Application will be accessible at: http://localhost:8080"
echo " Press Ctrl+C to stop port-forwarding"
kubectl port-forward service/nginx-service 8080:80 -n nginx-namespace
fi