Commit 08e9e903f393cbef4c0ff154537bb276579117e6

Authored by volodymyr-babak
1 parent 73458484

TB-58: k8s feature improvements

  1 +FROM cassandra:3.9
  2 +
  3 +COPY ready-probe.sh /
  4 +
  5 +CMD ["cassandra", "-f"]
\ No newline at end of file
... ...
  1 +VERSION=k8stest
  2 +PROJECT=thingsboard
  3 +APP=cassandra
  4 +
  5 +all: build
  6 +
  7 +build:
  8 + docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
  9 +
  10 +push: build
  11 + docker push ${PROJECT}/${APP}:${VERSION}
  12 +
  13 +.PHONY: all build push
\ No newline at end of file
... ...
1 1 apiVersion: v1
2 2 kind: Service
3 3 metadata:
  4 + name: cassandra-headless
4 5 labels:
5   - app: cassandra
6   - name: cassandra
  6 + app: cassandra-headless
7 7 spec:
8   - clusterIP: None
9 8 ports:
10 9 - port: 9042
  10 + name: cql
  11 + clusterIP: None
11 12 selector:
12 13 app: cassandra
13 14 ---
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 15 apiVersion: "apps/v1beta1"
23 16 kind: StatefulSet
24 17 metadata:
25 18 name: cassandra
26 19 spec:
27   - serviceName: cassandra
  20 + serviceName: cassandra-headless
28 21 replicas: 3
29 22 template:
30 23 metadata:
... ... @@ -39,11 +32,11 @@ spec:
39 32 - key: "app"
40 33 operator: In
41 34 values:
42   - - cassandra
  35 + - cassandra-headless
43 36 topologyKey: "kubernetes.io/hostname"
44 37 containers:
45 38 - name: cassandra
46   - image: gcr.io/google-samples/cassandra:v12
  39 + image: thingsboard/cassandra:k8stest
47 40 imagePullPolicy: Always
48 41 ports:
49 42 - containerPort: 7000
... ... @@ -77,7 +70,7 @@ spec:
77 70 - name: HEAP_NEWSIZE
78 71 value: 100M
79 72 - name: CASSANDRA_SEEDS
80   - value: "cassandra-0.cassandra.default.svc.cluster.local"
  73 + value: "cassandra-0.cassandra-headless.default.svc.cluster.local"
81 74 - name: CASSANDRA_CLUSTER_NAME
82 75 value: "K8Demo"
83 76 - name: CASSANDRA_DC
... ... @@ -102,22 +95,16 @@ spec:
102 95 - /ready-probe.sh
103 96 initialDelaySeconds: 15
104 97 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 98 volumeMounts:
109 99 - name: cassandra-data
110   - mountPath: /cassandra_data
  100 + mountPath: /var/lib/cassandra/data
111 101 - 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
  102 + mountPath: /var/lib/cassandra/commitlog
116 103 volumeClaimTemplates:
117 104 - metadata:
118 105 name: cassandra-data
119 106 annotations:
120   - volume.beta.kubernetes.io/storage-class: regular
  107 + volume.beta.kubernetes.io/storage-class: slow
121 108 spec:
122 109 accessModes: [ "ReadWriteOnce" ]
123 110 resources:
... ... @@ -126,7 +113,7 @@ spec:
126 113 - metadata:
127 114 name: cassandra-commitlog
128 115 annotations:
129   - volume.beta.kubernetes.io/storage-class: regular
  116 + volume.beta.kubernetes.io/storage-class: slow
130 117 spec:
131 118 accessModes: [ "ReadWriteOnce" ]
132 119 resources:
... ...
docker/cassandra/ready-probe.sh renamed from docker/thingsboard/build_and_deploy.sh
1 1 #!/bin/bash
2   -#
3   -# Copyright © 2016-2017 The Thingsboard Authors
  2 +
  3 +# Copyright 2016 The Kubernetes Authors.
4 4 #
5 5 # Licensed under the Apache License, Version 2.0 (the "License");
6 6 # you may not use this file except in compliance with the License.
... ... @@ -13,16 +13,15 @@
13 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 14 # See the License for the specific language governing permissions and
15 15 # limitations under the License.
16   -#
17   -
18   -
19   -cp ../../application/target/thingsboard.deb thingsboard.deb
20   -
21   -docker build -t thingsboard/application:k8test .
22   -
23   -docker login
24   -
25   -docker push thingsboard/application:k8test
26 16
27   -# cleanup
28   -rm thingsboard.deb
\ No newline at end of file
  17 +if [[ $(nodetool status | grep $POD_IP) == *"UN"* ]]; then
  18 + if [[ $DEBUG ]]; then
  19 + echo "UN";
  20 + fi
  21 + exit 0;
  22 +else
  23 + if [[ $DEBUG ]]; then
  24 + echo "Not Up";
  25 + fi
  26 + exit 1;
  27 +fi
