-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·96 lines (80 loc) · 3.27 KB
/
setup.sh
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
#!/bin/bash
echo "Checking Dapr status in the cluster..."
DAPR_STATUS=$(dapr status -k 2>&1)
set -e
if echo "$DAPR_STATUS" | grep -q "No status returned. Is Dapr initialized in your cluster?"; then
echo "Dapr is not installed. Installing Dapr..."
dapr init -k --enable-ha --runtime-version 1.14.4
# Wait for all pods in the dapr-system namespace to be ready
echo "Waiting for Dapr pods to be ready..."
while [[ $(kubectl get pods -n dapr-system -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}' | grep -o "True" | wc -l) -ne $(kubectl get pods -n dapr-system --no-headers | wc -l) ]]; do
echo "Waiting for Dapr pods to be ready..."
sleep 2
done
else
echo "Dapr is already installed"
fi
# Default context
DEFAULT_CONTEXT="kind-kind"
# Set context from argument or use default
CONTEXT=${1:-$DEFAULT_CONTEXT}
# Set namespace to the specified context
echo "Setting kubectl context to $CONTEXT..."
kubectl config use-context $CONTEXT
# Create namespaces if they don't exist
echo "Creating namespaces..."
for ns in ns1 ns2; do
if kubectl get namespace $ns > /dev/null 2>&1; then
echo "Namespace $ns already exists"
else
kubectl create namespace $ns
fi
done
# Build app images and load them in the kind cluster
echo "Building and loading app images..."
docker build -t demoactor-client:latest -f client/Dockerfile client
docker build -t demoactor-server:latest -f service/Dockerfile service
kind load docker-image demoactor-client:latest
kind load docker-image demoactor-server:latest
# Install Redis
echo "Installing Redis..."
if helm ls --all --short | grep -q '^redis$'; then
echo "Redis is already installed"
else
helm install redis bitnami/redis
fi
# Create secret with the password if it doesn't exist
echo "Creating Redis secrets..."
REDIS_PASSWORD=$(kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 -d)
for ns in ns1 ns2; do
if kubectl get secret redis-secret -n $ns > /dev/null 2>&1; then
echo "Secret redis-secret already exists in namespace $ns"
else
kubectl create secret generic redis-secret -n $ns --from-literal=redis-password=$REDIS_PASSWORD
fi
done
# Deploy the apps
echo "Deploying the apps..."
kubectl apply -f deploy/ns1.yml
kubectl apply -f deploy/ns2.yml
kubectl rollout restart deployment -n ns1
kubectl rollout restart deployment -n ns2
# Print instructions in green
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo -e "\n\n"
echo -e "${GREEN}Your application is deployed. Run the following port-forward commands to access the app:${NC}"
echo -e "${GREEN}------------------------------------------${NC}"
echo "kubectl port-forward svc/demoactor-client-app-service 3001:3000 -n ns1"
echo "kubectl port-forward svc/demoactor-client-app-service 3002:3000 -n ns2"
echo "kubectl port-forward svc/demoactor-server-app-service 4001:5000 -n ns1"
echo "kubectl port-forward svc/demoactor-server-app-service 4002:5000 -n ns2"
echo ""
echo -e "${GREEN}Once the port-forward commands are running, you can access the app at the following URLs:${NC}"
echo -e "${GREEN}------------------------------------------${NC}"
echo "Client ns1: http://localhost:3001"
echo "Client ns2: http://localhost:3002"
echo "Server ns1: http://localhost:4001"
echo "Server ns2: http://localhost:4002"
# Wait to keep the port forwards open
wait