Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TUBEMQ-241] add k8s helm chart for tubemq #164

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions tubemq-docker/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#### TubeMQ Docker
##### maven build
##### Maven build for docker image
```
mvn -f ../pom.xml clean install -DskipTests -Pdocker
```
```

##### TubeMQ on Kubernetes
[the Helm Chart for TubeMQ](tubemq-k8s/README.md)
21 changes: 21 additions & 0 deletions tubemq-docker/tubemq-k8s/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
31 changes: 31 additions & 0 deletions tubemq-docker/tubemq-k8s/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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
description: a trillion-records-scale distributed messaging queue (MQ) system
name: tubemq-k8s
version: 1.0.0
appVersion: 0.5.0
home: https://tubemq.apache.org/
sources:
- https://github.com/apache/incubator-tubemq
icon: https://tubemq.apache.org/img/first-page-bg.jpg
maintainers:
- name: dockerzhang
email: dockerzhang@tencent.com
50 changes: 50 additions & 0 deletions tubemq-docker/tubemq-k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
### the Helm Chart for TubeMQ
This helm chart provides an implementation of the TubeMQ StatefulSet, include Master/Broker/ZooKeeper services.

#### Prerequisites
- Kubernetes 1.10+
- Helm 3.0+
- A dynamic provisioner for the PersistentVolumes(`production environment`)

#### Installing the Chart
You can install the chart with the release name `tubemq` as below.
```
$ kubectl create namespace tubemq
$ helm upgrade tubemq --install -n tubemq ./
```
Installed Components
You can use `kubectl get po -n tubemq` to view all of the installed components.
```
NAME READY STATUS RESTARTS AGE
tubemq-k8s-broker-0 1/1 Running 0 2m36s
tubemq-k8s-broker-1 1/1 Running 0 54s
tubemq-k8s-broker-2 1/1 Running 0 30s
tubemq-k8s-master-0 1/1 Running 0 2m36s
tubemq-k8s-zookeeper-0 1/1 Running 0 2m36s
tubemq-k8s-zookeeper-1 1/1 Running 0 116s
tubemq-k8s-zookeeper-2 1/1 Running 0 86s
```
#### Configuration
The following table lists the configurable parameters of the `tubemq-k8s` chart and their default values.
| Parameter | Description | Default |
| :--: | :--:| :--: |
| images.tubemq_all.repository | Container image repository | apachetubemq/tubemq-all |
| images.tubemq_all.tag | Container image tag | latest |
| images.tubemq_all.pullPolicy | Container pull policy | `IfNotPresent ` |
| volumes.persistence | Using Persistent | false |
| volumes.storageClassName | Persistent volume storage class | `"local-storage"` |
| affinity.anti_affinity | Container image repository | false |

You can specify each parameter using the `--set key=value[,key=value]` argument to helm install.For example,
```
$ helm upgrade tubemq --install --set master.ports.webNodePort=8081 -n tubemq ./
```

#### Uninstall
```
$ helm uninstall tubemq -n tubemq
```
You can delete all `PVC ` if any persistent volume claims used, it will lost all data.
```
$ kubectl delete pvc -n tubemq --all
```
34 changes: 34 additions & 0 deletions tubemq-docker/tubemq-k8s/templates/_broker.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{/*
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
*/}}

{{/*
Define the tubemq broker
*/}}
{{- define "tubemq.broker.service" -}}
{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}
{{- end }}

{{/*
Define the broker hostname
*/}}
{{- define "tubemq.broker.hostname" -}}
${HOSTNAME}.{{ template "tubemq.broker.service" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{- end -}}
76 changes: 76 additions & 0 deletions tubemq-docker/tubemq-k8s/templates/_helpers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{{/*
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
*/}}

{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "tubemq.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "tubemq.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "tubemq.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the common labels.
*/}}
{{- define "tubemq.standardLabels" -}}
app: {{ template "tubemq.name" . }}
chart: {{ template "tubemq.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
cluster: {{ template "tubemq.fullname" . }}
{{- end }}

{{/*
Create the template labels.
*/}}
{{- define "tubemq.template.labels" -}}
app: {{ template "tubemq.name" . }}
release: {{ .Release.Name }}
cluster: {{ template "tubemq.fullname" . }}
{{- end }}

{{/*
Create the match labels.
*/}}
{{- define "tubemq.matchLabels" -}}
app: {{ template "tubemq.name" . }}
release: {{ .Release.Name }}
{{- end }}
34 changes: 34 additions & 0 deletions tubemq-docker/tubemq-k8s/templates/_master.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{/*
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
*/}}

{{/*
Define the tubemq master
*/}}
{{- define "tubemq.master.service" -}}
{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}
{{- end }}

{{/*
Define the master hostname
*/}}
{{- define "tubemq.master.hostname" -}}
${HOSTNAME}.{{ template "tubemq.master.service" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{- end -}}
34 changes: 34 additions & 0 deletions tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{/*
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
*/}}

{{/*
Define the tubemq zookeeper
*/}}
{{- define "tubemq.zookeeper.service" -}}
{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}
{{- end }}

{{/*
Define the zookeeper hostname
*/}}
{{- define "tubemq.zookeeper.hostname" -}}
${HOSTNAME}.{{ template "tubemq.zookeeper.service" . }}.{{ .Release.Namespace }}.svc.cluster.local
{{- end -}}
75 changes: 75 additions & 0 deletions tubemq-docker/tubemq-k8s/templates/broker-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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: ConfigMap
metadata:
name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}"
namespace: {{ .Release.Namespace }}
labels:
component: {{ .Values.broker.component }}
data:
ok: |
#!/bin/sh
/opt/tubemq-server/bin/tubemq broker status

ready: |
#!/bin/sh
/opt/tubemq-server/bin/tubemq broker status

run: |
#!/bin/bash
set -a
# get pod index
HOST=$(hostname)
if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then
NAME=${BASH_REMATCH[1]}
ORD=${BASH_REMATCH[2]}
MY_POD_ID=$((ORD+1))
else
echo "Failed to extract ordinal from hostname $HOST"
exit 1
fi
# get active master and register broker
for ((i=0;i<{{ .Values.master.replicaCount }};i++)); do
master="{{ template "tubemq.fullname" $ }}-\
{{ .Values.master.component }}-$i.{{ template "tubemq.fullname" $ }}-\
{{ .Values.master.component }}.{{ .Release.Namespace }}.svc.cluster.local"
index=$(curl $master:8080/index.htm)
if [[ -n "$index" ]]; then
# add broker
curl -d "type=op_modify&method=admin_add_broker_configure&brokerId=$MY_POD_ID\
&brokerIp=$HOST&brokerPort=8123&deletePolicy=delete,168h&numPartitions=3\
&unflushThreshold=1000&acceptPublish=true&acceptSubscribe=true&unflushInterval=10000\
&createUser=docker&confModAuthToken=abc" http://$master:8080/webapi.htm
# online
curl -d "type=op_modify&method=admin_online_broker_configure&brokerId=$MY_POD_ID\
&modifyUser=docker&confModAuthToken=abc" http://$master:8080/webapi.htm
fi
# master addresses list
MASTER_LIST="$master:8000,"$MASTER_LIST
done
# generate config file
cp /opt/tubemq-server/conf/broker.ini.raw /opt/tubemq-server/conf/broker.ini
sed -i "s/REPLACE_BY_POD_ID/$MY_POD_ID/g" /opt/tubemq-server/conf/broker.ini
sed -i "s/REPLACE_BY_POD_HOSTNAME/$HOST/g" /opt/tubemq-server/conf/broker.ini
sed -i "s/REPLACE_BY_MASTER_LIST/${MASTER_LIST%?}/g" /opt/tubemq-server/conf/broker.ini
# start
/opt/tubemq-server/bin/tubemq broker start
tail -F /opt/tubemq-server/logs/broker.log