\ No newline at end of file
... ...
  1 +---
  2 +apiVersion: storage.k8s.io/v1beta1
  3 +kind: StorageClass
  4 +metadata:
  5 + name: slow
  6 +provisioner: kubernetes.io/gce-pd
  7 +parameters:
  8 + type: pd-standard
  9 +---
\ No newline at end of file
... ...
1   -#!/bin/bash
2   -#
3   -# Copyright © 2016-2017 The Thingsboard Authors
4   -#
5   -# Licensed under the Apache License, Version 2.0 (the "License");
6   -# you may not use this file except in compliance with the License.
7   -# You may obtain a copy of the License at
8   -#
9   -# http://www.apache.org/licenses/LICENSE-2.0
10   -#
11   -# Unless required by applicable law or agreed to in writing, software
12   -# distributed under the License is distributed on an "AS IS" BASIS,
13   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   -# See the License for the specific language governing permissions and
15   -# limitations under the License.
16   -#
17   -
18   -
19   -command='docker-compose -f docker-compose.yml -f docker-compose.random.yml'
20   -
21   -echo "stopping images.."
22   -$command stop
23   -
24   -echo "removing stopped images.."
25   -$command rm -f
26   -
27   -echo "building images.."
28   -$command build
29   -
30   -echo "starting images..."
31   -$command up -d
1   -#!/bin/bash
2   -#
3   -# Copyright © 2016-2017 The Thingsboard Authors
4   -#
5   -# Licensed under the Apache License, Version 2.0 (the "License");
6   -# you may not use this file except in compliance with the License.
7   -# You may obtain a copy of the License at
8   -#
9   -# http://www.apache.org/licenses/LICENSE-2.0
10   -#
11   -# Unless required by applicable law or agreed to in writing, software
12   -# distributed under the License is distributed on an "AS IS" BASIS,
13   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   -# See the License for the specific language governing permissions and
15   -# limitations under the License.
16   -#
17   -
18   -
19   -command='docker-compose -f docker-compose.yml -f docker-compose.static.yml'
20   -
21   -echo "stopping images.."
22   -$command stop
23   -
24   -echo "removing stopped images.."
25   -$command rm -f
26   -
27   -echo "building images.."
28   -$command build
29   -
30   -echo "starting cassandra, zookeeper, thingsboard-db-schema images..."
31   -$command up -d db zk thingsboard-db-schema
  1 +VERSION=k8stest
  2 +PROJECT=thingsboard
  3 +APP=thingsboard-db-schema
  4 +
  5 +all: build
  6 +
  7 +build:
  8 + docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
  9 +
  10 +push: build
  11 + docker push ${PROJECT}/${APP}:${VERSION}
  12 +
  13 +.PHONY: all build push
\ No newline at end of file
... ...
1   -#!/bin/bash
2   -#
3   -# Copyright © 2016-2017 The Thingsboard Authors
4   -#
5   -# Licensed under the Apache License, Version 2.0 (the "License");
6   -# you may not use this file except in compliance with the License.
7   -# You may obtain a copy of the License at
8   -#
9   -# http://www.apache.org/licenses/LICENSE-2.0
10   -#
11   -# Unless required by applicable law or agreed to in writing, software
12   -# distributed under the License is distributed on an "AS IS" BASIS,
13   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   -# See the License for the specific language governing permissions and
15   -# limitations under the License.
16   -#
17   -
18   -
19   -cp ../../dao/src/main/resources/schema.cql schema.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
22   -
23   -docker build -t thingsboard/thingsboard-db-schema:k8test .
24   -
25   -docker login
26   -
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
\ No newline at end of file
docker/thingsboard-db-schema/thingsboard-db-schema.yaml renamed from docker/thingsboard-db-schema/thingsboard-schema.yaml
... ... @@ -6,7 +6,7 @@ spec:
6 6 containers:
7 7 - name: tb-db-schema
8 8 imagePullPolicy: Always
9   - image: thingsboard/thingsboard-db-schema:k8test
  9 + image: thingsboard/thingsboard-db-schema:k8stest
