18 changed files with 823 additions and 70 deletions
@ -0,0 +1,9 @@ |
|||
VERSION=k8stest |
|||
PROJECT=thingsboard |
|||
APP=cassandra |
|||
|
|||
build: |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -0,0 +1,132 @@ |
|||
# |
|||
# 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. |
|||
# |
|||
|
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
name: cassandra-headless |
|||
labels: |
|||
app: cassandra-headless |
|||
spec: |
|||
ports: |
|||
- port: 9042 |
|||
name: cql |
|||
clusterIP: None |
|||
selector: |
|||
app: cassandra |
|||
--- |
|||
apiVersion: "apps/v1beta1" |
|||
kind: StatefulSet |
|||
metadata: |
|||
name: cassandra |
|||
spec: |
|||
serviceName: cassandra-headless |
|||
replicas: 2 |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: cassandra |
|||
spec: |
|||
nodeSelector: |
|||
machinetype: other |
|||
affinity: |
|||
podAntiAffinity: |
|||
requiredDuringSchedulingIgnoredDuringExecution: |
|||
- labelSelector: |
|||
matchExpressions: |
|||
- key: "app" |
|||
operator: In |
|||
values: |
|||
- cassandra-headless |
|||
topologyKey: "kubernetes.io/hostname" |
|||
containers: |
|||
- name: cassandra |
|||
image: thingsboard/cassandra:k8stest |
|||
imagePullPolicy: Always |
|||
ports: |
|||
- containerPort: 7000 |
|||
name: intra-node |
|||
- containerPort: 7001 |
|||
name: tls-intra-node |
|||
- containerPort: 7199 |
|||
name: jmx |
|||
- containerPort: 9042 |
|||
name: cql |
|||
- containerPort: 9160 |
|||
name: thrift |
|||
securityContext: |
|||
capabilities: |
|||
add: |
|||
- IPC_LOCK |
|||
lifecycle: |
|||
preStop: |
|||
exec: |
|||
command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"] |
|||
env: |
|||
- name: MAX_HEAP_SIZE |
|||
value: 2048M |
|||
- name: HEAP_NEWSIZE |
|||
value: 100M |
|||
- name: CASSANDRA_SEEDS |
|||
value: "cassandra-0.cassandra-headless.default.svc.cluster.local" |
|||
- name: CASSANDRA_CLUSTER_NAME |
|||
value: "K8Demo" |
|||
- name: CASSANDRA_DC |
|||
value: "DC1-K8Demo" |
|||
- name: CASSANDRA_RACK |
|||
value: "Rack1-K8Demo" |
|||
- name: CASSANDRA_AUTO_BOOTSTRAP |
|||
value: "false" |
|||
- name: POD_IP |
|||
valueFrom: |
|||
fieldRef: |
|||
fieldPath: status.podIP |
|||
- name: POD_NAMESPACE |
|||
valueFrom: |
|||
fieldRef: |
|||
fieldPath: metadata.namespace |
|||
readinessProbe: |
|||
exec: |
|||
command: |
|||
- /bin/bash |
|||
- -c |
|||
- /ready-probe.sh |
|||
initialDelaySeconds: 15 |
|||
timeoutSeconds: 5 |
|||
volumeMounts: |
|||
- name: cassandra-data |
|||
mountPath: /var/lib/cassandra/data |
|||
- name: cassandra-commitlog |
|||
mountPath: /var/lib/cassandra/commitlog |
|||
volumeClaimTemplates: |
|||
- metadata: |
|||
name: cassandra-data |
|||
annotations: |
|||
volume.beta.kubernetes.io/storage-class: fast |
|||
spec: |
|||
accessModes: [ "ReadWriteOnce" ] |
|||
resources: |
|||
requests: |
|||
storage: 3Gi |
|||
- metadata: |
|||
name: cassandra-commitlog |
|||
annotations: |
|||
volume.beta.kubernetes.io/storage-class: fast |
|||
spec: |
|||
accessModes: [ "ReadWriteOnce" ] |
|||
resources: |
|||
requests: |
|||
storage: 2Gi |
|||
@ -0,0 +1,13 @@ |
|||
VERSION=k8stest |
|||
PROJECT=thingsboard |
|||
APP=thingsboard-db-schema |
|||
|
|||
build: |
|||
cp ../../dao/src/main/resources/schema.cql . |
|||
cp ../../dao/src/main/resources/demo-data.cql . |
|||
cp ../../dao/src/main/resources/system-data.cql . |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
rm schema.cql demo-data.cql system-data.cql |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -0,0 +1,39 @@ |
|||
# |
|||
# 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. |
|||
# |
|||
|
|||
apiVersion: v1 |
|||
kind: Pod |
|||
metadata: |
|||
name: tb-db-schema |
|||
spec: |
|||
containers: |
|||
- name: tb-db-schema |
|||
imagePullPolicy: Always |
|||
image: thingsboard/thingsboard-db-schema:k8stest |
|||
env: |
|||
- name: SKIP_SCHEMA_CREATION |
|||
value: "false" |
|||
- name: SKIP_SYSTEM_DATA |
|||
value: "false" |
|||
- name : SKIP_DEMO_DATA |
|||
value: "false" |
|||
- name : CASSANDRA_URL |
|||
value: "cassandra-headless" |
|||
command: |
|||
- sh |
|||
- -c |
|||
- ./install_schema.sh |
|||
restartPolicy: Never |
|||
@ -0,0 +1,11 @@ |
|||
VERSION=k8stest |
|||
PROJECT=thingsboard |
|||
APP=application |
|||
|
|||
build: |
|||
cp ../../application/target/thingsboard.deb . |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
rm thingsboard.deb |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -0,0 +1,121 @@ |
|||
# |
|||
# 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. |
|||
# |
|||
|
|||
--- |
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
name: tb-service |
|||
labels: |
|||
app: tb-service |
|||
spec: |
|||
ports: |
|||
- port: 8080 |
|||
name: ui |
|||
- port: 1883 |
|||
name: mqtt |
|||
- port: 5683 |
|||
name: coap |
|||
selector: |
|||
app: tb |
|||
type: LoadBalancer |
|||
--- |
|||
apiVersion: policy/v1beta1 |
|||
kind: PodDisruptionBudget |
|||
metadata: |
|||
name: tb-budget |
|||
spec: |
|||
selector: |
|||
matchLabels: |
|||
app: tb |
|||
minAvailable: 3 |
|||
--- |
|||
apiVersion: v1 |
|||
kind: ConfigMap |
|||
metadata: |
|||
name: tb-config |
|||
data: |
|||
zookeeper.enabled: "true" |
|||
zookeeper.url: "zk-headless" |
|||
cassandra.url: "cassandra-headless:9042" |
|||
--- |
|||
apiVersion: apps/v1beta1 |
|||
kind: StatefulSet |
|||
metadata: |
|||
name: tb |
|||
spec: |
|||
serviceName: "tb-service" |
|||
replicas: 3 |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: tb |
|||
spec: |
|||
nodeSelector: |
|||
machinetype: tb |
|||
affinity: |
|||
podAntiAffinity: |
|||
requiredDuringSchedulingIgnoredDuringExecution: |
|||
- labelSelector: |
|||
matchExpressions: |
|||
- key: "app" |
|||
operator: In |
|||
values: |
|||
- tb-service |
|||
topologyKey: "kubernetes.io/hostname" |
|||
containers: |
|||
- name: tb |
|||
imagePullPolicy: Always |
|||
image: thingsboard/application:k8stest |
|||
ports: |
|||
- containerPort: 8080 |
|||
name: ui |
|||
- containerPort: 1883 |
|||
name: mqtt |
|||
- containerPort: 5683 |
|||
name: coap |
|||
- containerPort: 9001 |
|||
name: rpc |
|||
env: |
|||
- name: ZOOKEEPER_ENABLED |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: tb-config |
|||
key: zookeeper.enabled |
|||
- name: ZOOKEEPER_URL |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: tb-config |
|||
key: zookeeper.url |
|||
- name : CASSANDRA_URL |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: tb-config |
|||
key: cassandra.url |
|||
- name : RPC_HOST |
|||
valueFrom: |
|||
fieldRef: |
|||
fieldPath: status.podIP |
|||
command: |
|||
- sh |
|||
- -c |
|||
- ./run_thingsboard.sh |
|||
livenessProbe: |
|||
httpGet: |
|||
path: /login |
|||
port: ui-port |
|||
initialDelaySeconds: 120 |
|||
timeoutSeconds: 10 |
|||
@ -0,0 +1,71 @@ |
|||
# |
|||
# 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. |
|||
# |
|||
|
|||
FROM ubuntu:16.04 |
|||
ENV ZK_USER=zookeeper \ |
|||
ZK_DATA_DIR=/var/lib/zookeeper/data \ |
|||
ZK_DATA_LOG_DIR=/var/lib/zookeeper/log \ |
|||
ZK_LOG_DIR=/var/log/zookeeper \ |
|||
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 |
|||
|
|||
ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D |
|||
ARG ZK_DIST=zookeeper-3.4.9 |
|||
RUN set -x \ |
|||
&& apt-get update \ |
|||
&& apt-get install -y openjdk-8-jre-headless wget netcat-openbsd \ |
|||
&& wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz" \ |
|||
&& wget -q "http://www.apache.org/dist/zookeeper/$ZK_DIST/$ZK_DIST.tar.gz.asc" \ |
|||
&& export GNUPGHOME="$(mktemp -d)" \ |
|||
&& gpg --keyserver ha.pool.sks-keyservers.net --recv-key "$GPG_KEY" \ |
|||
&& gpg --batch --verify "$ZK_DIST.tar.gz.asc" "$ZK_DIST.tar.gz" \ |
|||
&& tar -xzf "$ZK_DIST.tar.gz" -C /opt \ |
|||
&& rm -r "$GNUPGHOME" "$ZK_DIST.tar.gz" "$ZK_DIST.tar.gz.asc" \ |
|||
&& ln -s /opt/$ZK_DIST /opt/zookeeper \ |
|||
&& rm -rf /opt/zookeeper/CHANGES.txt \ |
|||
/opt/zookeeper/README.txt \ |
|||
/opt/zookeeper/NOTICE.txt \ |
|||
/opt/zookeeper/CHANGES.txt \ |
|||
/opt/zookeeper/README_packaging.txt \ |
|||
/opt/zookeeper/build.xml \ |
|||
/opt/zookeeper/config \ |
|||
/opt/zookeeper/contrib \ |
|||
/opt/zookeeper/dist-maven \ |
|||
/opt/zookeeper/docs \ |
|||
/opt/zookeeper/ivy.xml \ |
|||
/opt/zookeeper/ivysettings.xml \ |
|||
/opt/zookeeper/recipes \ |
|||
/opt/zookeeper/src \ |
|||
/opt/zookeeper/$ZK_DIST.jar.asc \ |
|||
/opt/zookeeper/$ZK_DIST.jar.md5 \ |
|||
/opt/zookeeper/$ZK_DIST.jar.sha1 \ |
|||
&& apt-get autoremove -y wget \ |
|||
&& rm -rf /var/lib/apt/lists/* |
|||
|
|||
#Copy configuration generator script to bin |
|||
COPY zkGenConfig.sh zkOk.sh /opt/zookeeper/bin/ |
|||
|
|||
# Create a user for the zookeeper process and configure file system ownership |
|||
# for nessecary directories and symlink the distribution as a user executable |
|||
RUN set -x \ |
|||
&& useradd $ZK_USER \ |
|||
&& [ `id -u $ZK_USER` -eq 1000 ] \ |
|||
&& [ `id -g $ZK_USER` -eq 1000 ] \ |
|||
&& mkdir -p $ZK_DATA_DIR $ZK_DATA_LOG_DIR $ZK_LOG_DIR /usr/share/zookeeper /tmp/zookeeper /usr/etc/ \ |
|||
&& chown -R "$ZK_USER:$ZK_USER" /opt/$ZK_DIST $ZK_DATA_DIR $ZK_LOG_DIR $ZK_DATA_LOG_DIR /tmp/zookeeper \ |
|||
&& ln -s /opt/zookeeper/conf/ /usr/etc/zookeeper \ |
|||
&& ln -s /opt/zookeeper/bin/* /usr/bin \ |
|||
&& ln -s /opt/zookeeper/$ZK_DIST.jar /usr/share/zookeeper/ \ |
|||
&& ln -s /opt/zookeeper/lib/* /usr/share/zookeeper |
|||
@ -0,0 +1,9 @@ |
|||
VERSION=k8stest |
|||
PROJECT=thingsboard |
|||
APP=zk |
|||
|
|||
build: |
|||
docker build --pull -t ${PROJECT}/${APP}:${VERSION} . |
|||
|
|||
push: build |
|||
docker push ${PROJECT}/${APP}:${VERSION} |
|||
@ -0,0 +1,153 @@ |
|||
#!/usr/bin/env 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. |
|||
# |
|||
|
|||
ZK_USER=${ZK_USER:-"zookeeper"} |
|||
ZK_LOG_LEVEL=${ZK_LOG_LEVEL:-"INFO"} |
|||
ZK_DATA_DIR=${ZK_DATA_DIR:-"/var/lib/zookeeper/data"} |
|||
ZK_DATA_LOG_DIR=${ZK_DATA_LOG_DIR:-"/var/lib/zookeeper/log"} |
|||
ZK_LOG_DIR=${ZK_LOG_DIR:-"var/log/zookeeper"} |
|||
ZK_CONF_DIR=${ZK_CONF_DIR:-"/opt/zookeeper/conf"} |
|||
ZK_CLIENT_PORT=${ZK_CLIENT_PORT:-2181} |
|||
ZK_SERVER_PORT=${ZK_SERVER_PORT:-2888} |
|||
ZK_ELECTION_PORT=${ZK_ELECTION_PORT:-3888} |
|||
ZK_TICK_TIME=${ZK_TICK_TIME:-2000} |
|||
ZK_INIT_LIMIT=${ZK_INIT_LIMIT:-10} |
|||
ZK_SYNC_LIMIT=${ZK_SYNC_LIMIT:-5} |
|||
ZK_HEAP_SIZE=${ZK_HEAP_SIZE:-2G} |
|||
ZK_MAX_CLIENT_CNXNS=${ZK_MAX_CLIENT_CNXNS:-60} |
|||
ZK_MIN_SESSION_TIMEOUT=${ZK_MIN_SESSION_TIMEOUT:- $((ZK_TICK_TIME*2))} |
|||
ZK_MAX_SESSION_TIMEOUT=${ZK_MAX_SESSION_TIMEOUT:- $((ZK_TICK_TIME*20))} |
|||
ZK_SNAP_RETAIN_COUNT=${ZK_SNAP_RETAIN_COUNT:-3} |
|||
ZK_PURGE_INTERVAL=${ZK_PURGE_INTERVAL:-0} |
|||
ID_FILE="$ZK_DATA_DIR/myid" |
|||
ZK_CONFIG_FILE="$ZK_CONF_DIR/zoo.cfg" |
|||
LOGGER_PROPS_FILE="$ZK_CONF_DIR/log4j.properties" |
|||
JAVA_ENV_FILE="$ZK_CONF_DIR/java.env" |
|||
HOST=`hostname -s` |
|||
DOMAIN=`hostname -d` |
|||
|
|||
function print_servers() { |
|||
for (( i=1; i<=$ZK_REPLICAS; i++ )) |
|||
do |
|||
echo "server.$i=$NAME-$((i-1)).$DOMAIN:$ZK_SERVER_PORT:$ZK_ELECTION_PORT" |
|||
done |
|||
} |
|||
|
|||
function validate_env() { |
|||
echo "Validating environment" |
|||
if [ -z $ZK_REPLICAS ]; then |
|||
echo "ZK_REPLICAS is a mandatory environment variable" |
|||
exit 1 |
|||
fi |
|||
|
|||
if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then |
|||
NAME=${BASH_REMATCH[1]} |
|||
ORD=${BASH_REMATCH[2]} |
|||
else |
|||
echo "Failed to extract ordinal from hostname $HOST" |
|||
exit 1 |
|||
fi |
|||
MY_ID=$((ORD+1)) |
|||
echo "ZK_REPLICAS=$ZK_REPLICAS" |
|||
echo "MY_ID=$MY_ID" |
|||
echo "ZK_LOG_LEVEL=$ZK_LOG_LEVEL" |
|||
echo "ZK_DATA_DIR=$ZK_DATA_DIR" |
|||
echo "ZK_DATA_LOG_DIR=$ZK_DATA_LOG_DIR" |
|||
echo "ZK_LOG_DIR=$ZK_LOG_DIR" |
|||
echo "ZK_CLIENT_PORT=$ZK_CLIENT_PORT" |
|||
echo "ZK_SERVER_PORT=$ZK_SERVER_PORT" |
|||
echo "ZK_ELECTION_PORT=$ZK_ELECTION_PORT" |
|||
echo "ZK_TICK_TIME=$ZK_TICK_TIME" |
|||
echo "ZK_INIT_LIMIT=$ZK_INIT_LIMIT" |
|||
echo "ZK_SYNC_LIMIT=$ZK_SYNC_LIMIT" |
|||
echo "ZK_MAX_CLIENT_CNXNS=$ZK_MAX_CLIENT_CNXNS" |
|||
echo "ZK_MIN_SESSION_TIMEOUT=$ZK_MIN_SESSION_TIMEOUT" |
|||
echo "ZK_MAX_SESSION_TIMEOUT=$ZK_MAX_SESSION_TIMEOUT" |
|||
echo "ZK_HEAP_SIZE=$ZK_HEAP_SIZE" |
|||
echo "ZK_SNAP_RETAIN_COUNT=$ZK_SNAP_RETAIN_COUNT" |
|||
echo "ZK_PURGE_INTERVAL=$ZK_PURGE_INTERVAL" |
|||
echo "ENSEMBLE" |
|||
print_servers |
|||
echo "Environment validation successful" |
|||
} |
|||
|
|||
function create_config() { |
|||
rm -f $ZK_CONFIG_FILE |
|||
echo "Creating ZooKeeper configuration" |
|||
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 |
|||
echo "tickTime=$ZK_TICK_TIME" >> $ZK_CONFIG_FILE |
|||
echo "initLimit=$ZK_INIT_LIMIT" >> $ZK_CONFIG_FILE |
|||
echo "syncLimit=$ZK_SYNC_LIMIT" >> $ZK_CONFIG_FILE |
|||
echo "maxClientCnxns=$ZK_MAX_CLIENT_CNXNS" >> $ZK_CONFIG_FILE |
|||
echo "minSessionTimeout=$ZK_MIN_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE |
|||
echo "maxSessionTimeout=$ZK_MAX_SESSION_TIMEOUT" >> $ZK_CONFIG_FILE |
|||
echo "autopurge.snapRetainCount=$ZK_SNAP_RETAIN_COUNT" >> $ZK_CONFIG_FILE |
|||
echo "autopurge.purgeInteval=$ZK_PURGE_INTERVAL" >> $ZK_CONFIG_FILE |
|||
|
|||
if [ $ZK_REPLICAS -gt 1 ]; then |
|||
print_servers >> $ZK_CONFIG_FILE |
|||
fi |
|||
echo "Wrote ZooKeeper configuration file to $ZK_CONFIG_FILE" |
|||
} |
|||
|
|||
function create_data_dirs() { |
|||
echo "Creating ZooKeeper data directories and setting permissions" |
|||
if [ ! -d $ZK_DATA_DIR ]; then |
|||
mkdir -p $ZK_DATA_DIR |
|||
chown -R $ZK_USER:$ZK_USER $ZK_DATA_DIR |
|||
fi |
|||
|
|||
if [ ! -d $ZK_DATA_LOG_DIR ]; then |
|||
mkdir -p $ZK_DATA_LOG_DIR |
|||
chown -R $ZK_USER:$ZK_USER $ZK_DATA_LOG_DIR |
|||
fi |
|||
|
|||
if [ ! -d $ZK_LOG_DIR ]; then |
|||
mkdir -p $ZK_LOG_DIR |
|||
chown -R $ZK_USER:$ZK_USER $ZK_LOG_DIR |
|||
fi |
|||
if [ ! -f $ID_FILE ]; then |
|||
echo $MY_ID >> $ID_FILE |
|||
fi |
|||
echo "Created ZooKeeper data directories and set permissions in $ZK_DATA_DIR" |
|||
} |
|||
|
|||
function create_log_props () { |
|||
rm -f $LOGGER_PROPS_FILE |
|||
echo "Creating ZooKeeper log4j configuration" |
|||
echo "zookeeper.root.logger=CONSOLE" >> $LOGGER_PROPS_FILE |
|||
echo "zookeeper.console.threshold="$ZK_LOG_LEVEL >> $LOGGER_PROPS_FILE |
|||
echo "log4j.rootLogger=\${zookeeper.root.logger}" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout" >> $LOGGER_PROPS_FILE |
|||
echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n" >> $LOGGER_PROPS_FILE |
|||
echo "Wrote log4j configuration to $LOGGER_PROPS_FILE" |
|||
} |
|||
|
|||
function create_java_env() { |
|||
rm -f $JAVA_ENV_FILE |
|||
echo "Creating JVM configuration file" |
|||
echo "ZOO_LOG_DIR=$ZK_LOG_DIR" >> $JAVA_ENV_FILE |
|||
echo "JVMFLAGS=\"-Xmx$ZK_HEAP_SIZE -Xms$ZK_HEAP_SIZE\"" >> $JAVA_ENV_FILE |
|||
echo "Wrote JVM configuration to $JAVA_ENV_FILE" |
|||
} |
|||
|
|||
validate_env && create_config && create_log_props && create_data_dirs && create_java_env |
|||
@ -0,0 +1,190 @@ |
|||
# |
|||
# 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. |
|||
# |
|||
|
|||
apiVersion: v1 |
|||
kind: Service |
|||
metadata: |
|||
name: zk-headless |
|||
labels: |
|||
app: zk-headless |
|||
spec: |
|||
ports: |
|||
- port: 2888 |
|||
name: server |
|||
- port: 3888 |
|||
name: leader-election |
|||
clusterIP: None |
|||
selector: |
|||
app: zk |
|||
--- |
|||
apiVersion: v1 |
|||
kind: ConfigMap |
|||
metadata: |
|||
name: zk-config |
|||
data: |
|||
ensemble: "zk-0;zk-1" |
|||
replicas: "3" |
|||
jvm.heap: "500m" |
|||
tick: "2000" |
|||
init: "10" |
|||
sync: "5" |
|||
client.cnxns: "60" |
|||
snap.retain: "3" |
|||
purge.interval: "1" |
|||
client.port: "2181" |
|||
server.port: "2888" |
|||
election.port: "3888" |
|||
--- |
|||
apiVersion: policy/v1beta1 |
|||
kind: PodDisruptionBudget |
|||
metadata: |
|||
name: zk-budget |
|||
spec: |
|||
selector: |
|||
matchLabels: |
|||
app: zk |
|||
minAvailable: 2 |
|||
--- |
|||
apiVersion: apps/v1beta1 |
|||
kind: StatefulSet |
|||
metadata: |
|||
name: zk |
|||
spec: |
|||
serviceName: zk-headless |
|||
replicas: 2 |
|||
template: |
|||
metadata: |
|||
labels: |
|||
app: zk |
|||
annotations: |
|||
pod.alpha.kubernetes.io/initialized: "true" |
|||
spec: |
|||
nodeSelector: |
|||
machinetype: other |
|||
affinity: |
|||
podAntiAffinity: |
|||
requiredDuringSchedulingIgnoredDuringExecution: |
|||
- labelSelector: |
|||
matchExpressions: |
|||
- key: "app" |
|||
operator: In |
|||
values: |
|||
- zk-headless |
|||
topologyKey: "kubernetes.io/hostname" |
|||
containers: |
|||
- name: zk |
|||
imagePullPolicy: Always |
|||
image: thingsboard/zk:k8stest |
|||
ports: |
|||
- containerPort: 2181 |
|||
name: client |
|||
- containerPort: 2888 |
|||
name: server |
|||
- containerPort: 3888 |
|||
name: leader-election |
|||
env: |
|||
- name : ZK_ENSEMBLE |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: ensemble |
|||
- name : ZK_REPLICAS |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: replicas |
|||
- name : ZK_HEAP_SIZE |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: jvm.heap |
|||
- name : ZK_TICK_TIME |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: tick |
|||
- name : ZK_INIT_LIMIT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: init |
|||
- name : ZK_SYNC_LIMIT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: tick |
|||
- name : ZK_MAX_CLIENT_CNXNS |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: client.cnxns |
|||
- name: ZK_SNAP_RETAIN_COUNT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: snap.retain |
|||
- name: ZK_PURGE_INTERVAL |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: purge.interval |
|||
- name: ZK_CLIENT_PORT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: client.port |
|||
- name: ZK_SERVER_PORT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: server.port |
|||
- name: ZK_ELECTION_PORT |
|||
valueFrom: |
|||
configMapKeyRef: |
|||
name: zk-config |
|||
key: election.port |
|||
command: |
|||
- sh |
|||
- -c |
|||
- zkGenConfig.sh && zkServer.sh start-foreground |
|||
readinessProbe: |
|||
exec: |
|||
command: |
|||
- "zkOk.sh" |
|||
initialDelaySeconds: 15 |
|||
timeoutSeconds: 5 |
|||
livenessProbe: |
|||
exec: |
|||
command: |
|||
- "zkOk.sh" |
|||
initialDelaySeconds: 15 |
|||
timeoutSeconds: 5 |
|||
volumeMounts: |
|||
- name: zkdatadir |
|||
mountPath: /var/lib/zookeeper |
|||
securityContext: |
|||
runAsUser: 1000 |
|||
fsGroup: 1000 |
|||
volumeClaimTemplates: |
|||
- metadata: |
|||
name: zkdatadir |
|||
annotations: |
|||
volume.beta.kubernetes.io/storage-class: slow |
|||
spec: |
|||
accessModes: [ "ReadWriteOnce" ] |
|||
resources: |
|||
requests: |
|||
storage: 1Gi |
|||
Loading…
Reference in new issue