Add Mailu email server deployment via Helm chart
This commit is contained in:
+180
@@ -0,0 +1,180 @@
|
||||
# Email / Mailu
|
||||
|
||||
Mailu mail server deployed via the official Helm chart (`mailu 2.7.1`,
|
||||
appVersion `2024.06.51`). Managed by Helm, **not** `kubectl apply` — same model
|
||||
as the kube-prometheus-stack release in `Monitoring/`.
|
||||
|
||||
## Layout
|
||||
|
||||
| File | Kind | How to apply |
|
||||
|---|---|---|
|
||||
| `mailu_namespace.yaml` | Namespace | `kubectl apply -f` |
|
||||
| `mailu_lbippool.yaml` | CiliumLoadBalancerIPPool (`10.4.0.0/24`) | `kubectl apply -f` |
|
||||
| `mailu.values.yaml` | Helm values | `helm upgrade ... -f` (do NOT `kubectl apply`) |
|
||||
|
||||
Two non-Helm manifests (namespace + LBIP pool) are applied once with
|
||||
`kubectl apply -f`. Everything else is rendered by the Helm chart.
|
||||
|
||||
## Prerequisites — do these first (in order)
|
||||
|
||||
### 1. Apply the namespace + Cilium LB pool
|
||||
|
||||
```bash
|
||||
kubectl apply -f Email/mailu_namespace.yaml
|
||||
kubectl apply -f Email/mailu_lbippool.yaml
|
||||
```
|
||||
|
||||
### 2. Create the Mailu databases on the existing PostgreSQL
|
||||
|
||||
Mailu reuses the existing `postgres-hetzner` instance in the `database`
|
||||
namespace (`Service postgres.database.svc.cluster.local:5432`, admin user
|
||||
`admin`). The chart does NOT create databases/users when `externalDatabase` is
|
||||
enabled, so do it manually before `helm install`.
|
||||
|
||||
Get a shell on the postgres pod and create the `mailu` + `roundcube` databases
|
||||
and users. Replace `<MAILU_PW>` and `<ROUNDCUBE_PW>` with strong generated
|
||||
values (you'll reuse them in the secret below).
|
||||
|
||||
```bash
|
||||
# Generate the two passwords once and keep them for the next step:
|
||||
MAILU_PW=$(pwgen 24 1); echo "mailu: $MAILU_PW"
|
||||
ROUNDCUBE_PW=$(pwgen 24 1); echo "roundcube: $ROUNDCUBE_PW"
|
||||
|
||||
# Create databases + users on the existing postgres-hetzner:
|
||||
kubectl exec -n database deploy/postgres-hetzner -- psql -U admin -d postgres <<SQL
|
||||
CREATE USER mailu WITH LOGIN PASSWORD '$MAILU_PW';
|
||||
CREATE USER roundcube WITH LOGIN PASSWORD '$ROUNDCUBE_PW';
|
||||
CREATE DATABASE mailu OWNER mailu;
|
||||
CREATE DATABASE roundcube OWNER roundcube;
|
||||
\c mailu
|
||||
CREATE EXTENSION IF NOT EXISTS citext;
|
||||
SQL
|
||||
```
|
||||
|
||||
`citext` is required by Mailu on the `mailu` database (case-insensitive text).
|
||||
The `roundcube` database needs no extension.
|
||||
|
||||
### 3. Create the out-of-band secrets (gitignored — never `git add`)
|
||||
|
||||
Following the repo convention (see root README "Private registry authentication"
|
||||
and AGENTS.md "Secrets are gitignored"), these are created manually and are NOT
|
||||
committed.
|
||||
|
||||
```bash
|
||||
# Mailu secret-key + initial admin password
|
||||
kubectl create secret generic mailu-secret -n mailu \
|
||||
--from-literal=secret-key="$(pwgen 16 1)" \
|
||||
--from-literal=initial-admin-password="$(pwgen 24 1)"
|
||||
|
||||
# Mailu + Roundcube DB credentials against the existing postgres-hetzner.
|
||||
# Reuse the exact MAILU_PW / ROUNDCUBE_PW from step 2.
|
||||
kubectl create secret generic mailu-db-secret -n mailu \
|
||||
--from-literal=database=mailu \
|
||||
--from-literal=username=mailu \
|
||||
--from-literal=password="$MAILU_PW" \
|
||||
--from-literal=roundcube-password="$ROUNDCUBE_PW"
|
||||
```
|
||||
|
||||
If `pwgen` is not installed: `apt-get install -y pwgen` (or use
|
||||
`openssl rand -base64 24`).
|
||||
|
||||
### 3. External (non-repo) prerequisites — you must do these outside k8s
|
||||
|
||||
1. **Hetzner PTR record.** In the Hetzner Cloud Console, set the reverse DNS of
|
||||
the LoadBalancer IP `10.4.0.122` to `mail.mariushome.lt`. Without a PTR,
|
||||
receivers (Gmail/Outlook) silently drop your mail.
|
||||
2. **DNS records at your DNS provider** (NOT in this repo):
|
||||
- `A mail.mariushome.lt -> <public IP that 10.4.0.122 routes to>`
|
||||
- `MX mariushome.lt -> mail.mariushome.lt (prio 10)`
|
||||
- `TXT mariushome.lt "v=spf1 mx ~all"`
|
||||
- `TXT _dmarc.mariushome.lt "v=DMARC1; p=quarantine; rua=mailto:postmaster@mariushome.lt"`
|
||||
- DKIM: generated by the Mailu admin UI on first boot — add the `TXT`
|
||||
record Mailu shows you (typically `mail._domainkey.mariushome.lt`).
|
||||
- Optional: MTA-STS (`TXT _mta-sts.mariushome.lt` + a `/.well-known/mta-sts.txt`
|
||||
served over HTTPS — chart supports it via `front.overrides`).
|
||||
3. **Cloudflare**: only the web UIs (`mail.mariushome.lt`, and the `/admin` +
|
||||
`/webmail` paths) are proxied through Cloudflare (orange cloud). The SMTP /
|
||||
IMAP / Submission / ManageSieve ports must **NOT** go through Cloudflare —
|
||||
they need a direct, DNS-only route (grey cloud) to the Hetzner-announced IP.
|
||||
Mail clients should be configured against `mail.mariushome.lt` directly.
|
||||
4. **Hetzner Cloud firewall / security group**: ensure ports 25, 465, 587,
|
||||
143, 993, 4190 are open to the internet for the node(s) running the
|
||||
`front` pod. Hetzner blocks outbound 25 by default for new accounts —
|
||||
confirm it has been lifted (already done per planning).
|
||||
|
||||
## Install / upgrade
|
||||
|
||||
```bash
|
||||
# One time:
|
||||
helm repo add mailu https://mailu.github.io/helm-charts
|
||||
helm repo update
|
||||
|
||||
# Install:
|
||||
helm install mailu mailu/mailu -n mailu --version 2.7.1 -f Email/mailu.values.yaml
|
||||
|
||||
# Upgrade after editing Email/mailu.values.yaml:
|
||||
helm repo update
|
||||
helm upgrade mailu mailu/mailu -n mailu --version 2.7.1 -f Email/mailu.values.yaml
|
||||
```
|
||||
|
||||
The chart version `2.7.1` and `mailuVersion: "2024.06"` in the values are
|
||||
pinned deliberately — a mail server should move conservatively. To bump, edit
|
||||
both the `--version` here and (if needed) `mailuVersion` in the values, then
|
||||
test against a non-production domain first.
|
||||
|
||||
## Verification after install
|
||||
|
||||
```bash
|
||||
helm status mailu -n mailu
|
||||
kubectl get pods -n mailu # front, admin, imap, smtp, antispam, webmail, redis
|
||||
kubectl get svc -n mailu
|
||||
kubectl get ingress -n mailu
|
||||
kubectl get pvc -n mailu # mail storage (10Gi) only; DB lives on existing postgres-hetzner
|
||||
kubectl get ciliumloadbalancerippool mailu-pool
|
||||
|
||||
# Confirm the pinned mail LB IP allocated to the front external Service:
|
||||
kubectl get svc -n mailu -l app.kubernetes.io/component=front \
|
||||
-o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.loadBalancer.ingress}{"\n"}{end}'
|
||||
# Expect 10.4.0.122 in the ingress list.
|
||||
|
||||
# Mail flow smoke test (from inside the cluster):
|
||||
kubectl exec -n mailu deploy/mailu-smtp -- swaks --to <external-address> \
|
||||
--from admin@mariushome.lt --server mail.mariushome.lt
|
||||
|
||||
# DNS sanity (run from outside the cluster):
|
||||
dig MX mariushome.lt
|
||||
dig -x <mail-LB-public-IP> # must return mail.mariushome.lt (PTR)
|
||||
```
|
||||
|
||||
## Notes / gotchas
|
||||
|
||||
- **`slow` is the default StorageClass** in this cluster (SMB). The mail PVC
|
||||
in `mailu.values.yaml` sets `storageClassName: hcloud-volumes` explicitly —
|
||||
do not remove it, or mail data lands on SMB. (The metadata DB now lives on
|
||||
the existing `postgres-hetzner`, whose PVC already uses `hcloud-volumes`.)
|
||||
- **Only one default StorageClass may exist.** If `kubectl get sc` ever shows
|
||||
two `(default)`, patch the unwanted one (see AGENTS.md).
|
||||
- Mailu reuses the existing `postgres-hetzner` instance (`database` namespace)
|
||||
via `externalDatabase`. The chart's bundled PostgreSQL subchart is disabled
|
||||
(`postgresql.enabled: false`). The `mailu` and `roundcube` databases/users
|
||||
must be created manually before `helm install` — see step 2 above. The
|
||||
custom-postgres image's pgvector extension is irrelevant to Mailu; it works
|
||||
fine against the existing server.
|
||||
- `L2AnnouncementPolicy` (`Cilium/L2AnnouncementPolicy.yaml`) already announces
|
||||
LoadBalancer IPs, so no new policy is needed for `10.4.0.122`.
|
||||
- The `front` chart subchart defaults to `hostPort: true` (assumes bare-metal
|
||||
nodes). This deployment disables `hostPort` and uses `externalService`
|
||||
instead, so the Cilium LBIPAM pool hands out the IP. Do not re-enable
|
||||
`hostPort` on a managed k8s cluster.
|
||||
- `ingress.realIpFrom` lists the Cloudflare CIDRs; if you ever switch the
|
||||
upstream proxy, update this list or `front` will rate-limit / ban the new
|
||||
proxy IPs (Mailu docs warn about this).
|
||||
- Roundcube's DB lives in the existing `postgres-hetzner` instance. The chart
|
||||
does NOT auto-create it for `externalDatabase` mode — step 2 above handles
|
||||
it manually.
|
||||
- `kubectl apply -f` does NOT apply to `mailu.values.yaml` — it is consumed
|
||||
only by `helm`. Applying it with kubectl does nothing useful and may
|
||||
confuse diff tooling.
|
||||
- Admin UI is at `https://mail.mariushome.lt/admin`, webmail at
|
||||
`https://mail.mariushome.lt/webmail` (default paths; configurable via
|
||||
`admin.uri` / webmail settings in the chart).
|
||||
@@ -0,0 +1,117 @@
|
||||
# Mailu Helm values — managed via Helm (NOT kubectl apply)
|
||||
# Chart: mailu 2.7.1 (appVersion 2024.06.51)
|
||||
# Install/upgrade commands in Email/README.md
|
||||
# Edit here, then: helm upgrade mailu mailu/mailu -n mailu --version 2.7.1 -f Email/mailu.values.yaml
|
||||
|
||||
# -----------------------------
|
||||
# Identity
|
||||
# -----------------------------
|
||||
hostnames:
|
||||
- mail.mariushome.lt # primary mail hostname (PTR target)
|
||||
domain: mariushome.lt
|
||||
timezone: Europe/Vilnius
|
||||
logLevel: INFO
|
||||
postmaster: postmaster
|
||||
|
||||
# -----------------------------
|
||||
# Secrets (out-of-band, see README.md)
|
||||
# -----------------------------
|
||||
existingSecret: mailu-secret # holds secret-key + initial-admin-password
|
||||
|
||||
initialAccount:
|
||||
enabled: true
|
||||
username: admin
|
||||
domain: mariushome.lt
|
||||
existingSecret: mailu-secret
|
||||
existingSecretPasswordKey: initial-admin-password
|
||||
mode: ifmissing
|
||||
|
||||
# -----------------------------
|
||||
# Mail storage — single PVC on Hetzner block storage
|
||||
# hcloud-volumes is NOT the default SC (slow/SMB is) — set explicitly per AGENTS.md
|
||||
# -----------------------------
|
||||
persistence:
|
||||
single_pvc: true
|
||||
storageClass: hcloud-volumes
|
||||
size: 10Gi
|
||||
accessModes: [ReadWriteOnce]
|
||||
|
||||
# -----------------------------
|
||||
# External PostgreSQL — reuse the existing postgres-hetzner instance
|
||||
# (database namespace, Service postgres.database.svc.cluster.local:5432)
|
||||
# The mailu + roundcube databases and users must be created manually first;
|
||||
# see Email/README.md "Create the Mailu databases on the existing PostgreSQL".
|
||||
# -----------------------------
|
||||
postgresql:
|
||||
enabled: false # do NOT deploy the bundled postgres subchart
|
||||
|
||||
externalDatabase:
|
||||
enabled: true
|
||||
type: postgresql
|
||||
host: postgres.database.svc.cluster.local
|
||||
port: 5432
|
||||
existingSecret: mailu-db-secret # keys: database, username, password, roundcube-password
|
||||
existingSecretDatabaseKey: database
|
||||
existingSecretUsernameKey: username
|
||||
existingSecretPasswordKey: password
|
||||
|
||||
# Roundcube DB lives in the same external PG; chart does NOT create it for
|
||||
# externalDatabase mode — must be created manually (see README.md).
|
||||
global:
|
||||
database:
|
||||
roundcube:
|
||||
database: roundcube
|
||||
username: roundcube
|
||||
existingSecret: mailu-db-secret
|
||||
existingSecretPasswordKey: roundcube-password
|
||||
|
||||
# -----------------------------
|
||||
# Web UIs (admin + webmail) — behind Cilium Ingress
|
||||
# Upstream Cloudflare terminates TLS; no cert-manager in this repo
|
||||
# -----------------------------
|
||||
ingress:
|
||||
enabled: true
|
||||
ingressClassName: cilium
|
||||
pathType: Prefix
|
||||
annotations:
|
||||
ingress.cilium.io/loadbalancer-mode: "dedicated" # matches gitea/immich pattern
|
||||
tls: false # Cloudflare terminates TLS upstream
|
||||
selfSigned: false
|
||||
realIpHeader: CF-Connecting-IP
|
||||
# Cloudflare CIDRs — must be trusted or front will rate-limit/ban CF edge IPs
|
||||
# Source: https://www.cloudflare.com/ips/ (re-check periodically)
|
||||
realIpFrom: >-
|
||||
103.21.244.0/22,103.22.200.0/22,103.31.4.0/22,104.16.0.0/13,104.24.0.0/14,
|
||||
108.162.192.0/18,131.0.72.0/22,141.101.64.0/18,162.158.0.0/15,172.64.0.0/13,
|
||||
173.245.48.0/20,188.114.96.0/20,190.93.240.0/20,197.234.240.0/22,198.41.128.0/17,
|
||||
2400:cb00::/32,2606:4700::/32,2803:f800::/32,2405:b500::/32,2405:8100::/32,
|
||||
2a06:98c0::/29,2c0f:f248::/32
|
||||
|
||||
# -----------------------------
|
||||
# Mail ports (SMTP/IMAP/Submission/ManageSieve) — Cilium LoadBalancer
|
||||
# NOT hostPort (chart default assumes bare-metal); NOT through Cloudflare
|
||||
# IP pinned via lbipam.cilium.io/ips to 10.4.0.122 (mailu-pool, see mailu_lbippool.yaml)
|
||||
# -----------------------------
|
||||
front:
|
||||
hostPort:
|
||||
enabled: false # chart default true — must disable for k8s LB
|
||||
externalService:
|
||||
enabled: true
|
||||
type: LoadBalancer
|
||||
externalTrafficPolicy: Local
|
||||
annotations:
|
||||
lbipam.cilium.io/ips: "10.4.0.122"
|
||||
ports:
|
||||
smtp: true
|
||||
smtps: true
|
||||
submission: true
|
||||
imap: true
|
||||
imaps: true
|
||||
pop3: false # POP3 disabled per requirement
|
||||
pop3s: false
|
||||
manageSieve: true
|
||||
|
||||
# -----------------------------
|
||||
# Mailu app version pin (stable line)
|
||||
# -----------------------------
|
||||
mailuVersion: "2024.06"
|
||||
@@ -0,0 +1,8 @@
|
||||
apiVersion: "cilium.io/v2"
|
||||
kind: CiliumLoadBalancerIPPool
|
||||
metadata:
|
||||
name: "mailu-pool"
|
||||
spec:
|
||||
blocks:
|
||||
- start: "10.4.0.0"
|
||||
stop: "10.4.0.255"
|
||||
@@ -0,0 +1,4 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: mailu
|
||||
Reference in New Issue
Block a user