diff --git a/docker/cassandra/Dockerfile b/docker/cassandra/Dockerfile new file mode 100644 index 0000000000..72084cd0af --- /dev/null +++ b/docker/cassandra/Dockerfile @@ -0,0 +1,5 @@ +FROM cassandra:3.9 + +COPY ready-probe.sh / + +CMD ["cassandra", "-f"] \ No newline at end of file diff --git a/docker/cassandra/Makefile b/docker/cassandra/Makefile new file mode 100644 index 0000000000..ea71c6340c --- /dev/null +++ b/docker/cassandra/Makefile @@ -0,0 +1,13 @@ +VERSION=k8stest +PROJECT=thingsboard +APP=cassandra + +all: build + +build: + docker build --pull -t ${PROJECT}/${APP}:${VERSION} . + +push: build + docker push ${PROJECT}/${APP}:${VERSION} + +.PHONY: all build push \ No newline at end of file diff --git a/docker/cassandra/cassandra.yaml b/docker/cassandra/cassandra.yaml index 9333f4d939..c3772b15e1 100644 --- a/docker/cassandra/cassandra.yaml +++ b/docker/cassandra/cassandra.yaml @@ -1,30 +1,23 @@ apiVersion: v1 kind: Service metadata: + name: cassandra-headless labels: - app: cassandra - name: cassandra + app: cassandra-headless spec: - clusterIP: None ports: - port: 9042 + name: cql + clusterIP: None selector: app: cassandra --- -apiVersion: storage.k8s.io/v1beta1 -kind: StorageClass -metadata: - name: regular -provisioner: kubernetes.io/gce-pd -parameters: - type: pd-standard ---- apiVersion: "apps/v1beta1" kind: StatefulSet metadata: name: cassandra spec: - serviceName: cassandra + serviceName: cassandra-headless replicas: 3 template: metadata: @@ -39,11 +32,11 @@ spec: - key: "app" operator: In values: - - cassandra + - cassandra-headless topologyKey: "kubernetes.io/hostname" containers: - name: cassandra - image: gcr.io/google-samples/cassandra:v12 + image: thingsboard/cassandra:k8stest imagePullPolicy: Always ports: - containerPort: 7000 @@ -77,7 +70,7 @@ spec: - name: HEAP_NEWSIZE value: 100M - name: CASSANDRA_SEEDS - value: "cassandra-0.cassandra.default.svc.cluster.local" + value: "cassandra-0.cassandra-headless.default.svc.cluster.local" - name: CASSANDRA_CLUSTER_NAME value: "K8Demo" - name: CASSANDRA_DC @@ -102,22 +95,16 @@ spec: - /ready-probe.sh initialDelaySeconds: 15 timeoutSeconds: 5 - # These volume mounts are persistent. They are like inline claims, - # but not exactly because the names need to match exactly one of - # the stateful pod volumes. volumeMounts: - name: cassandra-data - mountPath: /cassandra_data + mountPath: /var/lib/cassandra/data - name: cassandra-commitlog - mountPath: /cassandra_commitlog - # These are converted to volume claims by the controller - # and mounted at the paths mentioned above. - # do not use these in production until ssd GCEPersistentDisk or other ssd pd + mountPath: /var/lib/cassandra/commitlog volumeClaimTemplates: - metadata: name: cassandra-data annotations: - volume.beta.kubernetes.io/storage-class: regular + volume.beta.kubernetes.io/storage-class: slow spec: accessModes: [ "ReadWriteOnce" ] resources: @@ -126,7 +113,7 @@ spec: - metadata: name: cassandra-commitlog annotations: - volume.beta.kubernetes.io/storage-class: regular + volume.beta.kubernetes.io/storage-class: slow spec: accessModes: [ "ReadWriteOnce" ] resources: diff --git a/docker/thingsboard/build_and_deploy.sh b/docker/cassandra/ready-probe.sh similarity index 69% rename from docker/thingsboard/build_and_deploy.sh rename to docker/cassandra/ready-probe.sh index d2d1e2cb76..989f4d90a1 100755 --- a/docker/thingsboard/build_and_deploy.sh +++ b/docker/cassandra/ready-probe.sh @@ -1,6 +1,6 @@ #!/bin/bash -# -# Copyright © 2016-2017 The Thingsboard Authors + +# Copyright 2016 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,16 +13,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# - -cp ../../application/target/thingsboard.deb thingsboard.deb - -docker build -t thingsboard/application:k8test . - -docker login - -docker push thingsboard/application:k8test - -# cleanup -rm thingsboard.deb \ No newline at end of file +if [[ $(nodetool status | grep $POD_IP) == *"UN"* ]]; then + if [[ $DEBUG ]]; then + echo "UN"; + fi + exit 0; +else + if [[ $DEBUG ]]; then + echo "Not Up"; + fi + exit 1; +fi \ No newline at end of file diff --git a/docker/common/common.yaml b/docker/common/common.yaml new file mode 100644 index 0000000000..610c027911 --- /dev/null +++ b/docker/common/common.yaml @@ -0,0 +1,9 @@ +--- +apiVersion: storage.k8s.io/v1beta1 +kind: StorageClass +metadata: + name: slow +provisioner: kubernetes.io/gce-pd +parameters: + type: pd-standard +--- \ No newline at end of file diff --git a/docker/deploy.sh b/docker/deploy.sh deleted file mode 100755 index ed69f7b0c7..0000000000 --- a/docker/deploy.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -command='docker-compose -f docker-compose.yml -f docker-compose.random.yml' - -echo "stopping images.." -$command stop - -echo "removing stopped images.." -$command rm -f - -echo "building images.." -$command build - -echo "starting images..." -$command up -d diff --git a/docker/deploy_cassandra_zookeeper.sh b/docker/deploy_cassandra_zookeeper.sh deleted file mode 100755 index a116e2130e..0000000000 --- a/docker/deploy_cassandra_zookeeper.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -command='docker-compose -f docker-compose.yml -f docker-compose.static.yml' - -echo "stopping images.." -$command stop - -echo "removing stopped images.." -$command rm -f - -echo "building images.." -$command build - -echo "starting cassandra, zookeeper, thingsboard-db-schema images..." -$command up -d db zk thingsboard-db-schema diff --git a/docker/thingsboard-db-schema/Makefile b/docker/thingsboard-db-schema/Makefile new file mode 100644 index 0000000000..653153940f --- /dev/null +++ b/docker/thingsboard-db-schema/Makefile @@ -0,0 +1,13 @@ +VERSION=k8stest +PROJECT=thingsboard +APP=thingsboard-db-schema + +all: build + +build: + docker build --pull -t ${PROJECT}/${APP}:${VERSION} . + +push: build + docker push ${PROJECT}/${APP}:${VERSION} + +.PHONY: all build push \ No newline at end of file diff --git a/docker/thingsboard-db-schema/build_and_deploy.sh b/docker/thingsboard-db-schema/build_and_deploy.sh deleted file mode 100755 index 428016c839..0000000000 --- a/docker/thingsboard-db-schema/build_and_deploy.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash -# -# Copyright © 2016-2017 The Thingsboard Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - - -cp ../../dao/src/main/resources/schema.cql schema.cql -cp ../../dao/src/main/resources/demo-data.cql demo-data.cql -cp ../../dao/src/main/resources/system-data.cql system-data.cql - -docker build -t thingsboard/thingsboard-db-schema:k8test . - -docker login - -docker push thingsboard/thingsboard-db-schema:k8test - -# cleanup -rm schema.cql -rm demo-data.cql -rm system-data.cql \ No newline at end of file diff --git a/docker/thingsboard-db-schema/thingsboard-schema.yaml b/docker/thingsboard-db-schema/thingsboard-db-schema.yaml similarity index 81% rename from docker/thingsboard-db-schema/thingsboard-schema.yaml rename to docker/thingsboard-db-schema/thingsboard-db-schema.yaml index 141e1e3d41..dbc4f587f2 100644 --- a/docker/thingsboard-db-schema/thingsboard-schema.yaml +++ b/docker/thingsboard-db-schema/thingsboard-db-schema.yaml @@ -6,7 +6,7 @@ spec: containers: - name: tb-db-schema imagePullPolicy: Always - image: thingsboard/thingsboard-db-schema:k8test + image: thingsboard/thingsboard-db-schema:k8stest env: - name: SKIP_SCHEMA_CREATION value: "false" @@ -15,7 +15,7 @@ spec: - name : SKIP_DEMO_DATA value: "false" - name : CASSANDRA_URL - value: "cassandra" + value: "cassandra-headless" command: - sh - -c diff --git a/docker/thingsboard/Makefile b/docker/thingsboard/Makefile new file mode 100644 index 0000000000..29203e30d3 --- /dev/null +++ b/docker/thingsboard/Makefile @@ -0,0 +1,13 @@ +VERSION=k8stest +PROJECT=thingsboard +APP=application + +all: build + +build: + docker build --pull -t ${PROJECT}/${APP}:${VERSION} . + +push: build + docker push ${PROJECT}/${APP}:${VERSION} + +.PHONY: all build push \ No newline at end of file diff --git a/docker/thingsboard/thingsboard.yaml b/docker/thingsboard/thingsboard.yaml index 702a7215f5..a9c1df37d8 100644 --- a/docker/thingsboard/thingsboard.yaml +++ b/docker/thingsboard/thingsboard.yaml @@ -8,13 +8,11 @@ metadata: spec: ports: - port: 8080 - name: ui-port + name: ui - port: 1883 - name: mqtt-port + name: mqtt - port: 5683 - name: coap-port - - port: 9001 - name: rpc-port + name: coap selector: app: tb type: LoadBalancer @@ -27,14 +25,8 @@ metadata: app: tb-headless spec: ports: - - port: 8080 - name: ui-port - - port: 1883 - name: mqtt-port - - port: 5683 - name: coap-port - port: 9001 - name: rpc-port + name: rpc selector: app: tb clusterIP: None @@ -56,7 +48,7 @@ metadata: data: zookeeper.enabled: "true" zookeeper.url: "zk-headless" - cassandra.url: "cassandra:9042" + cassandra.url: "cassandra-headless:9042" --- apiVersion: apps/v1beta1 kind: StatefulSet @@ -84,16 +76,23 @@ spec: containers: - name: tb imagePullPolicy: Always - image: thingsboard/application:k8test + image: thingsboard/application:k8stest ports: - containerPort: 8080 - name: ui-port + name: ui - containerPort: 1883 - name: mqtt-port + name: mqtt - containerPort: 5683 - name: coap-port + name: coap - containerPort: 9001 - name: rpc-port + name: rpc + resources: + limits: + cpu: "250m" + memory: "500Mi" + requests: + cpu: "250m" + memory: "500Mi" env: - name: ZOOKEEPER_ENABLED valueFrom: diff --git a/docker/zookeeper/Makefile b/docker/zookeeper/Makefile index a28937f1d5..4c7a8c4007 100644 --- a/docker/zookeeper/Makefile +++ b/docker/zookeeper/Makefile @@ -1,12 +1,13 @@ -VERSION=k8test +VERSION=k8stest PROJECT=thingsboard +APP=zk all: build build: - docker build --pull -t ${PROJECT}/k8szk:${VERSION} . + docker build --pull -t ${PROJECT}/${APP}:${VERSION} . push: build - docker push ${PROJECT}/k8szk:${VERSION} + docker push ${PROJECT}/${APP}:${VERSION} .PHONY: all build push diff --git a/docker/zookeeper/zkGenConfig.sh b/docker/zookeeper/zkGenConfig.sh index cef42f64f7..0b3365bcac 100755 --- a/docker/zookeeper/zkGenConfig.sh +++ b/docker/zookeeper/zkGenConfig.sh @@ -86,7 +86,7 @@ function validate_env() { function create_config() { rm -f $ZK_CONFIG_FILE echo "Creating ZooKeeper configuration" - echo "#This file was autogenerated by k8szk DO NOT EDIT" >> $ZK_CONFIG_FILE + echo "#This file was autogenerated by zk DO NOT EDIT" >> $ZK_CONFIG_FILE echo "clientPort=$ZK_CLIENT_PORT" >> $ZK_CONFIG_FILE echo "dataDir=$ZK_DATA_DIR" >> $ZK_CONFIG_FILE echo "dataLogDir=$ZK_DATA_LOG_DIR" >> $ZK_CONFIG_FILE diff --git a/docker/zookeeper/zookeeper.yaml b/docker/zookeeper/zookeeper.yaml index 4184a3ab8e..00bca9c902 100644 --- a/docker/zookeeper/zookeeper.yaml +++ b/docker/zookeeper/zookeeper.yaml @@ -20,6 +20,7 @@ metadata: name: zk-config data: ensemble: "zk-0;zk-1;zk-2" + replicas: "3" jvm.heap: "500m" tick: "2000" init: "10" @@ -27,6 +28,9 @@ data: client.cnxns: "60" snap.retain: "3" purge.interval: "1" + client.port: "2181" + server.port: "2888" + election.port: "3888" --- apiVersion: policy/v1beta1 kind: PodDisruptionBudget @@ -63,9 +67,9 @@ spec: - zk-headless topologyKey: "kubernetes.io/hostname" containers: - - name: k8szk + - name: zk imagePullPolicy: Always - image: thingsboard/k8szk:k8test + image: thingsboard/zk:k8stest resources: requests: memory: "500Mi" @@ -84,48 +88,60 @@ spec: name: zk-config key: ensemble - name : ZK_REPLICAS - value: "3" + valueFrom: + configMapKeyRef: + name: zk-config + key: replicas - name : ZK_HEAP_SIZE valueFrom: configMapKeyRef: - name: zk-config - key: jvm.heap + name: zk-config + key: jvm.heap - name : ZK_TICK_TIME valueFrom: configMapKeyRef: - name: zk-config - key: tick + name: zk-config + key: tick - name : ZK_INIT_LIMIT valueFrom: configMapKeyRef: - name: zk-config - key: init + name: zk-config + key: init - name : ZK_SYNC_LIMIT valueFrom: configMapKeyRef: - name: zk-config - key: tick + name: zk-config + key: tick - name : ZK_MAX_CLIENT_CNXNS valueFrom: configMapKeyRef: - name: zk-config - key: client.cnxns + name: zk-config + key: client.cnxns - name: ZK_SNAP_RETAIN_COUNT valueFrom: configMapKeyRef: - name: zk-config - key: snap.retain + name: zk-config + key: snap.retain - name: ZK_PURGE_INTERVAL valueFrom: configMapKeyRef: - name: zk-config - key: purge.interval + name: zk-config + key: purge.interval - name: ZK_CLIENT_PORT - value: "2181" + valueFrom: + configMapKeyRef: + name: zk-config + key: client.port - name: ZK_SERVER_PORT - value: "2888" + valueFrom: + configMapKeyRef: + name: zk-config + key: server.port - name: ZK_ELECTION_PORT - value: "3888" + valueFrom: + configMapKeyRef: + name: zk-config + key: election.port command: - sh - -c @@ -143,16 +159,16 @@ spec: initialDelaySeconds: 15 timeoutSeconds: 5 volumeMounts: - - name: datadir + - name: zkdatadir mountPath: /var/lib/zookeeper securityContext: runAsUser: 1000 fsGroup: 1000 volumeClaimTemplates: - metadata: - name: datadir + name: zkdatadir annotations: - volume.alpha.kubernetes.io/storage-class: anything + volume.beta.kubernetes.io/storage-class: slow spec: accessModes: [ "ReadWriteOnce" ] resources: