-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·150 lines (122 loc) · 5.03 KB
/
setup.sh
File metadata and controls
executable file
·150 lines (122 loc) · 5.03 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# Complete Kubernetes Setup Script for Split App
# This script sets up all three services with Minikube and LoadBalancer
set -e
echo "=========================================="
echo "Split App Kubernetes Setup"
echo "=========================================="
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Step 1: Start Minikube
echo -e "${YELLOW}Step 1: Starting Minikube...${NC}"
minikube start --cpus=4 --driver=docker
# Step 2: Set Docker environment to use Minikube's Docker daemon
echo -e "${YELLOW}Step 2: Setting Docker environment...${NC}"
eval $(minikube docker-env)
# Step 3: Build Docker images
echo -e "${YELLOW}Step 3: Building Docker images...${NC}"
echo "Building auth-service..."
cd auth
docker build -t auth-service:latest .
cd ..
echo "Building split-data-service..."
cd split_data
docker build -t split-data-service:latest .
cd ..
echo "Building split-service..."
cd split_service
docker build -t split-service:latest .
cd ..
# Step 4: Create k8s directory and copy all YAML files
echo -e "${YELLOW}Step 4: Setting up Kubernetes manifests...${NC}"
mkdir -p k8s
# Note: You need to have all the YAML files in the k8s directory before running this script
# Step 5: Apply Kubernetes configurations
echo -e "${YELLOW}Step 5: Applying Kubernetes configurations...${NC}"
echo "Creating namespace..."
kubectl apply -f k8s/00-namespace.yaml
echo "Creating ConfigMaps..."
kubectl apply -f k8s/01-configmap-auth.yaml
kubectl apply -f k8s/02-configmap-split-data.yaml
kubectl apply -f k8s/03-configmap-split-service.yaml
echo "Creating Secrets..."
kubectl apply -f k8s/04-secrets.yaml
echo "Creating Persistent Volume Claims..."
kubectl apply -f k8s/05-persistent-volumes.yaml
echo "Deploying databases..."
echo " - MongoDB (for auth-service)"
kubectl apply -f k8s/06-mongodb-deployment.yaml
echo " - MySQL Shared (for split-data and split-service)"
kubectl apply -f k8s/07-mysql-shared-deployment.yaml
echo "Waiting for databases to be ready..."
kubectl wait --for=condition=ready pod -l app=mongodb -n split-app --timeout=120s || {
echo -e "${RED}MongoDB failed to start. Check logs:${NC}"
kubectl logs -l app=mongodb -n split-app --tail=50
exit 1
}
kubectl wait --for=condition=ready pod -l app=mysql-shared -n split-app --timeout=120s || {
echo -e "${RED}MySQL failed to start. Check logs:${NC}"
kubectl logs -l app=mysql-shared -n split-app --tail=50
exit 1
}
echo -e "${GREEN}Databases are ready!${NC}"
echo "Deploying application services..."
kubectl apply -f k8s/09-auth-deployment.yaml
kubectl apply -f k8s/10-split-data-deployment.yaml
kubectl apply -f k8s/11-split-service-deployment.yaml
echo "Waiting for application services to be ready..."
sleep 10
kubectl wait --for=condition=ready pod -l app=auth-service -n split-app --timeout=180s || {
echo -e "${RED}Auth service failed to start. Check logs:${NC}"
kubectl logs -l app=auth-service -n split-app --tail=50
}
kubectl wait --for=condition=ready pod -l app=split-data-service -n split-app --timeout=180s || {
echo -e "${RED}Split-data service failed to start. Check logs:${NC}"
kubectl logs -l app=split-data-service -n split-app --tail=50
}
echo -e "${YELLOW}Note: Split-service may take longer or be in CrashLoopBackOff - this is expected${NC}"
kubectl wait --for=condition=ready pod -l app=split-service -n split-app --timeout=180s || {
echo -e "${YELLOW}Split service is still starting (this is normal)${NC}"
}
echo "Creating LoadBalancer services..."
kubectl apply -f k8s/13-loadbalancer-services.yaml
# Step 6: Display service information
echo ""
echo -e "${YELLOW}Step 6: Service Information${NC}"
echo "=========================================="
kubectl get all -n split-app
echo ""
echo -e "${GREEN}Setup Complete!${NC}"
echo ""
echo "Database Architecture:"
echo " - MongoDB: Used by auth-service only"
echo " - MySQL Shared: Used by BOTH split-data-service and split-service"
echo ""
echo -e "${YELLOW}IMPORTANT: To access your services, you need to run minikube tunnel${NC}"
echo -e "${YELLOW}Open a NEW terminal and run:${NC}"
echo -e "${GREEN} minikube tunnel${NC}"
echo -e "${YELLOW}(Keep that terminal running and enter your sudo password when prompted)${NC}"
echo ""
echo "Then access your services at:"
echo " Auth Service: http://127.0.0.1:8080"
echo " Split Data Service: http://127.0.0.1:8082"
echo " Split Service: http://127.0.0.1:8081"
echo ""
echo "Test your APIs:"
echo " curl http://127.0.0.1:8080/health"
echo " curl http://127.0.0.1:8080/"
echo " curl http://127.0.0.1:8082/health"
echo " curl http://127.0.0.1:8081/api/health"
echo ""
echo "Useful commands:"
echo " View pods: kubectl get pods -n split-app"
echo " View services: kubectl get svc -n split-app"
echo " View logs: kubectl logs -f <pod-name> -n split-app"
echo " MySQL logs: kubectl logs -f -l app=mysql-shared -n split-app"
echo " Minikube dashboard: minikube dashboard"
echo ""
echo -e "${GREEN}Don't forget to run 'minikube tunnel' in a separate terminal!${NC}"
echo ""