TB-58: k8s feature improvements

This commit is contained in:
volodymyr-babak 2017-05-10 21:01:06 +03:00
parent 73458484c2
commit 08e9e903f3
15 changed files with 141 additions and 180 deletions

View File

@ -0,0 +1,5 @@
FROM cassandra:3.9
COPY ready-probe.sh /
CMD ["cassandra", "-f"]

13
docker/cassandra/Makefile Normal file
View File

@ -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

View File

@ -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:

View File

@ -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
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

View File

@ -0,0 +1,9 @@
---
apiVersion: storage.k8s.io/v1beta1
kind: StorageClass
metadata:
name: slow
provisioner: kubernetes.io/gce-pd
parameters:
type: pd-standard
---

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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,7 +88,10 @@ spec:
name: zk-config
key: ensemble
- name : ZK_REPLICAS
value: "3"
valueFrom:
configMapKeyRef:
name: zk-config
key: replicas
- name : ZK_HEAP_SIZE
valueFrom:
configMapKeyRef:
@ -121,11 +128,20 @@ spec:
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: