Commit b39416232d59f24d312ce0fb600b882138a8e228

Authored by volodymyr-babak
1 parent cd11bb6c

TB-58: k8 base scripts

@@ -2,4 +2,5 @@ @@ -2,4 +2,5 @@
2 2
3 SKIP_SCHEMA_CREATION=false 3 SKIP_SCHEMA_CREATION=false
4 SKIP_SYSTEM_DATA=false 4 SKIP_SYSTEM_DATA=false
5 -SKIP_DEMO_DATA=false  
  5 +SKIP_DEMO_DATA=false
  6 +CASSANDRA_URL=db
@@ -20,9 +20,13 @@ cp ../../dao/src/main/resources/schema.cql schema.cql @@ -20,9 +20,13 @@ cp ../../dao/src/main/resources/schema.cql schema.cql
20 cp ../../dao/src/main/resources/demo-data.cql demo-data.cql 20 cp ../../dao/src/main/resources/demo-data.cql demo-data.cql
21 cp ../../dao/src/main/resources/system-data.cql system-data.cql 21 cp ../../dao/src/main/resources/system-data.cql system-data.cql
22 22
23 -docker build -t thingsboard/thingsboard-db-schema:1.2.2 -t thingsboard/thingsboard-db-schema:latest . 23 +docker build -t thingsboard/thingsboard-db-schema:k8test .
24 24
25 docker login 25 docker login
26 26
27 -docker push thingsboard/thingsboard-db-schema:1.2.2  
28 -docker push thingsboard/thingsboard-db-schema:latest  
  27 +docker push thingsboard/thingsboard-db-schema:k8test
  28 +
  29 +# cleanup
  30 +rm schema.cql
  31 +rm demo-data.cql
  32 +rm system-data.cql
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 # 16 #
17 17
18 18
19 -until nmap db -p 9042 | grep "9042/tcp open" 19 +until nmap $CASSANDRA_URL -p 9042 | grep "9042/tcp open"
20 do 20 do
21 echo "Wait for Cassandra..." 21 echo "Wait for Cassandra..."
22 sleep 10 22 sleep 10
@@ -24,7 +24,7 @@ done @@ -24,7 +24,7 @@ done
24 24
25 if [ "$SKIP_SCHEMA_CREATION" == "false" ]; then 25 if [ "$SKIP_SCHEMA_CREATION" == "false" ]; then
26 echo "Creating 'Thingsboard' keyspace..." 26 echo "Creating 'Thingsboard' keyspace..."
27 - cqlsh db -f /root/schema.cql 27 + cqlsh $CASSANDRA_URL -f /root/schema.cql
28 if [ "$?" -eq 0 ]; then 28 if [ "$?" -eq 0 ]; then
29 echo "'Thingsboard' keyspace was successfully created!" 29 echo "'Thingsboard' keyspace was successfully created!"
30 else 30 else
@@ -34,7 +34,7 @@ fi @@ -34,7 +34,7 @@ fi
34 34
35 if [ "$SKIP_SYSTEM_DATA" == "false" ]; then 35 if [ "$SKIP_SYSTEM_DATA" == "false" ]; then
36 echo "Adding system data..." 36 echo "Adding system data..."
37 - cqlsh db -f /root/system-data.cql 37 + cqlsh $CASSANDRA_URL -f /root/system-data.cql
38 if [ "$?" -eq 0 ]; then 38 if [ "$?" -eq 0 ]; then
39 echo "System data was successfully added!" 39 echo "System data was successfully added!"
40 else 40 else
@@ -44,7 +44,7 @@ fi @@ -44,7 +44,7 @@ fi
44 44
45 if [ "$SKIP_DEMO_DATA" == "false" ]; then 45 if [ "$SKIP_DEMO_DATA" == "false" ]; then
46 echo "Adding demo data..." 46 echo "Adding demo data..."
47 - cqlsh db -f /root/demo-data.cql 47 + cqlsh $CASSANDRA_URL -f /root/demo-data.cql
48 if [ "$?" -eq 0 ]; then 48 if [ "$?" -eq 0 ]; then
49 echo "Demo data was successfully added!" 49 echo "Demo data was successfully added!"
50 else 50 else
@@ -18,9 +18,11 @@ @@ -18,9 +18,11 @@
18 18
19 cp ../../application/target/thingsboard.deb thingsboard.deb 19 cp ../../application/target/thingsboard.deb thingsboard.deb
20 20
21 -docker build -t thingsboard/application:1.2.2 -t thingsboard/application:latest . 21 +docker build -t thingsboard/application:k8test .
22 22
23 docker login 23 docker login
24 24
25 -docker push thingsboard/application:1.2.2  
26 -docker push thingsboard/application:latest  
  25 +docker push thingsboard/application:k8test
  26 +
  27 +# cleanup
  28 +rm thingsboard.deb
@@ -34,6 +34,9 @@ done @@ -34,6 +34,9 @@ done
34 # Copying env variables into conf files 34 # Copying env variables into conf files
35 printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thingsboard/conf/thingsboard.conf 35 printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thingsboard/conf/thingsboard.conf
36 36
  37 +# Set env variable for RPC address
  38 +echo "export RPC_HOST='"$(hostname -f)"'" | tee -a /usr/share/thingsboard/conf/thingsboard.conf
  39 +
37 cat /usr/share/thingsboard/conf/thingsboard.conf 40 cat /usr/share/thingsboard/conf/thingsboard.conf
38 41
39 echo "Starting 'Thingsboard' service..." 42 echo "Starting 'Thingsboard' service..."
  1 +apiVersion: v1
  2 +kind: Service
  3 +metadata:
  4 + labels:
  5 + app: cassandra
  6 + name: cassandra
  7 +spec:
  8 + clusterIP: None
  9 + ports:
  10 + - port: 9042
  11 + selector:
  12 + app: cassandra
  13 +---
  14 +apiVersion: storage.k8s.io/v1beta1
  15 +kind: StorageClass
  16 +metadata:
  17 + name: regular
  18 +provisioner: kubernetes.io/gce-pd
  19 +parameters:
  20 + type: pd-standard
  21 +---
  22 +apiVersion: "apps/v1beta1"
  23 +kind: StatefulSet
  24 +metadata:
  25 + name: cassandra
  26 +spec:
  27 + serviceName: cassandra
  28 + replicas: 3
  29 + template:
  30 + metadata:
  31 + labels:
  32 + app: cassandra
  33 + spec:
  34 + affinity:
  35 + podAntiAffinity:
  36 + requiredDuringSchedulingIgnoredDuringExecution:
  37 + - labelSelector:
  38 + matchExpressions:
  39 + - key: "app"
  40 + operator: In
  41 + values:
  42 + - cassandra
  43 + topologyKey: "kubernetes.io/hostname"
  44 + containers:
  45 + - name: cassandra
  46 + image: gcr.io/google-samples/cassandra:v12
  47 + imagePullPolicy: Always
  48 + ports:
  49 + - containerPort: 7000
  50 + name: intra-node
  51 + - containerPort: 7001
  52 + name: tls-intra-node
  53 + - containerPort: 7199
  54 + name: jmx
  55 + - containerPort: 9042
  56 + name: cql
  57 + - containerPort: 9160
  58 + name: thrift
  59 + resources:
  60 + limits:
  61 + cpu: "500m"
  62 + memory: 1Gi
  63 + requests:
  64 + cpu: "500m"
  65 + memory: 1Gi
  66 + securityContext:
  67 + capabilities:
  68 + add:
  69 + - IPC_LOCK
  70 + lifecycle:
  71 + preStop:
  72 + exec:
  73 + command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
  74 + env:
  75 + - name: MAX_HEAP_SIZE
  76 + value: 512M
  77 + - name: HEAP_NEWSIZE
  78 + value: 100M
  79 + - name: CASSANDRA_SEEDS
  80 + value: "cassandra-0.cassandra.default.svc.cluster.local"
  81 + - name: CASSANDRA_CLUSTER_NAME
  82 + value: "K8Demo"
  83 + - name: CASSANDRA_DC
  84 + value: "DC1-K8Demo"
  85 + - name: CASSANDRA_RACK
  86 + value: "Rack1-K8Demo"
  87 + - name: CASSANDRA_AUTO_BOOTSTRAP
  88 + value: "false"
  89 + - name: POD_IP
  90 + valueFrom:
  91 + fieldRef:
  92 + fieldPath: status.podIP
  93 + - name: POD_NAMESPACE
  94 + valueFrom:
  95 + fieldRef:
  96 + fieldPath: metadata.namespace
  97 + readinessProbe:
  98 + exec:
  99 + command:
  100 + - /bin/bash
  101 + - -c
  102 + - /ready-probe.sh
  103 + initialDelaySeconds: 15
  104 + timeoutSeconds: 5
  105 + # These volume mounts are persistent. They are like inline claims,
  106 + # but not exactly because the names need to match exactly one of
  107 + # the stateful pod volumes.
  108 + volumeMounts:
  109 + - name: cassandra-data
  110 + mountPath: /cassandra_data
  111 + - name: cassandra-commitlog
  112 + mountPath: /cassandra_commitlog
  113 + # These are converted to volume claims by the controller
  114 + # and mounted at the paths mentioned above.
  115 + # do not use these in production until ssd GCEPersistentDisk or other ssd pd
  116 + volumeClaimTemplates:
  117 + - metadata:
  118 + name: cassandra-data
  119 + annotations:
  120 + volume.beta.kubernetes.io/storage-class: regular
  121 + spec:
  122 + accessModes: [ "ReadWriteOnce" ]
  123 + resources:
  124 + requests:
  125 + storage: 2Gi
  126 + - metadata:
  127 + name: cassandra-commitlog
  128 + annotations:
  129 + volume.beta.kubernetes.io/storage-class: regular
  130 + spec:
  131 + accessModes: [ "ReadWriteOnce" ]
  132 + resources:
  133 + requests:
  134 + storage: 1Gi
  1 +apiVersion: v1
  2 +kind: Pod
  3 +metadata:
  4 + name: tb-db-schema-deployment
  5 +spec:
  6 + containers:
  7 + - name: tb-db-schema-k8
  8 + image: thingsboard/thingsboard-db-schema:k8test
  9 + env:
  10 + - name: SKIP_SCHEMA_CREATION
  11 + value: "false"
  12 + - name: SKIP_SYSTEM_DATA
  13 + value: "false"
  14 + - name : SKIP_DEMO_DATA
  15 + value: "false"
  16 + - name : CASSANDRA_URL
  17 + value: "cassandra"
  18 + command:
  19 + - sh
  20 + - -c
  21 + - ./install_schema.sh
  22 + restartPolicy: Never
  1 +---
  2 +apiVersion: v1
  3 +kind: Service
  4 +metadata:
  5 + name: thingsboard-external
  6 + labels:
  7 + app: thingsboard-external
  8 +spec:
  9 + ports:
  10 + - port: 8080
  11 + name: ui
  12 + - port: 1883
  13 + name: mqtt
  14 + - port: 5683
  15 + name: coap
  16 + - port: 9001
  17 + name: rpc
  18 + selector:
  19 + app: thingsboard
  20 + type: LoadBalancer
  21 +---
  22 +apiVersion: v1
  23 +kind: Service
  24 +metadata:
  25 + name: thingsboard-headless
  26 + labels:
  27 + app: thingsboard-headless
  28 +spec:
  29 + ports:
  30 + - port: 8080
  31 + name: ui
  32 + - port: 1883
  33 + name: mqtt
  34 + - port: 5683
  35 + name: coap
  36 + - port: 9001
  37 + name: rpc
  38 + selector:
  39 + app: thingsboard
  40 + clusterIP: None
  41 +---
  42 +apiVersion: v1
  43 +kind: ConfigMap
  44 +metadata:
  45 + name: tb-config
  46 +data:
  47 + zookeeper.enabled: "true"
  48 + zookeeper.url: "zk-headless"
  49 + cassandra.url: "cassandra:9042"
  50 +---
  51 +apiVersion: apps/v1beta1
  52 +kind: StatefulSet
  53 +metadata:
  54 + name: tb
  55 +spec:
  56 + serviceName: "thingsboard-headless"
  57 + replicas: 2
  58 + template:
  59 + metadata:
  60 + labels:
  61 + app: thingsboard
  62 + spec:
  63 + terminationGracePeriodSeconds: 10
  64 + affinity:
  65 + podAntiAffinity:
  66 + requiredDuringSchedulingIgnoredDuringExecution:
  67 + - labelSelector:
  68 + matchExpressions:
  69 + - key: "app"
  70 + operator: In
  71 + values:
  72 + - thingsboard-headless
  73 + topologyKey: "kubernetes.io/hostname"
  74 + containers:
  75 + - name: thingsboard
  76 + image: thingsboard/application:k8test
  77 + ports:
  78 + - containerPort: 8080
  79 + name: ui
  80 + - containerPort: 1883
  81 + name: mqtt
  82 + - containerPort: 5683
  83 + name: coap
  84 + - containerPort: 9001
  85 + name: rpc
  86 + env:
  87 + - name: ZOOKEEPER_ENABLED
  88 + valueFrom:
  89 + configMapKeyRef:
  90 + name: tb-config
  91 + key: zookeeper.enabled
  92 + - name: ZOOKEEPER_URL
  93 + valueFrom:
  94 + configMapKeyRef:
  95 + name: tb-config
  96 + key: zookeeper.url
  97 + - name : CASSANDRA_URL
  98 + valueFrom:
  99 + configMapKeyRef:
  100 + name: tb-config
  101 + key: cassandra.url
  102 + command:
  103 + - sh
  104 + - -c
  105 + - ./run_thingsboard.sh
