diff --git a/charts/eclipse-mosquitto/Chart.yaml b/charts/eclipse-mosquitto/Chart.yaml new file mode 100644 index 0000000..2f2aa80 --- /dev/null +++ b/charts/eclipse-mosquitto/Chart.yaml @@ -0,0 +1,15 @@ +apiVersion: v2 +appVersion: 2.0.18 +description: Eclipse Mosquitto MQTT +name: mosquitto +version: 0.0.1 +type: application +keywords: +- mqtt +- mosquitto +home: https://github.com/JacekZubielik/jz-helm-charts/tree/master/charts/eclipse-mosquitto +icon: https://raw.githubusercontent.com/eclipse/mosquitto/master/logo/mosquitto-logo-min.svg +sources: +- https://github.com/eclipse/mosquitto +maintainers: +- name: jacekzubielik diff --git a/charts/eclipse-mosquitto/templates/_helpers.tpl b/charts/eclipse-mosquitto/templates/_helpers.tpl new file mode 100644 index 0000000..f548475 --- /dev/null +++ b/charts/eclipse-mosquitto/templates/_helpers.tpl @@ -0,0 +1,45 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "eclipse-mosquitto.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 "eclipse-mosquitto.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "eclipse-mosquitto.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "eclipse-mosquitto.labels" -}} +app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }} +helm.sh/chart: {{ include "eclipse-mosquitto.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} diff --git a/charts/eclipse-mosquitto/templates/configmap-certs.yaml b/charts/eclipse-mosquitto/templates/configmap-certs.yaml new file mode 100644 index 0000000..230da9f --- /dev/null +++ b/charts/eclipse-mosquitto/templates/configmap-certs.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "eclipse-mosquitto.fullname" . }}-certs + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} +data: + ca.crt: |- + {{- .Values.certs.ca.crt | nindent 4 }} + server.crt: |- + {{- .Values.certs.server.crt | nindent 4 }} + server.key: |- + {{- .Values.certs.server.key | nindent 4 }} diff --git a/charts/eclipse-mosquitto/templates/configmap.yaml b/charts/eclipse-mosquitto/templates/configmap.yaml new file mode 100644 index 0000000..db73932 --- /dev/null +++ b/charts/eclipse-mosquitto/templates/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "eclipse-mosquitto.fullname" . }}-config + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} +data: + mosquitto.conf: |- + {{- .Values.config | nindent 4 }} diff --git a/charts/eclipse-mosquitto/templates/deployment.yaml b/charts/eclipse-mosquitto/templates/deployment.yaml new file mode 100644 index 0000000..c87dc84 --- /dev/null +++ b/charts/eclipse-mosquitto/templates/deployment.yaml @@ -0,0 +1,111 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "eclipse-mosquitto.fullname" . }} + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.securityContext.fsGroup }} + runAsUser: {{ .Values.securityContext.runAsUser }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: {{ .Values.container.ports.mqtt.name }} + containerPort: {{ .Values.container.ports.mqtt.port }} + protocol: TCP + - name: {{ .Values.container.ports.mqtts.name }} + containerPort: {{ .Values.container.ports.mqtts.port }} + protocol: TCP + livenessProbe: + tcpSocket: + port: {{ .Values.container.ports.mqtt.port }} + initialDelaySeconds: 5 + periodSeconds: 15 + readinessProbe: + tcpSocket: + port: {{ .Values.container.ports.mqtt.port }} + initialDelaySeconds: 5 + periodSeconds: 10 + volumeMounts: + - name: mosquitto-conf + mountPath: /mosquitto/config/mosquitto.conf + subPath: mosquitto.conf + readOnly: true + - name: mosquitto-ca-cert + mountPath: /mosquitto/config/certs/ca.crt + subPath: ca.crt + readOnly: true + - name: mosquitto-server-cert + mountPath: /mosquitto/config/certs/server.crt + subPath: server.crt + readOnly: true + - name: mosquitto-server-key + mountPath: /mosquitto/config/certs/server.key + subPath: server.key + readOnly: true + - name: mosquitto-data + mountPath: /mosquitto/data + subPath: mosquitto/data + resources: + {{- toYaml .Values.resources | nindent 12 }} + volumes: + - name: mosquitto-conf + configMap: + name: {{ include "eclipse-mosquitto.fullname" . }}-config + - name: mosquitto-ca-cert + configMap: + name: {{ include "eclipse-mosquitto.fullname" . }}-certs + items: + - key: ca.crt + path: ca.crt + - name: mosquitto-server-cert + configMap: + name: {{ include "eclipse-mosquitto.fullname" . }}-certs + items: + - key: server.crt + path: server.crt + - name: mosquitto-server-key + configMap: + name: {{ include "eclipse-mosquitto.fullname" . }}-certs + items: + - key: server.key + path: server.key + - name: mosquitto-data + {{- if .Values.persistence.enabled }} + persistentVolumeClaim: + claimName: {{ include "eclipse-mosquitto.fullname" . }}-pvc + {{- else }} + emptyDir: {} + {{- end -}} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/eclipse-mosquitto/templates/ingress.yaml b/charts/eclipse-mosquitto/templates/ingress.yaml new file mode 100644 index 0000000..9e8a62a --- /dev/null +++ b/charts/eclipse-mosquitto/templates/ingress.yaml @@ -0,0 +1,37 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "eclipse-mosquitto.fullname" . -}} +{{- $portName := .Values.service.ports.mqtts.name -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ $fullName }}-mqtt + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $portName }} + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/eclipse-mosquitto/templates/pvc.yaml b/charts/eclipse-mosquitto/templates/pvc.yaml new file mode 100644 index 0000000..b65eae1 --- /dev/null +++ b/charts/eclipse-mosquitto/templates/pvc.yaml @@ -0,0 +1,26 @@ +{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "eclipse-mosquitto.fullname" . }}-pvc + namespace: {{ .Release.Namespace }} +{{- with .Values.persistence.annotations }} + annotations: +{{ toYaml . | indent 4 }} +{{- end }} + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} +spec: + accessModes: + - {{ .Values.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} +{{- if .Values.persistence.storageClass }} +{{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/eclipse-mosquitto/templates/service.yaml b/charts/eclipse-mosquitto/templates/service.yaml new file mode 100644 index 0000000..87968ca --- /dev/null +++ b/charts/eclipse-mosquitto/templates/service.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "eclipse-mosquitto.fullname" . }} + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.ports.mqtt.port }} + targetPort: {{ .Values.container.ports.mqtt.name }} + protocol: TCP + name: {{ .Values.service.ports.mqtt.name }} + - port: {{ .Values.service.ports.mqtts.port }} + targetPort: {{ .Values.container.ports.mqtts.name }} + protocol: TCP + name: {{ .Values.service.ports.mqtts.name }} + selector: + app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/eclipse-mosquitto/templates/tests/test-connection.yaml b/charts/eclipse-mosquitto/templates/tests/test-connection.yaml new file mode 100644 index 0000000..38769ff --- /dev/null +++ b/charts/eclipse-mosquitto/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "eclipse-mosquitto.fullname" . }}-test-connection" + labels: +{{ include "eclipse-mosquitto.labels" . | indent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "eclipse-mosquitto.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/charts/eclipse-mosquitto/values.yaml b/charts/eclipse-mosquitto/values.yaml new file mode 100644 index 0000000..fd93c36 --- /dev/null +++ b/charts/eclipse-mosquitto/values.yaml @@ -0,0 +1,112 @@ +# Default values for eclipse-mosquitto. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: eclipse-mosquitto + tag: 1.6.7 + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +container: + ports: + mqtt: + name: mqtt + port: 1884 + mqtts: + name: mqtts + port: 1883 + +service: + type: ClusterIP + ports: + mqtt: + name: mqtt + port: 1884 + mqtts: + name: mqtts + port: 1883 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +config: |- + persistence true + persistence_location /mosquitto/data/ + log_dest stdout + listener 1884 + listener 1883 + protocol mqtt + cafile /mosquitto/config/certs/ca.crt + certfile /mosquitto/config/certs/server.crt + keyfile /mosquitto/config/certs/server.key + require_certificate true + use_subject_as_username true + +certs: + ca: + crt: |- + -----BEGIN CERTIFICATE----- + CA_CERT + -----END CERTIFICATE----- + server: + crt: |- + -----BEGIN CERTIFICATE----- + SERVER_CERT + -----END CERTIFICATE----- + key: |- + -----BEGIN PRIVATE KEY----- + SERVER_KEY + -----END PRIVATE KEY----- + + +## Persist data to a persistent volume +persistence: + enabled: true + ## database data Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + ## + # storageClass: "-" + accessMode: ReadWriteOnce + size: 8Gi + annotations: {} + storageClass: standard + +## Security context +securityContext: + enabled: false + runAsUser: 999 + fsGroup: 999