10 10 env:
11 11 - name: SKIP_SCHEMA_CREATION
12 12 value: "false"
... ... @@ -15,7 +15,7 @@ spec:
15 15 - name : SKIP_DEMO_DATA
16 16 value: "false"
17 17 - name : CASSANDRA_URL
18   - value: "cassandra"
  18 + value: "cassandra-headless"
19 19 command:
20 20 - sh
21 21 - -c
... ...
  1 +VERSION=k8stest
  2 +PROJECT=thingsboard
  3 +APP=application
  4 +
  5 +all: build
  6 +
  7 +build:
  8 + docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
  9 +
  10 +push: build
  11 + docker push ${PROJECT}/${APP}:${VERSION}
  12 +
  13 +.PHONY: all build push
\ No newline at end of file
... ...
... ... @@ -8,13 +8,11 @@ metadata:
8 8 spec:
9 9 ports:
10 10 - port: 8080
11   - name: ui-port
  11 + name: ui
12 12 - port: 1883
13   - name: mqtt-port
  13 + name: mqtt
14 14 - port: 5683
15   - name: coap-port
16   - - port: 9001
17   - name: rpc-port
  15 + name: coap
18 16 selector:
19 17 app: tb
20 18 type: LoadBalancer
... ... @@ -27,14 +25,8 @@ metadata:
27 25 app: tb-headless
28 26 spec:
29 27 ports:
30   - - port: 8080
31   - name: ui-port
32   - - port: 1883
33   - name: mqtt-port
34   - - port: 5683
35   - name: coap-port
36 28 - port: 9001
37   - name: rpc-port
  29 + name: rpc
38 30 selector:
39 31 app: tb
40 32 clusterIP: None
... ... @@ -56,7 +48,7 @@ metadata:
56 48 data:
57 49 zookeeper.enabled: "true"
58 50 zookeeper.url: "zk-headless"
59   - cassandra.url: "cassandra:9042"
  51 + cassandra.url: "cassandra-headless:9042"
60 52 ---
61 53 apiVersion: apps/v1beta1
62 54 kind: StatefulSet
... ... @@ -84,16 +76,23 @@ spec:
84 76 containers:
85 77 - name: tb
86 78 imagePullPolicy: Always
87   - image: thingsboard/application:k8test
  79 + image: thingsboard/application:k8stest
88 80 ports:
89 81 - containerPort: 8080
90   - name: ui-port
  82 + name: ui
91 83 - containerPort: 1883
92   - name: mqtt-port
  84 + name: mqtt
93 85 - containerPort: 5683
94   - name: coap-port
  86 + name: coap
95 87 - containerPort: 9001
96   - name: rpc-port
  88 + name: rpc
  89 + resources:
  90 + limits:
  91 + cpu: "250m"
  92 + memory: "500Mi"
  93 + requests:
  94 + cpu: "250m"
  95 + memory: "500Mi"
97 96 env:
98 97 - name: ZOOKEEPER_ENABLED
99 98 valueFrom:
... ...
1   -VERSION=k8test
  1 +VERSION=k8stest
2 2 PROJECT=thingsboard
  3 +APP=zk
3 4
4 5 all: build
5 6
6 7 build:
7   - docker build --pull -t ${PROJECT}/k8szk:${VERSION} .
  8 + docker build --pull -t ${PROJECT}/${APP}:${VERSION} .
8 9
9 10 push: build
10   - docker push ${PROJECT}/k8szk:${VERSION}
  11 + docker push ${PROJECT}/${APP}:${VERSION}
