Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions charts/docker-mailserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Minimal Configuration](#minimal-configuration)
- [Certificate](#certificate)
- [Ports](#ports)
- [Rspamd web interface and metrics](#rspamd-web-interface-and-metrics)
- [Persistence](#persistence)
- [Backing Storage](#backing-storage)
- [Generic / All](#generic--all)
Expand Down Expand Up @@ -248,6 +249,12 @@ If you do not enable the PROXY protocol and your mail server is not exposed usin
[dms-docs::k8s::proxy-protocol]: https://docker-mailserver.github.io/docker-mailserver/latest/config/advanced/kubernetes/#proxy-port-to-service-via-proxy-protocol
[k3s-klipperlb-pp]: https://github.com/docker-mailserver/docker-mailserver-helm/issues/176#issuecomment-3097915161

### Rspamd web interface and metrics

The Rspamd web interface (port 11334) and the metrics exporter (`monitoring.service.port`, 9102 by default) are not on the main Service. They are on a separate ClusterIP Service named `<fullname>-internal`, so a main Service of type `LoadBalancer` or `NodePort` never publishes them outside the cluster. The Rspamd ingress (`rspamd.ingress`) and the ServiceMonitor (`metrics.serviceMonitor`) use the internal Service, and it carries the `prometheus.io/*` annotations. `service.labels`, `service.ipFamilyPolicy` and `service.ipFamilies` apply to both Services.

If you reached the Rspamd web interface or scraped the metrics through the main Service before (a port-forward, an annotation-based scrape, or an external address), use `<fullname>-internal` instead.

## Persistence

Docker-mailserver assumes there are [four](https://docker-mailserver.github.io/docker-mailserver/latest/config/advanced/optional-config/#volumes) mounted volumes:
Expand Down
2 changes: 1 addition & 1 deletion charts/docker-mailserver/templates/ingress-rspamd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
path: {{ .Values.rspamd.ingress.path }}
backend:
service:
name: {{ template "dockermailserver.fullname" . }}
name: {{ template "dockermailserver.fullname" . }}-internal
port:
name: rspamd

Expand Down
48 changes: 48 additions & 0 deletions charts/docker-mailserver/templates/service-internal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{{- if or .Values.deployment.env.ENABLE_RSPAMD .Values.metrics.enabled }}
---
## The Rspamd web interface and the metrics exporter live on this ClusterIP
## Service, never on the main Service, so a LoadBalancer or NodePort main
## Service does not publish them outside the cluster. The rspamd ingress and the
## ServiceMonitor use this Service.
kind: "Service"
apiVersion: "v1"
metadata:
annotations:
## These annotations mark the service as monitorable by Prometheus, both directly as a service level metric and
## via the blackbox exporter. For more information, see values.yaml
prometheus.io/scrape: {{ .Values.monitoring.service.scrape | quote }}
prometheus.io/probe: {{ .Values.monitoring.service.probe | quote }}
prometheus.io/path: {{ .Values.monitoring.service.path | quote }}
prometheus.io/port: {{ .Values.monitoring.service.port | quote }}
labels:
app.kubernetes.io/name: {{ template "dockermailserver.fullname" . }}
app.kubernetes.io/component: internal
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: "{{ .Release.Service }}"
release: "{{ .Release.Name }}"
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | indent 4 }}
{{- end }}
name: {{ template "dockermailserver.fullname" . }}-internal
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: {{ template "dockermailserver.fullname" . }}
release: "{{ .Release.Name }}"
ports:
{{- if .Values.deployment.env.ENABLE_RSPAMD }}
- name: rspamd
targetPort: rspamd
port: 11334
{{- end }}
{{- if .Values.metrics.enabled }}
- name: metrics
targetPort: metrics
port: {{ .Values.monitoring.service.port }}
{{- end }}
ipFamilyPolicy: {{ default "SingleStack" .Values.service.ipFamilyPolicy }}
{{- if .Values.service.ipFamilies }}
ipFamilies:
{{- toYaml .Values.service.ipFamilies | nindent 2 }}
{{- end }}
{{- end }}
22 changes: 1 addition & 21 deletions charts/docker-mailserver/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@
kind: "Service"
apiVersion: "v1"
metadata:
annotations:
## These annontations mark the service as monitorable by Prometheus, both directly as a service level metric and
## via the blackbox exporter. For more information, see
## values.yaml
prometheus.io/scrape: {{ .Values.monitoring.service.scrape | quote }}
prometheus.io/probe: {{ .Values.monitoring.service.probe | quote }}
prometheus.io/path: {{ .Values.monitoring.service.path | quote }}
prometheus.io/port: {{ .Values.monitoring.service.port | quote }}
##
{{- if .Values.service.annotations }}
annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{ end }}
labels:
Expand Down Expand Up @@ -118,12 +110,6 @@ spec:
{{- end }}
{{- end }}

{{- if .Values.deployment.env.ENABLE_RSPAMD }}
- name: rspamd
targetPort: rspamd
port: 11334
{{- end }}

{{- if and (.Values.deployment.env.ENABLE_MANAGESIEVE) (not .Values.deployment.env.SMTP_ONLY) }}
- name: managesieve
targetPort: managesieve
Expand All @@ -135,12 +121,6 @@ spec:
{{- end }}
{{- end }}

{{- if .Values.metrics.enabled }}
- name: metrics
port: {{ .Values.monitoring.service.port }}
targetPort: metrics
{{- end }}

type: {{ default "ClusterIP" .Values.service.type }}
{{- if .Values.service.clusterIp }}
clusterIP: {{ .Values.service.clusterIp }}
Expand Down
1 change: 1 addition & 0 deletions charts/docker-mailserver/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
selector:
matchLabels:
app.kubernetes.io/name: {{ template "dockermailserver.fullname" . }}
app.kubernetes.io/component: internal
release: "{{ .Release.Name }}"

{{- end }}
124 changes: 124 additions & 0 deletions charts/docker-mailserver/tests/service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
suite: service tests
templates:
- service.yaml
- service-internal.yaml
- ingress-rspamd.yaml
- servicemonitor.yaml
chart:
version: 0.1.0
appVersion: 0.1.0
values:
- ../values.yaml
set:
service.type: LoadBalancer
metrics.enabled: true
metrics.serviceMonitor.enabled: true
rspamd.ingress.enabled: true
tests:
- it: keeps the rspamd and metrics ports off the main service
template: service.yaml
asserts:
- notContains:
path: spec.ports
any: true
content:
name: rspamd
- notContains:
path: spec.ports
any: true
content:
name: metrics
- contains:
path: spec.ports
any: true
content:
name: smtp

- it: leaves the prometheus annotations off the main service
template: service.yaml
asserts:
- notExists:
path: metadata.annotations["prometheus.io/scrape"]
- notExists:
path: metadata.annotations["prometheus.io/port"]

- it: serves the rspamd and metrics ports on a ClusterIP service
template: service-internal.yaml
asserts:
- isKind:
of: Service
- matchRegex:
path: metadata.name
pattern: -docker-mailserver-internal$
- equal:
path: spec.type
value: ClusterIP
- equal:
path: metadata.labels["app.kubernetes.io/component"]
value: internal
- equal:
path: spec.ports
value:
- name: rspamd
targetPort: rspamd
port: 11334
- name: metrics
targetPort: metrics
port: 9102

- it: carries the prometheus annotations on the internal service
template: service-internal.yaml
asserts:
- equal:
path: metadata.annotations["prometheus.io/scrape"]
value: "true"
- equal:
path: metadata.annotations["prometheus.io/port"]
value: "9102"
- equal:
path: metadata.annotations["prometheus.io/path"]
value: /metrics

- it: applies service.labels and the IP family settings to the internal service
template: service-internal.yaml
set:
service.labels:
team: mail
service.ipFamilyPolicy: PreferDualStack
service.ipFamilies: [IPv4, IPv6]
asserts:
- equal:
path: metadata.labels.team
value: mail
- equal:
path: spec.ipFamilyPolicy
value: PreferDualStack
- equal:
path: spec.ipFamilies
value: [IPv4, IPv6]

- it: renders no internal service when rspamd and metrics are both off
template: service-internal.yaml
set:
deployment.env.ENABLE_RSPAMD: 0
metrics.enabled: false
asserts:
- hasDocuments:
count: 0

- it: routes the rspamd ingress to the internal service
template: ingress-rspamd.yaml
asserts:
- matchRegex:
path: spec.rules[0].http.paths[0].backend.service.name
pattern: -docker-mailserver-internal$
- equal:
path: spec.rules[0].http.paths[0].backend.service.port.name
value: rspamd

- it: scrapes only the internal service, so metrics are not collected twice
template: servicemonitor.yaml
asserts:
- equal:
path: spec.selector.matchLabels["app.kubernetes.io/component"]
value: internal
3 changes: 2 additions & 1 deletion charts/docker-mailserver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ persistence:
## See https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml
monitoring:
## Whether to scrape this service with the monitoring toolkit. Mostly useful for blackbox probing of a given service
## to ensure it's "up"
## to ensure it's "up". These prometheus.io/* annotations go on the <fullname>-internal Service, which carries the
## metrics port (the main Service does not).
service:
## monitoring should be configured to only scrape services that have a value of "true"
scrape: "true"
Expand Down
Loading