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

Helm chart #15

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
22 changes: 22 additions & 0 deletions helm/.helmignore
Original file line number Diff line number Diff line change
@@ -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/
5 changes: 5 additions & 0 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "2.2.2"
description: Helm chart for mjml-server
name: mjml-server
version: 0.1.0
1 change: 1 addition & 0 deletions helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The server will run on port {{ .Values.image.port }}
56 changes: 56 additions & 0 deletions helm/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -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 -}}
15 changes: 15 additions & 0 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

89 changes: 89 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
14 changes: 14 additions & 0 deletions helm/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
39 changes: 39 additions & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
@@ -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: {}