@@ -20,7 +20,7 @@ metadata: @@ -20,7 +20,7 @@ metadata:
20 name: zk-config 20 name: zk-config
21 data: 21 data:
22 ensemble: "zk-0;zk-1;zk-2" 22 ensemble: "zk-0;zk-1;zk-2"
23 - jvm.heap: "2G" 23 + jvm.heap: "1G"
24 tick: "2000" 24 tick: "2000"
25 init: "10" 25 init: "10"
26 sync: "5" 26 sync: "5"
@@ -51,34 +51,25 @@ spec: @@ -51,34 +51,25 @@ spec:
51 app: zk 51 app: zk
52 annotations: 52 annotations:
53 pod.alpha.kubernetes.io/initialized: "true" 53 pod.alpha.kubernetes.io/initialized: "true"
54 - scheduler.alpha.kubernetes.io/affinity: >  
55 - {  
56 - "podAntiAffinity": {  
57 - "requiredDuringSchedulingIgnoredDuringExecution": [  
58 - {  
59 - "labelSelector": {  
60 - "matchExpressions": [  
61 - {  
62 - "key": "app",  
63 - "operator": "In",  
64 - "values": [ "zk-headless" ]  
65 - }  
66 - ]  
67 - },  
68 - "topologyKey": "kubernetes.io/hostname"  
69 - }  
70 - ]  
71 - }  
72 - }  
73 spec: 54 spec:
  55 + affinity:
  56 + podAntiAffinity:
  57 + requiredDuringSchedulingIgnoredDuringExecution:
  58 + - labelSelector:
  59 + matchExpressions:
  60 + - key: "app"
  61 + operator: In
  62 + values:
  63 + - zk-headless
  64 + topologyKey: "kubernetes.io/hostname"
74 containers: 65 containers:
75 - name: k8szk 66 - name: k8szk
76 imagePullPolicy: Always 67 imagePullPolicy: Always
77 image: gcr.io/google_samples/k8szk:v1 68 image: gcr.io/google_samples/k8szk:v1
78 resources: 69 resources:
79 requests: 70 requests:
80 - memory: "1Gi"  
81 - cpu: "0.5" 71 + memory: "0.5Gi"
  72 + cpu: "0.2"
82 ports: 73 ports:
83 - containerPort: 2181 74 - containerPort: 2181
84 name: client 75 name: client
@@ -164,4 +155,4 @@ spec: @@ -164,4 +155,4 @@ spec:
164 accessModes: [ "ReadWriteOnce" ] 155 accessModes: [ "ReadWriteOnce" ]
165 resources: 156 resources:
166 requests: 157 requests:
167 - storage: 20Gi  
  158 + storage: 1Gi