-
Notifications
You must be signed in to change notification settings - Fork 27
/
initiate.sh
executable file
·91 lines (68 loc) · 2.59 KB
/
initiate.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
#!/bin/bash
source config
#set -e
#Creating config nodes
kubectl create -f mongo_config.yaml
#Waiting for containers
echo "Waiting config containers"
kubectl get pods | grep "mongocfg" | grep "ContainerCreating"
while [ $? -eq 0 ]
do
sleep 1
echo -e "\n\nWaiting the following containers:"
kubectl get pods | grep "mongocfg" | grep "ContainerCreating"
done
#Initializating configuration nodes
POD_NAME=$(kubectl get pods | grep "mongocfg1" | awk '{print $1;}')
echo "Initializating config replica set... connecting to: $POD_NAME"
CMD='rs.initiate({ _id : "cfgrs", configsvr: true, members: [{ _id : 0, host : "mongocfg1:27019" },{ _id : 1, host : "mongocfg2:27019" },{ _id : 2, host : "mongocfg3:27019" }]})'
kubectl exec -it $POD_NAME -- bash -c "mongo --port 27019 --eval '$CMD'"
#Creating shard nodes
for ((rs=1; rs<=$SHARD_REPLICA_SET; rs++)) do
kubectl create -f mongo_sh_$rs.yaml
done
#Waiting for containers
POD_STATUS= kubectl get pods | grep "mongosh" | grep "ContainerCreating"
echo "Waiting shard containers"
kubectl get pods | grep "mongosh" | grep "ContainerCreating"
while [ $? -eq 0 ]
do
sleep 1
echo -e "\n\nWaiting the following containers:"
kubectl get pods | grep "mongosh" | grep "ContainerCreating"
done
#Initializating shard nodes
for ((rs=1; rs<=$SHARD_REPLICA_SET; rs++)) do
echo -e "\n\n---------------------------------------------------"
echo "Initializing mongosh$rs"
#Retriving pod name
POD_NAME=$(kubectl get pods | grep "mongosh$rs-1" | awk '{print $1;}')
echo "Pod Name: $POD_NAME"
CMD="rs.initiate({ _id : \"rs$rs\", members: [{ _id : 0, host : \"mongosh$rs-1:27017\" },{ _id : 1, host : \"mongosh$rs-2:27017\" },{ _id : 2, host : \"mongosh$rs-3:27017\" }]})"
#Executing cmd inside pod
echo $CMD
kubectl exec -it $POD_NAME -- bash -c "mongo --eval '$CMD'"
done
#Initializing routers
kubectl create -f mongos.yaml
echo "Waiting router containers"
kubectl get pods | grep "mongos[0-9]" | grep "ContainerCreating"
while [ $? -eq 0 ]
do
sleep 1
echo -e "\n\nWaiting the following containers:"
kubectl get pods | grep "mongos[0-9]" | grep "ContainerCreating"
done
#Adding shard to cluster
#Retriving pod name
POD_NAME=$(kubectl get pods | grep "mongos1" | awk '{print $1;}')
for ((rs=1; rs<=$SHARD_REPLICA_SET; rs++)) do
echo -e "\n\n---------------------------------------------------"
echo "Adding rs$rs to cluster"
echo "Pod Name: $POD_NAME"
CMD="sh.addShard(\"rs$rs/mongosh$rs-1:27017\")"
#Executing cmd inside pod
echo $CMD
kubectl exec -it $POD_NAME -- bash -c "mongo --eval '$CMD'"
done
echo "All done!!!"