Commit 45af758f46f4b15fb1d6d64364f9bfefcad38508
Merge branch 'volodymyr-babak-feature/stateful-services'
Showing
6 changed files
with
369 additions
and
163 deletions
... | ... | @@ -40,6 +40,26 @@ Where: |
40 | 40 | |
41 | 41 | ## Running |
42 | 42 | |
43 | +Execute the following command to deploy thirdparty resources: | |
44 | + | |
45 | +` | |
46 | +$ ./k8s-deploy-thirdparty.sh | |
47 | +` | |
48 | + | |
49 | +Get list of the running tb-redis pods and verify that all of them are in running state: | |
50 | + | |
51 | +` | |
52 | +$ kubectl get pods -l app=tb-redis | |
53 | +` | |
54 | + | |
55 | +Execute the following command to create redis cluster: | |
56 | + | |
57 | +` | |
58 | +$ 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 ') | |
59 | +` | |
60 | + | |
61 | +Type **'yes'** when prompted. | |
62 | + | |
43 | 63 | Execute the following command to deploy resources: |
44 | 64 | |
45 | 65 | ` | ... | ... |
k8s/k8s-delete-thirdparty.sh
0 → 100755
1 | +#!/bin/bash | |
2 | +# | |
3 | +# Copyright © 2016-2020 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 | +set -e | |
19 | + | |
20 | +kubectl config set-context $(kubectl config current-context) --namespace=thingsboard | |
21 | +kubectl delete -f thirdparty.yml | ... | ... |
k8s/k8s-deploy-thirdparty.sh
0 → 100755
1 | +#!/bin/bash | |
2 | +# | |
3 | +# Copyright © 2016-2020 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 | +set -e | |
19 | + | |
20 | +kubectl apply -f tb-namespace.yml | |
21 | +kubectl config set-context $(kubectl config current-context) --namespace=thingsboard | |
22 | +kubectl apply -f thirdparty.yml | ... | ... |
... | ... | @@ -17,169 +17,6 @@ |
17 | 17 | apiVersion: apps/v1 |
18 | 18 | kind: Deployment |
19 | 19 | metadata: |
20 | - name: zookeeper | |
21 | - namespace: thingsboard | |
22 | -spec: | |
23 | - selector: | |
24 | - matchLabels: | |
25 | - app: zookeeper | |
26 | - template: | |
27 | - metadata: | |
28 | - labels: | |
29 | - app: zookeeper | |
30 | - spec: | |
31 | - containers: | |
32 | - - name: server | |
33 | - imagePullPolicy: Always | |
34 | - image: zookeeper:3.5 | |
35 | - ports: | |
36 | - - containerPort: 2181 | |
37 | - readinessProbe: | |
38 | - periodSeconds: 5 | |
39 | - tcpSocket: | |
40 | - port: 2181 | |
41 | - livenessProbe: | |
42 | - periodSeconds: 5 | |
43 | - tcpSocket: | |
44 | - port: 2181 | |
45 | - env: | |
46 | - - name: ZOO_MY_ID | |
47 | - value: "1" | |
48 | - - name: ZOO_SERVERS | |
49 | - value: "server.1=0.0.0.0:2888:3888;0.0.0.0:2181" | |
50 | - restartPolicy: Always | |
51 | ---- | |
52 | -apiVersion: v1 | |
53 | -kind: Service | |
54 | -metadata: | |
55 | - name: zookeeper | |
56 | - namespace: thingsboard | |
57 | -spec: | |
58 | - type: ClusterIP | |
59 | - selector: | |
60 | - app: zookeeper | |
61 | - ports: | |
62 | - - name: zk-port | |
63 | - port: 2181 | |
64 | ---- | |
65 | -apiVersion: apps/v1 | |
66 | -kind: Deployment | |
67 | -metadata: | |
68 | - name: tb-kafka | |
69 | - namespace: thingsboard | |
70 | -spec: | |
71 | - selector: | |
72 | - matchLabels: | |
73 | - app: tb-kafka | |
74 | - template: | |
75 | - metadata: | |
76 | - labels: | |
77 | - app: tb-kafka | |
78 | - spec: | |
79 | - containers: | |
80 | - - name: server | |
81 | - imagePullPolicy: Always | |
82 | - image: wurstmeister/kafka:2.12-2.2.1 | |
83 | - ports: | |
84 | - - containerPort: 9092 | |
85 | - readinessProbe: | |
86 | - periodSeconds: 20 | |
87 | - tcpSocket: | |
88 | - port: 9092 | |
89 | - livenessProbe: | |
90 | - periodSeconds: 5 | |
91 | - tcpSocket: | |
92 | - port: 9092 | |
93 | - env: | |
94 | - - name: KAFKA_ZOOKEEPER_CONNECT | |
95 | - value: "zookeeper:2181" | |
96 | - - name: KAFKA_LISTENERS | |
97 | - value: "INSIDE://:9093,OUTSIDE://:9092" | |
98 | - - name: KAFKA_ADVERTISED_LISTENERS | |
99 | - value: "INSIDE://:9093,OUTSIDE://tb-kafka:9092" | |
100 | - - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP | |
101 | - value: "INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT" | |
102 | - - name: KAFKA_INTER_BROKER_LISTENER_NAME | |
103 | - value: "INSIDE" | |
104 | - - name: KAFKA_CREATE_TOPICS | |
105 | - value: "js.eval.requests:100:1:delete --config=retention.ms=60000 --config=segment.bytes=26214400 --config=retention.bytes=104857600,tb.transport.api.requests:30:1:delete --config=retention.ms=60000 --config=segment.bytes=26214400 --config=retention.bytes=104857600,tb.rule-engine:30:1:delete --config=retention.ms=60000 --config=segment.bytes=26214400 --config=retention.bytes=104857600" | |
106 | - - name: KAFKA_AUTO_CREATE_TOPICS_ENABLE | |
107 | - value: "false" | |
108 | - - name: KAFKA_LOG_RETENTION_BYTES | |
109 | - value: "1073741824" | |
110 | - - name: KAFKA_LOG_SEGMENT_BYTES | |
111 | - value: "268435456" | |
112 | - - name: KAFKA_LOG_RETENTION_MS | |
113 | - value: "300000" | |
114 | - - name: KAFKA_LOG_CLEANUP_POLICY | |
115 | - value: "delete" | |
116 | - restartPolicy: Always | |
117 | ---- | |
118 | -apiVersion: v1 | |
119 | -kind: Service | |
120 | -metadata: | |
121 | - name: tb-kafka | |
122 | - namespace: thingsboard | |
123 | -spec: | |
124 | - type: ClusterIP | |
125 | - selector: | |
126 | - app: tb-kafka | |
127 | - ports: | |
128 | - - name: tb-kafka-port | |
129 | - port: 9092 | |
130 | ---- | |
131 | -apiVersion: apps/v1 | |
132 | -kind: Deployment | |
133 | -metadata: | |
134 | - name: tb-redis | |
135 | - namespace: thingsboard | |
136 | -spec: | |
137 | - selector: | |
138 | - matchLabels: | |
139 | - app: tb-redis | |
140 | - template: | |
141 | - metadata: | |
142 | - labels: | |
143 | - app: tb-redis | |
144 | - spec: | |
145 | - containers: | |
146 | - - name: server | |
147 | - imagePullPolicy: Always | |
148 | - image: redis:4.0 | |
149 | - ports: | |
150 | - - containerPort: 6379 | |
151 | - readinessProbe: | |
152 | - periodSeconds: 5 | |
153 | - tcpSocket: | |
154 | - port: 6379 | |
155 | - livenessProbe: | |
156 | - periodSeconds: 5 | |
157 | - tcpSocket: | |
158 | - port: 6379 | |
159 | - volumeMounts: | |
160 | - - mountPath: /data | |
161 | - name: redis-data | |
162 | - volumes: | |
163 | - - name: redis-data | |
164 | - emptyDir: {} | |
165 | - restartPolicy: Always | |
166 | ---- | |
167 | -apiVersion: v1 | |
168 | -kind: Service | |
169 | -metadata: | |
170 | - name: tb-redis | |
171 | - namespace: thingsboard | |
172 | -spec: | |
173 | - type: ClusterIP | |
174 | - selector: | |
175 | - app: tb-redis | |
176 | - ports: | |
177 | - - name: tb-redis-port | |
178 | - port: 6379 | |
179 | ---- | |
180 | -apiVersion: apps/v1 | |
181 | -kind: Deployment | |
182 | -metadata: | |
183 | 20 | name: tb-js-executor |
184 | 21 | namespace: thingsboard |
185 | 22 | spec: |
... | ... | @@ -267,6 +104,10 @@ spec: |
267 | 104 | value: "redis" |
268 | 105 | - name: REDIS_HOST |
269 | 106 | value: "tb-redis" |
107 | + - name: REDIS_CONNECTION_TYPE | |
108 | + value: "cluster" | |
109 | + - name: REDIS_NODES | |
110 | + value: "tb-redis:6379" | |
270 | 111 | - name: HTTP_LOG_CONTROLLER_ERROR_STACK_TRACE |
271 | 112 | value: "false" |
272 | 113 | envFrom: | ... | ... |
k8s/thirdparty.yml
0 → 100644
1 | +# | |
2 | +# Copyright © 2016-2020 The Thingsboard Authors | |
3 | +# | |
4 | +# Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +# you may not use this file except in compliance with the License. | |
6 | +# You may obtain a copy of the License at | |
7 | +# | |
8 | +# http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +# | |
10 | +# Unless required by applicable law or agreed to in writing, software | |
11 | +# distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +# See the License for the specific language governing permissions and | |
14 | +# limitations under the License. | |
15 | +# | |
16 | + | |
17 | +apiVersion: apps/v1 | |
18 | +kind: StatefulSet | |
19 | +metadata: | |
20 | + name: zookeeper | |
21 | + namespace: thingsboard | |
22 | +spec: | |
23 | + serviceName: "zookeeper" | |
24 | + replicas: 3 | |
25 | + podManagementPolicy: Parallel | |
26 | + selector: | |
27 | + matchLabels: | |
28 | + app: zookeeper | |
29 | + template: | |
30 | + metadata: | |
31 | + labels: | |
32 | + app: zookeeper | |
33 | + spec: | |
34 | + containers: | |
35 | + - name: zookeeper | |
36 | + imagePullPolicy: Always | |
37 | + image: zookeeper:3.5 | |
38 | + ports: | |
39 | + - containerPort: 2181 | |
40 | + name: client | |
41 | + - containerPort: 2888 | |
42 | + name: server | |
43 | + - containerPort: 3888 | |
44 | + name: election | |
45 | + readinessProbe: | |
46 | + periodSeconds: 60 | |
47 | + tcpSocket: | |
48 | + port: 2181 | |
49 | + livenessProbe: | |
50 | + periodSeconds: 60 | |
51 | + tcpSocket: | |
52 | + port: 2181 | |
53 | + env: | |
54 | + - name: ZOO_SERVERS | |
55 | + value: "server.0=zookeeper-0.zookeeper:2888:3888;2181 server.1=zookeeper-1.zookeeper:2888:3888;2181 server.2=zookeeper-2.zookeeper:2888:3888;2181" | |
56 | + - name: JVMFLAGS | |
57 | + value: "-Dzookeeper.electionPortBindRetry=0" | |
58 | + volumeMounts: | |
59 | + - name: data | |
60 | + mountPath: /data | |
61 | + readOnly: false | |
62 | + initContainers: | |
63 | + - command: | |
64 | + - /bin/bash | |
65 | + - -c | |
66 | + - |- | |
67 | + set -ex; | |
68 | + mkdir -p "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR"; | |
69 | + chown "$ZOO_USER:$ZOO_USER" "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR" | |
70 | + if [[ ! -f "$ZOO_DATA_DIR/myid" ]]; then | |
71 | + echo $HOSTNAME| rev | cut -d "-" -f1 | rev > "$ZOO_DATA_DIR/myid" | |
72 | + fi | |
73 | + env: | |
74 | + - name: HOSTNAME | |
75 | + valueFrom: | |
76 | + fieldRef: | |
77 | + fieldPath: metadata.name | |
78 | + image: zookeeper:3.5 | |
79 | + imagePullPolicy: IfNotPresent | |
80 | + name: zookeeper-init | |
81 | + securityContext: | |
82 | + runAsUser: 0 | |
83 | + volumeMounts: | |
84 | + - name: data | |
85 | + mountPath: /data | |
86 | + readOnly: false | |
87 | + volumeClaimTemplates: | |
88 | + - metadata: | |
89 | + name: data | |
90 | + spec: | |
91 | + accessModes: [ "ReadWriteOnce" ] | |
92 | + resources: | |
93 | + requests: | |
94 | + storage: 100Mi | |
95 | +--- | |
96 | +apiVersion: v1 | |
97 | +kind: Service | |
98 | +metadata: | |
99 | + name: zookeeper | |
100 | + namespace: thingsboard | |
101 | +spec: | |
102 | + type: ClusterIP | |
103 | + ports: | |
104 | + - port: 2181 | |
105 | + targetPort: 2181 | |
106 | + name: client | |
107 | + - port: 2888 | |
108 | + targetPort: 2888 | |
109 | + name: server | |
110 | + - port: 3888 | |
111 | + targetPort: 3888 | |
112 | + name: election | |
113 | + selector: | |
114 | + app: zookeeper | |
115 | +--- | |
116 | +apiVersion: apps/v1 | |
117 | +kind: StatefulSet | |
118 | +metadata: | |
119 | + name: tb-kafka | |
120 | + namespace: thingsboard | |
121 | +spec: | |
122 | + serviceName: "tb-kafka" | |
123 | + replicas: 3 | |
124 | + podManagementPolicy: Parallel | |
125 | + selector: | |
126 | + matchLabels: | |
127 | + app: tb-kafka | |
128 | + template: | |
129 | + metadata: | |
130 | + labels: | |
131 | + app: tb-kafka | |
132 | + spec: | |
133 | + containers: | |
134 | + - name: tb-kafka | |
135 | + imagePullPolicy: Always | |
136 | + image: wurstmeister/kafka:2.12-2.2.1 | |
137 | + ports: | |
138 | + - containerPort: 9092 | |
139 | + name: kafka-int | |
140 | + readinessProbe: | |
141 | + periodSeconds: 5 | |
142 | + timeoutSeconds: 5 | |
143 | + tcpSocket: | |
144 | + port: 9092 | |
145 | + initialDelaySeconds: 60 | |
146 | + livenessProbe: | |
147 | + timeoutSeconds: 5 | |
148 | + periodSeconds: 5 | |
149 | + tcpSocket: | |
150 | + port: 9092 | |
151 | + initialDelaySeconds: 80 | |
152 | + env: | |
153 | + - name: BROKER_ID_COMMAND | |
154 | + value: "hostname | cut -d'-' -f3" | |
155 | + - name: KAFKA_ZOOKEEPER_CONNECT | |
156 | + value: "zookeeper:2181" | |
157 | + - name: KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS | |
158 | + value: "60000" | |
159 | + - name: KAFKA_UNCLEAN_LEADER_ELECTION_ENABLE | |
160 | + value: "true" | |
161 | + - name: KAFKA_LISTENERS | |
162 | + value: "INSIDE://:9092" | |
163 | + - name: KAFKA_ADVERTISED_LISTENERS | |
164 | + value: "INSIDE://:9092" | |
165 | + - name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP | |
166 | + value: "INSIDE:PLAINTEXT" | |
167 | + - name: KAFKA_INTER_BROKER_LISTENER_NAME | |
168 | + value: "INSIDE" | |
169 | + - name: KAFKA_CONTROLLER_SHUTDOWN_ENABLE | |
170 | + value: "true" | |
171 | + - name: KAFKA_CREATE_TOPICS | |
172 | + value: "js_eval.requests:100:1:delete --config=retention.ms=60000 --config=segment.bytes=26214400 --config=retention.bytes=104857600,tb_transport.api.requests:30:1:delete --config=retention.ms=60000 --config=segment.bytes=26214400 --config=retention.bytes=104857600" | |
173 | + - name: KAFKA_AUTO_CREATE_TOPICS_ENABLE | |
174 | + value: "false" | |
175 | + - name: KAFKA_LOG_RETENTION_BYTES | |
176 | + value: "1073741824" | |
177 | + - name: KAFKA_LOG_SEGMENT_BYTES | |
178 | + value: "268435456" | |
179 | + - name: KAFKA_LOG_RETENTION_MS | |
180 | + value: "300000" | |
181 | + - name: KAFKA_LOG_CLEANUP_POLICY | |
182 | + value: "delete" | |
183 | + - name: KAFKA_PORT | |
184 | + value: "9092" | |
185 | + - name: KAFKA_LOG_DIRS | |
186 | + value: "/kafka-logs" | |
187 | + volumeMounts: | |
188 | + - name: logs | |
189 | + mountPath: /kafka-logs | |
190 | + subPath: logs | |
191 | + volumeClaimTemplates: | |
192 | + - metadata: | |
193 | + name: logs | |
194 | + spec: | |
195 | + accessModes: | |
196 | + - ReadWriteOnce | |
197 | + resources: | |
198 | + requests: | |
199 | + storage: 1Gi | |
200 | +--- | |
201 | +apiVersion: v1 | |
202 | +kind: Service | |
203 | +metadata: | |
204 | + name: tb-kafka | |
205 | + namespace: thingsboard | |
206 | +spec: | |
207 | + type: ClusterIP | |
208 | + ports: | |
209 | + - port: 9092 | |
210 | + targetPort: 9092 | |
211 | + name: kafka-int | |
212 | + selector: | |
213 | + app: tb-kafka | |
214 | +--- | |
215 | +apiVersion: v1 | |
216 | +kind: ConfigMap | |
217 | +metadata: | |
218 | + name: tb-redis | |
219 | + namespace: thingsboard | |
220 | +data: | |
221 | + update-node.sh: | | |
222 | + #!/bin/sh | |
223 | + REDIS_NODES="/data/nodes.conf" | |
224 | + sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${REDIS_NODES} | |
225 | + exec "$@" | |
226 | + redis.conf: |+ | |
227 | + cluster-enabled yes | |
228 | + cluster-require-full-coverage no | |
229 | + cluster-node-timeout 15000 | |
230 | + cluster-config-file /data/nodes.conf | |
231 | + cluster-migration-barrier 1 | |
232 | + appendonly yes | |
233 | + protected-mode no | |
234 | +--- | |
235 | +apiVersion: apps/v1 | |
236 | +kind: StatefulSet | |
237 | +metadata: | |
238 | + name: tb-redis | |
239 | + namespace: thingsboard | |
240 | +spec: | |
241 | + serviceName: server | |
242 | + replicas: 6 | |
243 | + selector: | |
244 | + matchLabels: | |
245 | + app: tb-redis | |
246 | + template: | |
247 | + metadata: | |
248 | + labels: | |
249 | + app: tb-redis | |
250 | + spec: | |
251 | + containers: | |
252 | + - name: redis | |
253 | + image: redis:5.0.1-alpine | |
254 | + ports: | |
255 | + - containerPort: 6379 | |
256 | + name: client | |
257 | + - containerPort: 16379 | |
258 | + name: gossip | |
259 | + command: ["/conf/update-node.sh", "redis-server", "/conf/redis.conf"] | |
260 | + env: | |
261 | + - name: POD_IP | |
262 | + valueFrom: | |
263 | + fieldRef: | |
264 | + fieldPath: status.podIP | |
265 | + volumeMounts: | |
266 | + - name: conf | |
267 | + mountPath: /conf | |
268 | + readOnly: false | |
269 | + - name: data | |
270 | + mountPath: /data | |
271 | + readOnly: false | |
272 | + volumes: | |
273 | + - name: conf | |
274 | + configMap: | |
275 | + name: tb-redis | |
276 | + defaultMode: 0755 | |
277 | + volumeClaimTemplates: | |
278 | + - metadata: | |
279 | + name: data | |
280 | + spec: | |
281 | + accessModes: [ "ReadWriteOnce" ] | |
282 | + resources: | |
283 | + requests: | |
284 | + storage: 100Mi | |
285 | +--- | |
286 | +apiVersion: v1 | |
287 | +kind: Service | |
288 | +metadata: | |
289 | + name: tb-redis | |
290 | + namespace: thingsboard | |
291 | +spec: | |
292 | + type: ClusterIP | |
293 | + ports: | |
294 | + - port: 6379 | |
295 | + targetPort: 6379 | |
296 | + name: client | |
297 | + - port: 16379 | |
298 | + targetPort: 16379 | |
299 | + name: gossip | |
300 | + selector: | |
301 | + app: tb-redis | ... | ... |