From 14361f952c97992c9d522e7d004ac98df5f98d25 Mon Sep 17 00:00:00 2001 From: dockerzhang Date: Fri, 19 Jun 2020 13:01:39 +0800 Subject: [PATCH 1/2] [TUBEMQ-241] add k8s helm chart for tubemq --- tubemq-docker/README.md | 7 +- tubemq-docker/tubemq-k8s/.helmignore | 21 +++ tubemq-docker/tubemq-k8s/Chart.yaml | 31 ++++ tubemq-docker/tubemq-k8s/README.md | 50 ++++++ .../tubemq-k8s/templates/_broker.tpl | 13 ++ .../tubemq-k8s/templates/_helpers.yaml | 55 ++++++ .../tubemq-k8s/templates/_master.tpl | 13 ++ .../tubemq-k8s/templates/_zookeeper.tpl | 13 ++ .../templates/broker-configmap.yaml | 75 ++++++++ .../templates/broker-ini-configmap.yaml | 49 ++++++ .../tubemq-k8s/templates/broker-pdb.yaml | 35 ++++ .../tubemq-k8s/templates/broker-service.yaml | 39 +++++ .../templates/broker-statefulset.yaml | 159 +++++++++++++++++ .../templates/master-configmap.yaml | 55 ++++++ .../templates/master-ini-configmap.yaml | 55 ++++++ .../tubemq-k8s/templates/master-pdb.yaml | 35 ++++ .../tubemq-k8s/templates/master-service.yaml | 42 +++++ .../templates/master-statefulset.yaml | 161 ++++++++++++++++++ .../templates/zookeeper-configmap.yaml | 55 ++++++ .../tubemq-k8s/templates/zookeeper-pdb.yaml | 35 ++++ .../templates/zookeeper-service.yaml | 41 +++++ .../templates/zookeeper-statefulset.yaml | 143 ++++++++++++++++ tubemq-docker/tubemq-k8s/values.yaml | 158 +++++++++++++++++ 23 files changed, 1338 insertions(+), 2 deletions(-) create mode 100644 tubemq-docker/tubemq-k8s/.helmignore create mode 100644 tubemq-docker/tubemq-k8s/Chart.yaml create mode 100644 tubemq-docker/tubemq-k8s/README.md create mode 100644 tubemq-docker/tubemq-k8s/templates/_broker.tpl create mode 100644 tubemq-docker/tubemq-k8s/templates/_helpers.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/_master.tpl create mode 100644 tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl create mode 100644 tubemq-docker/tubemq-k8s/templates/broker-configmap.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/broker-ini-configmap.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/broker-pdb.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/broker-service.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/broker-statefulset.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/master-configmap.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/master-ini-configmap.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/master-pdb.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/master-service.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/master-statefulset.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/zookeeper-configmap.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/zookeeper-pdb.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/zookeeper-service.yaml create mode 100644 tubemq-docker/tubemq-k8s/templates/zookeeper-statefulset.yaml create mode 100644 tubemq-docker/tubemq-k8s/values.yaml diff --git a/tubemq-docker/README.md b/tubemq-docker/README.md index 2fa5d74635b..e8af66c0dcf 100644 --- a/tubemq-docker/README.md +++ b/tubemq-docker/README.md @@ -1,5 +1,8 @@ #### TubeMQ Docker -##### maven build +##### Maven build for docker image ``` mvn -f ../pom.xml clean install -DskipTests -Pdocker -``` \ No newline at end of file +``` + +##### TubeMQ on Kubernetes +[the Helm Chart for TubeMQ](tubemq-k8s/README.md) \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/.helmignore b/tubemq-docker/tubemq-k8s/.helmignore new file mode 100644 index 00000000000..f0c13194444 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/.helmignore @@ -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 diff --git a/tubemq-docker/tubemq-k8s/Chart.yaml b/tubemq-docker/tubemq-k8s/Chart.yaml new file mode 100644 index 00000000000..718101d76fd --- /dev/null +++ b/tubemq-docker/tubemq-k8s/Chart.yaml @@ -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 \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/README.md b/tubemq-docker/tubemq-k8s/README.md new file mode 100644 index 00000000000..f77a8fa4a52 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/README.md @@ -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 +``` \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/_broker.tpl b/tubemq-docker/tubemq-k8s/templates/_broker.tpl new file mode 100644 index 00000000000..d77fdc96f5c --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/_broker.tpl @@ -0,0 +1,13 @@ +{{/* +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 -}} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/_helpers.yaml b/tubemq-docker/tubemq-k8s/templates/_helpers.yaml new file mode 100644 index 00000000000..dc5d7e673ea --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/_helpers.yaml @@ -0,0 +1,55 @@ +{{/* 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 }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/_master.tpl b/tubemq-docker/tubemq-k8s/templates/_master.tpl new file mode 100644 index 00000000000..fee8d7f411a --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/_master.tpl @@ -0,0 +1,13 @@ +{{/* +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 -}} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl b/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl new file mode 100644 index 00000000000..2f31ad2e5a8 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl @@ -0,0 +1,13 @@ +{{/* +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 -}} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/broker-configmap.yaml b/tubemq-docker/tubemq-k8s/templates/broker-configmap.yaml new file mode 100644 index 00000000000..f873d6faf0c --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/broker-configmap.yaml @@ -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 \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/broker-ini-configmap.yaml b/tubemq-docker/tubemq-k8s/templates/broker-ini-configmap.yaml new file mode 100644 index 00000000000..3ce21978ec6 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/broker-ini-configmap.yaml @@ -0,0 +1,49 @@ +# +# 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 }}-ini" + namespace: {{ .Release.Namespace }} + labels: + component: {{ .Values.broker.component }} +data: + broker.ini.raw: | + [broker] + brokerId=REPLACE_BY_POD_ID + hostName=REPLACE_BY_POD_HOSTNAME + port=8123 + webPort=8081 + masterAddressList=REPLACE_BY_MASTER_LIST + primaryPath=/data/stage/metadata_REPLACE_BY_POD_ID + maxSegmentSize=1073741824 + maxIndexSegmentSize=22020096 + transferSize= 524288 + loadMessageStoresInParallel=true + consumerRegTimeoutMs=35000 + + [zookeeper] + zkNodeRoot=/tubemq + zkServerAddr={{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}:2181 + zkSessionTimeoutMs=30000 + zkConnectionTimeoutMs=30000 + zkSyncTimeMs=5000 + zkCommitPeriodMs=5000 + zkCommitFailRetries=10 diff --git a/tubemq-docker/tubemq-k8s/templates/broker-pdb.yaml b/tubemq-docker/tubemq-k8s/templates/broker-pdb.yaml new file mode 100644 index 00000000000..184c440959e --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/broker-pdb.yaml @@ -0,0 +1,35 @@ +# +# 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. +# + +{{- if .Values.broker.pdb.usePolicy }} +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.broker.component }} +spec: + selector: + matchLabels: + {{- include "tubemq.matchLabels" . | nindent 6 }} + component: {{ .Values.broker.component }} + maxUnavailable: {{ .Values.broker.pdb.maxUnavailable }} +{{- end }} diff --git a/tubemq-docker/tubemq-k8s/templates/broker-service.yaml b/tubemq-docker/tubemq-k8s/templates/broker-service.yaml new file mode 100644 index 00000000000..89002bc68fc --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/broker-service.yaml @@ -0,0 +1,39 @@ +# +# 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: Service +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.broker.component }} + annotations: +{{ toYaml .Values.broker.service.annotations | indent 4 }} +spec: + type: {{ .Values.broker.service.type }} + ports: + - name: web-port + port: {{ .Values.broker.ports.webPort }} + - name: rpc-port + port: {{ .Values.broker.ports.rpcPort }} + selector: + {{- include "tubemq.matchLabels" . | nindent 4 }} + component: {{ .Values.broker.component }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/broker-statefulset.yaml b/tubemq-docker/tubemq-k8s/templates/broker-statefulset.yaml new file mode 100644 index 00000000000..8032b22e921 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/broker-statefulset.yaml @@ -0,0 +1,159 @@ +# +# 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: apps/v1 +kind: StatefulSet +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.broker.component }} +spec: + serviceName: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}" + replicas: {{ .Values.broker.replicaCount }} + selector: + matchLabels: + {{- include "tubemq.matchLabels" . | nindent 6 }} + component: {{ .Values.broker.component }} + updateStrategy: +{{ toYaml .Values.broker.updateStrategy | indent 4 }} + podManagementPolicy: {{ .Values.broker.podManagementPolicy }} + template: + metadata: + labels: + {{- include "tubemq.template.labels" . | nindent 8 }} + component: {{ .Values.broker.component }} + annotations: +{{ toYaml .Values.broker.annotations | indent 8 }} + spec: + {{- if .Values.broker.nodeSelector }} + nodeSelector: +{{ toYaml .Values.broker.nodeSelector | indent 8 }} + {{- end }} + {{- if .Values.broker.tolerations }} + tolerations: +{{ toYaml .Values.broker.tolerations | indent 8 }} + {{- end }} + initContainers: + - name: wait-master-ready + image: "{{ .Values.images.tubemq_all.repository }}:{{ .Values.images.tubemq_all.tag }}" + imagePullPolicy: {{ .Values.images.tubemq_all.pullPolicy }} + command: ["/bin/bash", "-c"] + args: + - >- + for ((i=0;i<{{ .Values.master.replicaCount }};i++)); do + until curl {{ template "tubemq.fullname" $ }}-{{ .Values.master.component }}-$i.{{ template "tubemq.fullname" $ }}-{{ .Values.master.component }}.{{ .Release.Namespace }}.svc.cluster.local:${1:-8080}/index.htm; do + sleep 3; done; done; + affinity: + {{- if .Values.affinity.anti_affinity}} + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: "app" + operator: In + values: + - "{{ template "tubemq.name" . }}-{{ .Values.broker.component }}" + - key: "release" + operator: In + values: + - {{ .Release.Name }} + - key: "component" + operator: In + values: + - {{ .Values.broker.component }} + topologyKey: "kubernetes.io/hostname" + {{- end }} + terminationGracePeriodSeconds: {{ .Values.broker.gracePeriod }} + containers: + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}" + image: "{{ .Values.images.tubemq_all.repository }}:{{ .Values.images.tubemq_all.tag }}" + imagePullPolicy: {{ .Values.images.tubemq_all.pullPolicy }} + {{- if .Values.broker.resources }} + resources: +{{ toYaml .Values.broker.resources | indent 10 }} + {{- end }} + command: ["sh", "-c"] + args: + - > + /config-scripts/run; + ports: + - name: web-port + containerPort: {{ .Values.broker.ports.webPort }} + - name: rpc-port + containerPort: {{ .Values.broker.ports.rpcPort }} + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + {{- if .Values.broker.probe.readiness.enabled }} + readinessProbe: + exec: + command: + - /config-scripts/ready + initialDelaySeconds: {{ .Values.broker.probe.readiness.initialDelaySeconds }} + periodSeconds: {{ .Values.broker.probe.readiness.periodSeconds }} + failureThreshold: {{ .Values.broker.probe.readiness.failureThreshold }} + {{- end }} + {{- if .Values.broker.probe.liveness.enabled }} + livenessProbe: + exec: + command: + - /config-scripts/ok + initialDelaySeconds: {{ .Values.broker.probe.liveness.initialDelaySeconds }} + periodSeconds: {{ .Values.broker.probe.liveness.periodSeconds }} + failureThreshold: {{ .Values.broker.probe.liveness.failureThreshold }} + {{- end }} + volumeMounts: + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}-{{ .Values.broker.volumes.data.name }}" + mountPath: /data + - name: config + mountPath: /config-scripts + - name: {{ .Values.broker.component }}-ini + mountPath: /opt/tubemq-server/conf/{{ .Values.broker.component }}.ini.raw + subPath: {{ .Values.broker.component }}.ini.raw + readOnly: false + volumes: + - name: config + configMap: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}" + defaultMode: 0755 + - name: {{ .Values.broker.component }}-ini + configMap: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}-ini" + defaultMode: 0644 + {{- if not .Values.volumes.persistence }} + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}-{{ .Values.broker.volumes.data.name }}" + emptyDir: {} + {{- end }} +{{- if .Values.volumes.persistence }} + volumeClaimTemplates: + - metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.broker.component }}-{{ .Values.broker.volumes.data.name }}" + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .Values.broker.volumes.data.size }} + {{- if .Values.volumes.storageClassName }} + storageClassName: "{{ .Values.volumes.storageClassName }}" + {{- end }} +{{- end }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/master-configmap.yaml b/tubemq-docker/tubemq-k8s/templates/master-configmap.yaml new file mode 100644 index 00000000000..21acca7828a --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/master-configmap.yaml @@ -0,0 +1,55 @@ +# +# 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.master.component }}" + namespace: {{ .Release.Namespace }} + labels: + component: {{ .Values.master.component }} +data: + ok: | + #!/bin/sh + /opt/tubemq-server/bin/tubemq master status + + ready: | + #!/bin/sh + curl 127.0.0.1:8080/index.htm + + 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 + # generate config file + cp /opt/tubemq-server/conf/master.ini.raw /opt/tubemq-server/conf/master.ini + sed -i "s/REPLACE_BY_POD_ID/$MY_POD_ID/g" /opt/tubemq-server/conf/master.ini + sed -i "s/REPLACE_BY_POD_HOSTNAME/$HOST.{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}.{{ .Release.Name }}.svc.cluster.local/g" /opt/tubemq-server/conf/master.ini + # start master + /opt/tubemq-server/bin/tubemq master start + tail -F /opt/tubemq-server/logs/master.log \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/master-ini-configmap.yaml b/tubemq-docker/tubemq-k8s/templates/master-ini-configmap.yaml new file mode 100644 index 00000000000..84fae632bcb --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/master-ini-configmap.yaml @@ -0,0 +1,55 @@ +# +# 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.master.component }}-ini" + namespace: {{ .Release.Namespace }} + labels: + component: {{ .Values.master.component }} +data: + master.ini.raw: | + [master] + hostName=REPLACE_BY_POD_HOSTNAME + port=8000 + webPort=8080 + consumerBalancePeriodMs=30000 + firstBalanceDelayAfterStartMs=60000 + consumerHeartbeatTimeoutMs=30000 + producerHeartbeatTimeoutMs=45000 + brokerHeartbeatTimeoutMs=25000 + confModAuthToken=abc + webResourcePath=resources + metaDataPath=/data/meta_data + useWebProxy=true + + [zookeeper] + zkNodeRoot=/tubemq + zkServerAddr={{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}:2181 + zkSessionTimeoutMs=30000 + zkConnectionTimeoutMs=30000 + zkSyncTimeMs=5000 + zkCommitPeriodMs=5000 + + [replication] + repGroupName={{ template "tubemq.fullname" . }}-{{ .Values.master.component }} + repNodeName={{ template "tubemq.fullname" . }}-{{ .Values.master.component }}-REPLACE_BY_POD_ID + repNodePort=9001 + repHelperHost={{ template "tubemq.fullname" . }}-{{ .Values.master.component }}-0.{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}.{{ .Release.Name }}.svc.cluster.local:9001 diff --git a/tubemq-docker/tubemq-k8s/templates/master-pdb.yaml b/tubemq-docker/tubemq-k8s/templates/master-pdb.yaml new file mode 100644 index 00000000000..eae1b5b07ea --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/master-pdb.yaml @@ -0,0 +1,35 @@ +# +# 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. +# + +{{- if .Values.master.pdb.usePolicy }} +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.master.component }} +spec: + selector: + matchLabels: + {{- include "tubemq.matchLabels" . | nindent 6 }} + component: {{ .Values.master.component }} + maxUnavailable: {{ .Values.master.pdb.maxUnavailable }} +{{- end }} diff --git a/tubemq-docker/tubemq-k8s/templates/master-service.yaml b/tubemq-docker/tubemq-k8s/templates/master-service.yaml new file mode 100644 index 00000000000..e31d305b7ae --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/master-service.yaml @@ -0,0 +1,42 @@ +# +# 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: Service +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.master.component }} + annotations: +{{ toYaml .Values.master.service.annotations | indent 4 }} +spec: + type: {{ .Values.master.service.type }} + ports: + - name: web-port + port: {{ .Values.master.ports.webPort }} + nodePort: {{ .Values.master.ports.webNodePort }} + - name: help-port + port: {{ .Values.master.ports.helpPort }} + - name: rpc-port + port: {{ .Values.master.ports.rpcPort }} + selector: + {{- include "tubemq.matchLabels" . | nindent 4 }} + component: {{ .Values.master.component }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/master-statefulset.yaml b/tubemq-docker/tubemq-k8s/templates/master-statefulset.yaml new file mode 100644 index 00000000000..db6bb293d68 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/master-statefulset.yaml @@ -0,0 +1,161 @@ +# +# 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: apps/v1 +kind: StatefulSet +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.master.component }} +spec: + serviceName: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}" + replicas: {{ .Values.master.replicaCount }} + selector: + matchLabels: + {{- include "tubemq.matchLabels" . | nindent 6 }} + component: {{ .Values.master.component }} + updateStrategy: +{{ toYaml .Values.master.updateStrategy | indent 4 }} + podManagementPolicy: {{ .Values.master.podManagementPolicy }} + template: + metadata: + labels: + {{- include "tubemq.template.labels" . | nindent 8 }} + component: {{ .Values.master.component }} + annotations: +{{ toYaml .Values.master.annotations | indent 8 }} + spec: + {{- if .Values.master.nodeSelector }} + nodeSelector: +{{ toYaml .Values.master.nodeSelector | indent 8 }} + {{- end }} + {{- if .Values.master.tolerations }} + tolerations: +{{ toYaml .Values.master.tolerations | indent 8 }} + {{- end }} + initContainers: + - name: wait-zk-ready + image: "{{ .Values.images.tubemq_all.repository }}:{{ .Values.images.tubemq_all.tag }}" + imagePullPolicy: {{ .Values.images.tubemq_all.pullPolicy }} + command: ["/bin/bash", "-c"] + args: + - >- + for ((i=0;i<{{ .Values.zookeeper.replicaCount }};i++)); do + until echo ruok | nc {{ template "tubemq.fullname" $ }}-{{ .Values.zookeeper.component }}-$i.{{ template "tubemq.fullname" $ }}-{{ .Values.zookeeper.component }}.{{ .Release.Namespace }}.svc.cluster.local ${1:-2181}; do + sleep 3; done; done; + affinity: + {{- if .Values.affinity.anti_affinity}} + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: "app" + operator: In + values: + - "{{ template "tubemq.name" . }}-{{ .Values.master.component }}" + - key: "release" + operator: In + values: + - {{ .Release.Name }} + - key: "component" + operator: In + values: + - {{ .Values.master.component }} + topologyKey: "kubernetes.io/hostname" + {{- end }} + terminationGracePeriodSeconds: {{ .Values.master.gracePeriod }} + containers: + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}" + image: "{{ .Values.images.tubemq_all.repository }}:{{ .Values.images.tubemq_all.tag }}" + imagePullPolicy: {{ .Values.images.tubemq_all.pullPolicy }} + {{- if .Values.master.resources }} + resources: +{{ toYaml .Values.master.resources | indent 10 }} + {{- end }} + command: ["sh", "-c"] + args: + - > + /config-scripts/run; + ports: + - name: web-port + containerPort: {{ .Values.master.ports.webPort }} + - name: help-port + containerPort: {{ .Values.master.ports.helpPort }} + - name: rpc-port + containerPort: {{ .Values.master.ports.rpcPort }} + env: + - name: MY_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + {{- if .Values.master.probe.readiness.enabled }} + readinessProbe: + exec: + command: + - /config-scripts/ready + initialDelaySeconds: {{ .Values.master.probe.readiness.initialDelaySeconds }} + periodSeconds: {{ .Values.master.probe.readiness.periodSeconds }} + failureThreshold: {{ .Values.master.probe.readiness.failureThreshold }} + {{- end }} + {{- if .Values.master.probe.liveness.enabled }} + livenessProbe: + exec: + command: + - /config-scripts/ok + initialDelaySeconds: {{ .Values.master.probe.liveness.initialDelaySeconds }} + periodSeconds: {{ .Values.master.probe.liveness.periodSeconds }} + failureThreshold: {{ .Values.master.probe.liveness.failureThreshold }} + {{- end }} + volumeMounts: + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}-{{ .Values.master.volumes.data.name }}" + mountPath: /data + - name: config + mountPath: /config-scripts + - name: {{ .Values.master.component }}-ini + mountPath: /opt/tubemq-server/conf/{{ .Values.master.component }}.ini.raw + subPath: {{ .Values.master.component }}.ini.raw + readOnly: false + volumes: + - name: config + configMap: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}" + defaultMode: 0755 + - name: {{ .Values.master.component }}-ini + configMap: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}-ini" + defaultMode: 0644 + {{- if not .Values.volumes.persistence }} + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}-{{ .Values.master.volumes.data.name }}" + emptyDir: {} + {{- end }} +{{- if .Values.volumes.persistence }} + volumeClaimTemplates: + - metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.master.component }}-{{ .Values.master.volumes.data.name }}" + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .Values.master.volumes.data.size }} + {{- if .Values.volumes.storageClassName }} + storageClassName: "{{ .Values.volumes.storageClassName }}" + {{- end }} +{{- end }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/zookeeper-configmap.yaml b/tubemq-docker/tubemq-k8s/templates/zookeeper-configmap.yaml new file mode 100644 index 00000000000..a8f1a75962f --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/zookeeper-configmap.yaml @@ -0,0 +1,55 @@ +# +# 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.zookeeper.component }}" + namespace: {{ .Release.Namespace }} + labels: + component: {{ .Values.zookeeper.component }} +data: + ok: | + #!/bin/sh + zkServer.sh status + + ready: | + #!/bin/sh + echo ruok | nc 127.0.0.1 ${1:-2181} + + run: | + #!/bin/bash + set -a + 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 + if [ ! -d "/data/zoo_data/" ]; then + mkdir /data/zoo_data/ /data/zoo_log/ + fi + export ZOO_MY_ID=$MY_POD_ID + export ZOO_DATA_DIR="/data/zoo_data/" + export ZOO_DATA_LOG_DIR="/data/zoo_log/" + export SERVER_JVMFLAGS="-Xmx1g -Xms1g" + /docker-entrypoint.sh zkServer.sh start-foreground \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/zookeeper-pdb.yaml b/tubemq-docker/tubemq-k8s/templates/zookeeper-pdb.yaml new file mode 100644 index 00000000000..0e47bcf46a3 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/zookeeper-pdb.yaml @@ -0,0 +1,35 @@ +# +# 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. +# + +{{- if .Values.zookeeper.pdb.usePolicy }} +apiVersion: policy/v1beta1 +kind: PodDisruptionBudget +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.zookeeper.component }} +spec: + selector: + matchLabels: + {{- include "tubemq.matchLabels" . | nindent 6 }} + component: {{ .Values.zookeeper.component }} + maxUnavailable: {{ .Values.zookeeper.pdb.maxUnavailable }} +{{- end }} diff --git a/tubemq-docker/tubemq-k8s/templates/zookeeper-service.yaml b/tubemq-docker/tubemq-k8s/templates/zookeeper-service.yaml new file mode 100644 index 00000000000..04322563573 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/zookeeper-service.yaml @@ -0,0 +1,41 @@ +# +# 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: Service +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.zookeeper.component }} + annotations: +{{ toYaml .Values.zookeeper.service.annotations | indent 4 }} +spec: + ports: + - name: follower + port: {{ .Values.zookeeper.ports.follower }} + - name: leader-election + port: {{ .Values.zookeeper.ports.leaderElection }} + - name: client + port: {{ .Values.zookeeper.ports.client }} + clusterIP: None + selector: + {{- include "tubemq.matchLabels" . | nindent 4 }} + component: {{ .Values.zookeeper.component }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/templates/zookeeper-statefulset.yaml b/tubemq-docker/tubemq-k8s/templates/zookeeper-statefulset.yaml new file mode 100644 index 00000000000..b75ca405f03 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/templates/zookeeper-statefulset.yaml @@ -0,0 +1,143 @@ +# +# 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: apps/v1 +kind: StatefulSet +metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "tubemq.standardLabels" . | nindent 4 }} + component: {{ .Values.zookeeper.component }} +spec: + serviceName: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}" + replicas: {{ .Values.zookeeper.replicaCount }} + selector: + matchLabels: + {{- include "tubemq.matchLabels" . | nindent 6 }} + component: {{ .Values.zookeeper.component }} + updateStrategy: +{{ toYaml .Values.zookeeper.updateStrategy | indent 4 }} + podManagementPolicy: {{ .Values.zookeeper.podManagementPolicy }} + template: + metadata: + labels: + {{- include "tubemq.template.labels" . | nindent 8 }} + component: {{ .Values.zookeeper.component }} + annotations: +{{ toYaml .Values.zookeeper.annotations | indent 8 }} + spec: + {{- if .Values.zookeeper.nodeSelector }} + nodeSelector: +{{ toYaml .Values.zookeeper.nodeSelector | indent 8 }} + {{- end }} + {{- if .Values.zookeeper.tolerations }} + tolerations: +{{ toYaml .Values.zookeeper.tolerations | indent 8 }} + {{- end }} + affinity: + {{- if .Values.affinity.anti_affinity}} + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: "app" + operator: In + values: + - "{{ template "tubemq.name" . }}-{{ .Values.zookeeper.component }}" + - key: "release" + operator: In + values: + - {{ .Release.Name }} + - key: "component" + operator: In + values: + - {{ .Values.zookeeper.component }} + topologyKey: "kubernetes.io/hostname" + {{- end }} + terminationGracePeriodSeconds: {{ .Values.zookeeper.gracePeriod }} + containers: + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}" + image: "{{ .Values.images.tubemq_all.repository }}:{{ .Values.images.tubemq_all.tag }}" + imagePullPolicy: {{ .Values.images.tubemq_all.pullPolicy }} + {{- if .Values.zookeeper.resources }} + resources: +{{ toYaml .Values.zookeeper.resources | indent 10 }} + {{- end }} + command: ["sh", "-c"] + args: + - > + /config-scripts/run; + ports: + - name: client + containerPort: {{ .Values.zookeeper.ports.client }} + - name: follower + containerPort: {{ .Values.zookeeper.ports.follower }} + - name: leader-election + containerPort: {{ .Values.zookeeper.ports.leaderElection }} + env: + - name: ZOOKEEPER_SERVERS + value: + {{- $global := . }} + {{ range $i, $e := until (.Values.zookeeper.replicaCount | int) }}{{ if ne $i 0 }},{{ end }}{{ template "tubemq.fullname" $global }}-{{ $global.Values.zookeeper.component }}-{{ printf "%d" $i }}{{ end }} + {{- if .Values.zookeeper.probe.readiness.enabled }} + readinessProbe: + exec: + command: + - /config-scripts/ready + initialDelaySeconds: {{ .Values.zookeeper.probe.readiness.initialDelaySeconds }} + periodSeconds: {{ .Values.zookeeper.probe.readiness.periodSeconds }} + failureThreshold: {{ .Values.zookeeper.probe.readiness.failureThreshold }} + {{- end }} + {{- if .Values.zookeeper.probe.liveness.enabled }} + livenessProbe: + exec: + command: + - /config-scripts/ok + initialDelaySeconds: {{ .Values.zookeeper.probe.liveness.initialDelaySeconds }} + periodSeconds: {{ .Values.zookeeper.probe.liveness.periodSeconds }} + failureThreshold: {{ .Values.zookeeper.probe.liveness.failureThreshold }} + {{- end }} + volumeMounts: + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}-{{ .Values.zookeeper.volumes.data.name }}" + mountPath: /data + - name: config + mountPath: /config-scripts + volumes: + - name: config + configMap: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}" + defaultMode: 0755 + {{- if not .Values.volumes.persistence }} + - name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}-{{ .Values.zookeeper.volumes.data.name }}" + emptyDir: {} + {{- end }} +{{- if .Values.volumes.persistence }} + volumeClaimTemplates: + - metadata: + name: "{{ template "tubemq.fullname" . }}-{{ .Values.zookeeper.component }}-{{ .Values.zookeeper.volumes.data.name }}" + spec: + accessModes: [ "ReadWriteOnce" ] + resources: + requests: + storage: {{ .Values.zookeeper.volumes.data.size }} + {{- if .Values.volumes.storageClassName }} + storageClassName: "{{ .Values.volumes.storageClassName }}" + {{- end }} +{{- end }} \ No newline at end of file diff --git a/tubemq-docker/tubemq-k8s/values.yaml b/tubemq-docker/tubemq-k8s/values.yaml new file mode 100644 index 00000000000..28c18604de6 --- /dev/null +++ b/tubemq-docker/tubemq-k8s/values.yaml @@ -0,0 +1,158 @@ +# +# 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. +# + +# Default values for TubeMQ. +# Declare variables to be passed into your templates. +images: + tubemq_all: + repository: apachetubemq/tubemq-all + tag: latest + pullPolicy: IfNotPresent + +volumes: + persistence: false + storageClassName: "local-storage" + +affinity: + anti_affinity: false + +zookeeper: + component: zookeeper + replicaCount: 3 + updateStrategy: + type: RollingUpdate + podManagementPolicy: OrderedReady + ports: + client: 2181 + follower: 2888 + leaderElection: 3888 + #nodeSelector: + # apache-tubemq-nodepool: zookeeper-pool + probe: + liveness: + enabled: true + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 30 + readiness: + enabled: true + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 30 + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "8000" + tolerations: [] + gracePeriod: 30 + resources: + requests: + memory: 2Gi + cpu: 1 + volumes: + data: + name: data + size: 20Gi + service: + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" + pdb: + usePolicy: true + maxUnavailable: 1 + +master: + component: master + replicaCount: 1 + updateStrategy: + type: RollingUpdate + podManagementPolicy: OrderedReady + ports: + rpcPort: 8000 + webPort: 8080 + webNodePort: 8080 + helpPort: 9001 + #nodeSelector: + # apache-tubemq-nodepool: master-pool + probe: + liveness: + enabled: true + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 30 + readiness: + enabled: true + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 30 + tolerations: [] + gracePeriod: 30 + resources: + requests: + memory: 2Gi + cpu: 1 + volumes: + data: + name: data + size: 20Gi + service: + type: LoadBalancer + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" + pdb: + usePolicy: true + maxUnavailable: 1 + +broker: + component: broker + replicaCount: 3 + updateStrategy: + type: RollingUpdate + podManagementPolicy: OrderedReady + ports: + rpcPort: 8123 + webPort: 8081 + #nodeSelector: + # apache-tubemq-nodepool: broker-pool + probe: + liveness: + enabled: true + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 30 + readiness: + enabled: true + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 30 + tolerations: [] + gracePeriod: 30 + resources: + requests: + memory: 2Gi + cpu: 1 + volumes: + data: + name: data + size: 20Gi + service: + type: LoadBalancer + annotations: + service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" + pdb: + usePolicy: true + maxUnavailable: 1 \ No newline at end of file From e4c8212ecfe6df0826de8d0eaa83f8df217c4b9a Mon Sep 17 00:00:00 2001 From: dockerzhang Date: Fri, 19 Jun 2020 14:55:32 +0800 Subject: [PATCH 2/2] [TUBEMQ-241] add approved license --- .../tubemq-k8s/templates/_broker.tpl | 21 +++++++++++++++++++ .../tubemq-k8s/templates/_helpers.yaml | 21 +++++++++++++++++++ .../tubemq-k8s/templates/_master.tpl | 21 +++++++++++++++++++ .../tubemq-k8s/templates/_zookeeper.tpl | 21 +++++++++++++++++++ 4 files changed, 84 insertions(+) diff --git a/tubemq-docker/tubemq-k8s/templates/_broker.tpl b/tubemq-docker/tubemq-k8s/templates/_broker.tpl index d77fdc96f5c..17afc0ffc58 100644 --- a/tubemq-docker/tubemq-k8s/templates/_broker.tpl +++ b/tubemq-docker/tubemq-k8s/templates/_broker.tpl @@ -1,3 +1,24 @@ +{{/* +# +# 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 */}} diff --git a/tubemq-docker/tubemq-k8s/templates/_helpers.yaml b/tubemq-docker/tubemq-k8s/templates/_helpers.yaml index dc5d7e673ea..c525cd23d1a 100644 --- a/tubemq-docker/tubemq-k8s/templates/_helpers.yaml +++ b/tubemq-docker/tubemq-k8s/templates/_helpers.yaml @@ -1,3 +1,24 @@ +{{/* +# +# 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. diff --git a/tubemq-docker/tubemq-k8s/templates/_master.tpl b/tubemq-docker/tubemq-k8s/templates/_master.tpl index fee8d7f411a..0e84b69438c 100644 --- a/tubemq-docker/tubemq-k8s/templates/_master.tpl +++ b/tubemq-docker/tubemq-k8s/templates/_master.tpl @@ -1,3 +1,24 @@ +{{/* +# +# 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 */}} diff --git a/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl b/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl index 2f31ad2e5a8..59d0bdabbde 100644 --- a/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl +++ b/tubemq-docker/tubemq-k8s/templates/_zookeeper.tpl @@ -1,3 +1,24 @@ +{{/* +# +# 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 */}}