diff --git a/README.md b/README.md index d6b29bb..da85a0e 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,8 @@ Due to various challenges this image sports the following features: - [Overview](#overview) - [Defaults](#defaults) - [Development](#development) + - [Kubernetes](#kubernetes) - [Troubleshooting](#troubleshooting) - - [Kubernetes](#kubernetes) ## Overview @@ -77,31 +77,18 @@ HEALTHCHECK "false" This will escalate any issues you have with invalid mjml code to the docker log (`stdout` or `docker-compose logs`). -## Troubleshooting +## Kubernetes -Make sure you pass along a plain Content-Type header and pass the mjml as raw body. +The helm chart will deploy an mjml server accessible from any pods in the cluster. -Catch errors by looking at the HTTP response code. +### Deploy to cluster +`helm install mjml-server ./helm` -### Kubernetes +To change the port +`helm install --set image.port=8080 mjml-server ./helm` -As the default Dockerfile specific `HEALTHCHECK` directive is not supported by kubernetes, you might need to specify your own probes: +## Troubleshooting -``` -spec: - containers: - - name: ... - livenessProbe: - exec: - command: - - curl - -X POST - 'http://localhost:80/' - initialDelaySeconds: 30 - periodSeconds: 30 - readinessProbe: - exec: - command: - - curl - -X POST - 'http://localhost:80/' - initialDelaySeconds: 25 -``` +Make sure you pass along a plain Content-Type header and pass the mjml as raw body. -Be aware that this does only check the connectivity and that the port might vary. If you want a functional check as well, you could shift to an approach like the ones used for docker with the result of the [healthcheck.sh](healthcheck.sh). But I'm not a kubernetes user, so feel free to do a pull request if you have a slim approach. +Catch errors by looking at the HTTP response code. diff --git a/helm/.helmignore b/helm/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/helm/.helmignore @@ -0,0 +1,22 @@ +# 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 +.vscode/ diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..277591c --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "2.2.2" +description: Helm chart for mjml-server +name: mjml-server +version: 0.1.0 diff --git a/helm/templates/NOTES.txt b/helm/templates/NOTES.txt new file mode 100644 index 0000000..8738a5e --- /dev/null +++ b/helm/templates/NOTES.txt @@ -0,0 +1 @@ +The server will run on port {{ .Values.image.port }} \ No newline at end of file diff --git a/helm/templates/_helpers.tpl b/helm/templates/_helpers.tpl new file mode 100644 index 0000000..86a9288 --- /dev/null +++ b/helm/templates/_helpers.tpl @@ -0,0 +1,56 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "helm.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 "helm.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 "helm.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "helm.labels" -}} +app.kubernetes.io/name: {{ include "helm.name" . }} +helm.sh/chart: {{ include "helm.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 -}} + +{{/* +Create the name of the service account to use +*/}} +{{- define "helm.serviceAccountName" -}} +{{- if .Values.serviceAccount.create -}} + {{ default (include "helm.fullname" .) .Values.serviceAccount.name }} +{{- else -}} + {{ default "default" .Values.serviceAccount.name }} +{{- end -}} +{{- end -}} diff --git a/helm/templates/configmap.yaml b/helm/templates/configmap.yaml new file mode 100644 index 0000000..9994990 --- /dev/null +++ b/helm/templates/configmap.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "helm.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "helm.fullname" . }} + app.kubernetes.io/part-of: {{ include "helm.fullname" . }} +data: + port: {{ .Values.image.port | quote }} + cors: {{ .Values.image.cors | quote }} + mjml-keep-comments: {{ .Values.image.mjmlKeepComments | quote }} + mjml-validation-level: {{ .Values.image.mjmlValidationLevel | quote }} + mjml-minify: {{ .Values.image.mjmlMinify | quote }} + mjml-beautify: {{ .Values.image.mjmlBeautify | quote }} + \ No newline at end of file diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..7ecc4aa --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,89 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "helm.fullname" . }} + labels: +{{ include "helm.labels" . | indent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "helm.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "helm.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + ports: + - name: http + containerPort: {{ .Values.image.port }} + protocol: TCP + livenessProbe: + exec: + command: + - curl + - -X POST + - 'http://localhost:{{ .Values.image.port }}/' + initialDelaySeconds: 30 + periodSeconds: 30 + readinessProbe: + exec: + command: + - curl + - -X POST + - 'http://localhost:{{ .Values.image.port }}/' + initialDelaySeconds: 25 + env: + - name: PORT + valueFrom: + configMapKeyRef: + name: {{ template "helm.fullname" . }} + key: port + - name: CORS + valueFrom: + configMapKeyRef: + name: {{ template "helm.fullname" . }} + key: cors + - name: MJML_KEEP_COMMENTS + valueFrom: + configMapKeyRef: + name: {{ template "helm.fullname" . }} + key: mjml-keep-comments + - name: MJML_VALIDATION_LEVEL + valueFrom: + configMapKeyRef: + name: {{ template "helm.fullname" . }} + key: mjml-validation-level + - name: MJML_MINIFY + valueFrom: + configMapKeyRef: + name: {{ template "helm.fullname" . }} + key: mjml-minify + - name: MJML_BEAUTIFY + valueFrom: + configMapKeyRef: + name: {{ template "helm.fullname" . }} + key: mjml-beautify + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- 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/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..c16db3e --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "helm.fullname" . }} + labels: +{{ include "helm.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.image.port }} + protocol: TCP + selector: + app.kubernetes.io/name: {{ include "helm.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..2e84043 --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,39 @@ +# Default values for helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: adrianrudnik/mjml-server + tag: latest + port: 80 + cors: "*" + mjmlKeepComments: false + mjmlValidationLevel: "soft" + mjmlMinify: true + mjmlBeautify: false +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + +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: {}