Commit 7c72233387a3ad52f461a743d9a3926e3e153e9e
1 parent
53b240a7
Added commands for creating Redis cluster in k8s-deploy-thirdparty.sh
Showing
3 changed files
with
22 additions
and
14 deletions
1 | # Can be either basic (with single instance of Zookeeper, Kafka and Redis) or high-availability (with Zookeeper, Kafka and Redis in cluster modes). | 1 | # Can be either basic (with single instance of Zookeeper, Kafka and Redis) or high-availability (with Zookeeper, Kafka and Redis in cluster modes). |
2 | # According to the deployment type corresponding kubernetes resources will be deployed (see content of the directories ./basic and ./high-availability for details). | 2 | # According to the deployment type corresponding kubernetes resources will be deployed (see content of the directories ./basic and ./high-availability for details). |
3 | -DEPLOYMENT_TYPE=basic | 3 | +DEPLOYMENT_TYPE=high-availability |
4 | 4 | ||
5 | # Database used by ThingsBoard, can be either postgres (PostgreSQL) or cassandra (Cassandra). | 5 | # Database used by ThingsBoard, can be either postgres (PostgreSQL) or cassandra (Cassandra). |
6 | # According to the database type corresponding kubernetes resources will be deployed (see postgres.yml, cassandra.yml for details). | 6 | # According to the database type corresponding kubernetes resources will be deployed (see postgres.yml, cassandra.yml for details). |
@@ -53,19 +53,7 @@ Execute the following command to deploy thirdparty resources: | @@ -53,19 +53,7 @@ Execute the following command to deploy thirdparty resources: | ||
53 | $ ./k8s-deploy-thirdparty.sh | 53 | $ ./k8s-deploy-thirdparty.sh |
54 | ` | 54 | ` |
55 | 55 | ||
56 | -Get list of the running tb-redis pods and verify that all of them are in running state: | ||
57 | - | ||
58 | -` | ||
59 | -$ kubectl get pods -l app=tb-redis | ||
60 | -` | ||
61 | - | ||
62 | -If you are running ThingsBoard in `high-availability` `DEPLOYMENT_TYPE` execute the following command to create redis cluster: | ||
63 | - | ||
64 | -` | ||
65 | -$ kubectl exec -it tb-redis-0 -- redis-cli --cluster create --cluster-replicas 1 $(kubectl get pods -l app=tb-redis -o jsonpath='{range.items[*]}{.status.podIP}:6379 ') | ||
66 | -` | ||
67 | - | ||
68 | -Type **'yes'** when prompted. | 56 | +Type **'yes'** when prompted, if you are running ThingsBoard in `high-availability` `DEPLOYMENT_TYPE` for the first time and don't configured Redis cluster. |
69 | 57 | ||
70 | Execute the following command to deploy resources: | 58 | Execute the following command to deploy resources: |
71 | 59 |
@@ -23,3 +23,23 @@ kubectl apply -f common/tb-namespace.yml | @@ -23,3 +23,23 @@ kubectl apply -f common/tb-namespace.yml | ||
23 | kubectl config set-context $(kubectl config current-context) --namespace=thingsboard | 23 | kubectl config set-context $(kubectl config current-context) --namespace=thingsboard |
24 | 24 | ||
25 | kubectl apply -f $DEPLOYMENT_TYPE/thirdparty.yml | 25 | kubectl apply -f $DEPLOYMENT_TYPE/thirdparty.yml |
26 | + | ||
27 | + | ||
28 | +if [ "$DEPLOYMENT_TYPE" == "high-availability" ]; then | ||
29 | + echo -n "waiting for all redis pods to be ready"; | ||
30 | + while [[ $(kubectl get pods tb-redis-5 -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}' 2>/dev/null) != "True" ]]; | ||
31 | + do | ||
32 | + echo -n "." && sleep 5; | ||
33 | + done | ||
34 | + | ||
35 | + if [[ $(kubectl exec -it tb-redis-0 -- redis-cli cluster info 2>&1 | head -n 1) =~ "cluster_state:ok" ]] | ||
36 | + then | ||
37 | + echo "redis cluster is already configured" | ||
38 | + else | ||
39 | + echo "starting redis cluster" | ||
40 | + redisNodes=$(kubectl get pods -l app=tb-redis -o jsonpath='{range.items[*]}{.status.podIP}:6379 ') | ||
41 | + kubectl exec -it tb-redis-0 -- redis-cli --cluster create --cluster-replicas 1 $redisNodes | ||
42 | + fi | ||
43 | + | ||
44 | +fi | ||
45 | + |