11 12
12 13 .PHONY: all build push
... ...
... ... @@ -86,7 +86,7 @@ function validate_env() {
86 86 function create_config() {
87 87 rm -f $ZK_CONFIG_FILE
88 88 echo "Creating ZooKeeper configuration"
89   - echo "#This file was autogenerated by k8szk DO NOT EDIT" >> $ZK_CONFIG_FILE
  89 + echo "#This file was autogenerated by zk DO NOT EDIT" >> $ZK_CONFIG_FILE
90 90 echo "clientPort=$ZK_CLIENT_PORT" >> $ZK_CONFIG_FILE
91 91 echo "dataDir=$ZK_DATA_DIR" >> $ZK_CONFIG_FILE
92 92 echo "dataLogDir=$ZK_DATA_LOG_DIR" >> $ZK_CONFIG_FILE
... ...
... ... @@ -20,6 +20,7 @@ metadata:
20 20 name: zk-config
21 21 data:
22 22 ensemble: "zk-0;zk-1;zk-2"
  23 + replicas: "3"
23 24 jvm.heap: "500m"
24 25 tick: "2000"
25 26 init: "10"
... ... @@ -27,6 +28,9 @@ data:
27 28 client.cnxns: "60"
28 29 snap.retain: "3"
29 30 purge.interval: "1"
  31 + client.port: "2181"
  32 + server.port: "2888"
  33 + election.port: "3888"
30 34 ---
31 35 apiVersion: policy/v1beta1
32 36 kind: PodDisruptionBudget
... ... @@ -63,9 +67,9 @@ spec:
63 67 - zk-headless
64 68 topologyKey: "kubernetes.io/hostname"
65 69 containers:
66   - - name: k8szk
  70 + - name: zk
67 71 imagePullPolicy: Always
68   - image: thingsboard/k8szk:k8test
  72 + image: thingsboard/zk:k8stest
69 73 resources:
70 74 requests:
71 75 memory: "500Mi"
... ... @@ -84,48 +88,60 @@ spec:
84 88 name: zk-config
85 89 key: ensemble
86 90 - name : ZK_REPLICAS
87   - value: "3"
  91 + valueFrom:
  92 + configMapKeyRef:
  93 + name: zk-config
  94 + key: replicas
88 95 - name : ZK_HEAP_SIZE
89 96 valueFrom:
90 97 configMapKeyRef:
91   - name: zk-config
92   - key: jvm.heap
  98 + name: zk-config
  99 + key: jvm.heap
93 100 - name : ZK_TICK_TIME
94 101 valueFrom:
95 102 configMapKeyRef:
96   - name: zk-config
97   - key: tick
  103 + name: zk-config
  104 + key: tick
98 105 - name : ZK_INIT_LIMIT
99 106 valueFrom:
100 107 configMapKeyRef:
101   - name: zk-config
102   - key: init
  108 + name: zk-config
  109 + key: init
103 110 - name : ZK_SYNC_LIMIT
104 111 valueFrom:
105 112 configMapKeyRef:
106   - name: zk-config
107   - key: tick
  113 + name: zk-config
  114 + key: tick
108 115 - name : ZK_MAX_CLIENT_CNXNS
109 116 valueFrom:
110 117 configMapKeyRef:
111   - name: zk-config
112   - key: client.cnxns
  118 + name: zk-config
  119 + key: client.cnxns
113 120 - name: ZK_SNAP_RETAIN_COUNT
114 121 valueFrom:
115 122 configMapKeyRef:
116   - name: zk-config
117   - key: snap.retain
  123 + name: zk-config
  124 + key: snap.retain
118 125 - name: ZK_PURGE_INTERVAL
119 126 valueFrom:
120 127 configMapKeyRef:
121   - name: zk-config
122   - key: purge.interval
  128 + name: zk-config
  129 + key: purge.interval
123 130 - name: ZK_CLIENT_PORT
124   - value: "2181"
  131 + valueFrom:
  132 + configMapKeyRef:
  133 + name: zk-config
  134 + key: client.port
125 135 - name: ZK_SERVER_PORT
126   - value: "2888"
  136 + valueFrom:
  137 + configMapKeyRef:
  138 + name: zk-config
  139 + key: server.port
127 140 - name: ZK_ELECTION_PORT
128   - value: "3888"
  141 + valueFrom:
  142 + configMapKeyRef:
  143 + name: zk-config
  144 + key: election.port
129 145 command:
130 146 - sh
131 147 - -c
... ... @@ -143,16 +159,16 @@ spec:
143 159 initialDelaySeconds: 15
144 160 timeoutSeconds: 5
145 161 volumeMounts:
146   - - name: datadir
  162 + - name: zkdatadir
147 163 mountPath: /var/lib/zookeeper
148 164 securityContext:
149 165 runAsUser: 1000
150 166 fsGroup: 1000
151 167 volumeClaimTemplates:
152 168 - metadata:
153   - name: datadir
  169 + name: zkdatadir
154 170 annotations:
155   - volume.alpha.kubernetes.io/storage-class: anything
  171 + volume.beta.kubernetes.io/storage-class: slow
156 172 spec:
157 173 accessModes: [ "ReadWriteOnce" ]
158 174 resources:
... ...