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