-
Notifications
You must be signed in to change notification settings - Fork 0
/
order-blue-green.sh
60 lines (47 loc) · 2.21 KB
/
order-blue-green.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
#kubectl delete service order-db
#kubectl delete statefulset order-db
#kubectl delete pvc pvc-order
#kubectl delete pv pv-order
#
#kubectl apply -f database/order/initdb-config.yml
#kubectl apply -f database/order/pv-pvc.yml
#kubectl apply -f database/order/statefulset.yml
#kubectl apply -f database/order/service.yml
# Check if order-service-blue deployment is running
if kubectl get deployment order-service-blue | grep "1/1" &> /dev/null; then
# Apply order-service-green deployment
kubectl apply -f service/order/green-deployment.yml
# Wait for order-service-green pods to be ready
until kubectl get pods -l app=order-service,color=green | grep "1/1" &> /dev/null; do
echo "Waiting for order-service-green pods to be ready..."
sleep 5
done
kubectl patch service order-service -n prod -p '{"spec":{"selector":{"color":"green"}}}'
# Scale down order-service-blue deployment
kubectl scale deployment order-service-blue --replicas=0
echo "Blue deployment applied, and blue deployment scaled down."
# Check if order-service-green deployment is running
elif kubectl get deployment order-service-green | grep "1/1" &> /dev/null; then
echo "order-service-blue deployment not found."
# Apply order-service-blue deployment
kubectl apply -f service/order/blue-deployment.yml
# Wait for order-service-blue pods to be ready
until kubectl get pods -l app=order-service,color=blue | grep "1/1" &> /dev/null; do
echo "Waiting for order-service-blue pods to be ready..."
sleep 5
done
kubectl patch service order-service -n prod -p '{"spec":{"selector":{"color":"blue"}}}'
# Scale down order-service-green deployment
kubectl scale deployment order-service-green --replicas=0
echo "Blue deployment applied, and green deployment scaled down."
else
echo "order-service-green deployment not found."
echo "start order service"
kubectl apply -f database/order/initdb-config.yml
kubectl apply -f database/order/pv-pvc.yml
kubectl apply -f database/order/statefulset.yml
kubectl apply -f database/order/service.yml
kubectl apply -f service/order/blue-deployment.yml
kubectl apply -f service/order/blue-service.yml
exit 1
fi