TB-58: k8 base scripts
This commit is contained in:
parent
cd11bb6c05
commit
b39416232d
@ -2,4 +2,5 @@
|
||||
|
||||
SKIP_SCHEMA_CREATION=false
|
||||
SKIP_SYSTEM_DATA=false
|
||||
SKIP_DEMO_DATA=false
|
||||
SKIP_DEMO_DATA=false
|
||||
CASSANDRA_URL=db
|
||||
@ -20,9 +20,13 @@ 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:1.2.2 -t thingsboard/thingsboard-db-schema:latest .
|
||||
docker build -t thingsboard/thingsboard-db-schema:k8test .
|
||||
|
||||
docker login
|
||||
|
||||
docker push thingsboard/thingsboard-db-schema:1.2.2
|
||||
docker push thingsboard/thingsboard-db-schema:latest
|
||||
docker push thingsboard/thingsboard-db-schema:k8test
|
||||
|
||||
# cleanup
|
||||
rm schema.cql
|
||||
rm demo-data.cql
|
||||
rm system-data.cql
|
||||
@ -16,7 +16,7 @@
|
||||
#
|
||||
|
||||
|
||||
until nmap db -p 9042 | grep "9042/tcp open"
|
||||
until nmap $CASSANDRA_URL -p 9042 | grep "9042/tcp open"
|
||||
do
|
||||
echo "Wait for Cassandra..."
|
||||
sleep 10
|
||||
@ -24,7 +24,7 @@ done
|
||||
|
||||
if [ "$SKIP_SCHEMA_CREATION" == "false" ]; then
|
||||
echo "Creating 'Thingsboard' keyspace..."
|
||||
cqlsh db -f /root/schema.cql
|
||||
cqlsh $CASSANDRA_URL -f /root/schema.cql
|
||||
if [ "$?" -eq 0 ]; then
|
||||
echo "'Thingsboard' keyspace was successfully created!"
|
||||
else
|
||||
@ -34,7 +34,7 @@ fi
|
||||
|
||||
if [ "$SKIP_SYSTEM_DATA" == "false" ]; then
|
||||
echo "Adding system data..."
|
||||
cqlsh db -f /root/system-data.cql
|
||||
cqlsh $CASSANDRA_URL -f /root/system-data.cql
|
||||
if [ "$?" -eq 0 ]; then
|
||||
echo "System data was successfully added!"
|
||||
else
|
||||
@ -44,7 +44,7 @@ fi
|
||||
|
||||
if [ "$SKIP_DEMO_DATA" == "false" ]; then
|
||||
echo "Adding demo data..."
|
||||
cqlsh db -f /root/demo-data.cql
|
||||
cqlsh $CASSANDRA_URL -f /root/demo-data.cql
|
||||
if [ "$?" -eq 0 ]; then
|
||||
echo "Demo data was successfully added!"
|
||||
else
|
||||
|
||||
@ -18,9 +18,11 @@
|
||||
|
||||
cp ../../application/target/thingsboard.deb thingsboard.deb
|
||||
|
||||
docker build -t thingsboard/application:1.2.2 -t thingsboard/application:latest .
|
||||
docker build -t thingsboard/application:k8test .
|
||||
|
||||
docker login
|
||||
|
||||
docker push thingsboard/application:1.2.2
|
||||
docker push thingsboard/application:latest
|
||||
docker push thingsboard/application:k8test
|
||||
|
||||
# cleanup
|
||||
rm thingsboard.deb
|
||||
@ -34,6 +34,9 @@ done
|
||||
# Copying env variables into conf files
|
||||
printenv | awk -F "=" '{print "export " $1 "='\''" $2 "'\''"}' >> /usr/share/thingsboard/conf/thingsboard.conf
|
||||
|
||||
# Set env variable for RPC address
|
||||
echo "export RPC_HOST='"$(hostname -f)"'" | tee -a /usr/share/thingsboard/conf/thingsboard.conf
|
||||
|
||||
cat /usr/share/thingsboard/conf/thingsboard.conf
|
||||
|
||||
echo "Starting 'Thingsboard' service..."
|
||||
|
||||
134
kubernetes/cassandra.yaml
Normal file
134
kubernetes/cassandra.yaml
Normal file
@ -0,0 +1,134 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: cassandra
|
||||
name: cassandra
|
||||
spec:
|
||||
clusterIP: None
|
||||
ports:
|
||||
- port: 9042
|
||||
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
|
||||
replicas: 3
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: cassandra
|
||||
spec:
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- labelSelector:
|
||||
matchExpressions:
|
||||
- key: "app"
|
||||
operator: In
|
||||
values:
|
||||
- cassandra
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
containers:
|
||||
- name: cassandra
|
||||
image: gcr.io/google-samples/cassandra:v12
|
||||
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
|
||||
resources:
|
||||
limits:
|
||||
cpu: "500m"
|
||||
memory: 1Gi
|
||||
requests:
|
||||
cpu: "500m"
|
||||
memory: 1Gi
|
||||
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: 512M
|
||||
- name: HEAP_NEWSIZE
|
||||
value: 100M
|
||||
- name: CASSANDRA_SEEDS
|
||||
value: "cassandra-0.cassandra.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
|
||||
# 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
|
||||
- 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
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: cassandra-data
|
||||
annotations:
|
||||
volume.beta.kubernetes.io/storage-class: regular
|
||||
spec:
|
||||
accessModes: [ "ReadWriteOnce" ]
|
||||
resources:
|
||||
requests:
|
||||
storage: 2Gi
|
||||
- metadata:
|
||||
name: cassandra-commitlog
|
||||
annotations:
|
||||
volume.beta.kubernetes.io/storage-class: regular
|
||||
spec:
|
||||
accessModes: [ "ReadWriteOnce" ]
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
22
kubernetes/thingsboard-schema.yaml
Normal file
22
kubernetes/thingsboard-schema.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: tb-db-schema-deployment
|
||||
spec:
|
||||
containers:
|
||||
- name: tb-db-schema-k8
|
||||
image: thingsboard/thingsboard-db-schema:k8test
|
||||
env:
|
||||
- name: SKIP_SCHEMA_CREATION
|
||||
value: "false"
|
||||
- name: SKIP_SYSTEM_DATA
|
||||
value: "false"
|
||||
- name : SKIP_DEMO_DATA
|
||||
value: "false"
|
||||
- name : CASSANDRA_URL
|
||||
value: "cassandra"
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- ./install_schema.sh
|
||||
restartPolicy: Never
|
||||
105
kubernetes/thingsboard.yaml
Normal file
105
kubernetes/thingsboard.yaml
Normal file
@ -0,0 +1,105 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: thingsboard-external
|
||||
labels:
|
||||
app: thingsboard-external
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
name: ui
|
||||
- port: 1883
|
||||
name: mqtt
|
||||
- port: 5683
|
||||
name: coap
|
||||
- port: 9001
|
||||
name: rpc
|
||||
selector:
|
||||
app: thingsboard
|
||||
type: LoadBalancer
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: thingsboard-headless
|
||||
labels:
|
||||
app: thingsboard-headless
|
||||
spec:
|
||||
ports:
|
||||
- port: 8080
|
||||
name: ui
|
||||
- port: 1883
|
||||
name: mqtt
|
||||
- port: 5683
|
||||
name: coap
|
||||
- port: 9001
|
||||
name: rpc
|
||||
selector:
|
||||
app: thingsboard
|
||||
clusterIP: None
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: tb-config
|
||||
data:
|
||||
zookeeper.enabled: "true"
|
||||
zookeeper.url: "zk-headless"
|
||||
cassandra.url: "cassandra:9042"
|
||||
---
|
||||
apiVersion: apps/v1beta1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: tb
|
||||
spec:
|
||||
serviceName: "thingsboard-headless"
|
||||
replicas: 2
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: thingsboard
|
||||
spec:
|
||||
terminationGracePeriodSeconds: 10
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- labelSelector:
|
||||
matchExpressions:
|
||||
- key: "app"
|
||||
operator: In
|
||||
values:
|
||||
- thingsboard-headless
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
containers:
|
||||
- name: thingsboard
|
||||
image: thingsboard/application:k8test
|
||||
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
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- ./run_thingsboard.sh
|
||||
@ -20,7 +20,7 @@ metadata:
|
||||
name: zk-config
|
||||
data:
|
||||
ensemble: "zk-0;zk-1;zk-2"
|
||||
jvm.heap: "2G"
|
||||
jvm.heap: "1G"
|
||||
tick: "2000"
|
||||
init: "10"
|
||||
sync: "5"
|
||||
@ -51,34 +51,25 @@ spec:
|
||||
app: zk
|
||||
annotations:
|
||||
pod.alpha.kubernetes.io/initialized: "true"
|
||||
scheduler.alpha.kubernetes.io/affinity: >
|
||||
{
|
||||
"podAntiAffinity": {
|
||||
"requiredDuringSchedulingIgnoredDuringExecution": [
|
||||
{
|
||||
"labelSelector": {
|
||||
"matchExpressions": [
|
||||
{
|
||||
"key": "app",
|
||||
"operator": "In",
|
||||
"values": [ "zk-headless" ]
|
||||
}
|
||||
]
|
||||
},
|
||||
"topologyKey": "kubernetes.io/hostname"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
spec:
|
||||
affinity:
|
||||
podAntiAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
- labelSelector:
|
||||
matchExpressions:
|
||||
- key: "app"
|
||||
operator: In
|
||||
values:
|
||||
- zk-headless
|
||||
topologyKey: "kubernetes.io/hostname"
|
||||
containers:
|
||||
- name: k8szk
|
||||
imagePullPolicy: Always
|
||||
image: gcr.io/google_samples/k8szk:v1
|
||||
resources:
|
||||
requests:
|
||||
memory: "1Gi"
|
||||
cpu: "0.5"
|
||||
memory: "0.5Gi"
|
||||
cpu: "0.2"
|
||||
ports:
|
||||
- containerPort: 2181
|
||||
name: client
|
||||
@ -164,4 +155,4 @@ spec:
|
||||
accessModes: [ "ReadWriteOnce" ]
|
||||
resources:
|
||||
requests:
|
||||
storage: 20Gi
|
||||
storage: 1Gi
|
||||
Loading…
x
Reference in New Issue
Block a user