From 7c72233387a3ad52f461a743d9a3926e3e153e9e Mon Sep 17 00:00:00 2001 From: viktor Date: Wed, 27 May 2020 15:40:57 +0300 Subject: [PATCH] Added commands for creating Redis cluster in k8s-deploy-thirdparty.sh --- k8s/.env | 2 +- k8s/README.md | 14 +------------- k8s/k8s-deploy-thirdparty.sh | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/k8s/.env b/k8s/.env index 5490250d8d..5f6b634b45 100644 --- a/k8s/.env +++ b/k8s/.env @@ -1,6 +1,6 @@ # Can be either basic (with single instance of Zookeeper, Kafka and Redis) or high-availability (with Zookeeper, Kafka and Redis in cluster modes). # According to the deployment type corresponding kubernetes resources will be deployed (see content of the directories ./basic and ./high-availability for details). -DEPLOYMENT_TYPE=basic +DEPLOYMENT_TYPE=high-availability # Database used by ThingsBoard, can be either postgres (PostgreSQL) or cassandra (Cassandra). # According to the database type corresponding kubernetes resources will be deployed (see postgres.yml, cassandra.yml for details). diff --git a/k8s/README.md b/k8s/README.md index 90fdea6afb..6017df1bd2 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -53,19 +53,7 @@ Execute the following command to deploy thirdparty resources: $ ./k8s-deploy-thirdparty.sh ` -Get list of the running tb-redis pods and verify that all of them are in running state: - -` -$ kubectl get pods -l app=tb-redis -` - -If you are running ThingsBoard in `high-availability` `DEPLOYMENT_TYPE` execute the following command to create redis cluster: - -` -$ 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 ') -` - -Type **'yes'** when prompted. +Type **'yes'** when prompted, if you are running ThingsBoard in `high-availability` `DEPLOYMENT_TYPE` for the first time and don't configured Redis cluster. Execute the following command to deploy resources: diff --git a/k8s/k8s-deploy-thirdparty.sh b/k8s/k8s-deploy-thirdparty.sh index 17e9d3740f..f530fb2903 100755 --- a/k8s/k8s-deploy-thirdparty.sh +++ b/k8s/k8s-deploy-thirdparty.sh @@ -23,3 +23,23 @@ kubectl apply -f common/tb-namespace.yml kubectl config set-context $(kubectl config current-context) --namespace=thingsboard kubectl apply -f $DEPLOYMENT_TYPE/thirdparty.yml + + +if [ "$DEPLOYMENT_TYPE" == "high-availability" ]; then + echo -n "waiting for all redis pods to be ready"; + while [[ $(kubectl get pods tb-redis-5 -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}' 2>/dev/null) != "True" ]]; + do + echo -n "." && sleep 5; + done + + if [[ $(kubectl exec -it tb-redis-0 -- redis-cli cluster info 2>&1 | head -n 1) =~ "cluster_state:ok" ]] + then + echo "redis cluster is already configured" + else + echo "starting redis cluster" + redisNodes=$(kubectl get pods -l app=tb-redis -o jsonpath='{range.items[*]}{.status.podIP}:6379 ') + kubectl exec -it tb-redis-0 -- redis-cli --cluster create --cluster-replicas 1 $redisNodes + fi + +fi +