Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(helm): add Helm chart for Kubernetes deployments (#1061)

Yudhi Armyndharisb92af557b7f7
diff --git a/.dockerignore b/.dockerignore
index bca194612..828f2cd9f 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -66,3 +66,6 @@ temp/
# Debug
.pnpm-debug.log*
+
+# Helm chart — deployment artifact, not a build input
+charts/
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 226eb965d..e1ed6c9ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
without one. `send-catalog` stays `501` on both engines: neither library has a catalog-share
message type. whatsapp-web.js is unchanged (`501` throughout — it has no catalog API). (#905)
+- **Helm chart for Kubernetes deployments, under `charts/openwa/`.** A single-replica
+ StatefulSet with a PVC for `/app/data` (session auth, main DB, media, plugins), the
+ docker-compose hardening mirrored (read-only rootfs, dropped capabilities, writable
+ `emptyDir` at `/tmp`), free-form `env`/`secretEnv` maps covering every variable in
+ `.env.example`, and optional Ingress, PodDisruptionBudget and ServiceMonitor.
+ Datastores are not bundled — point `env` at your own or stay on the SQLite default.
+ Closes #695.
+
### Fixed
- **A contact who hides their number no longer keeps a stale `lid -> phone` mapping forever.**
diff --git a/charts/openwa/Chart.yaml b/charts/openwa/Chart.yaml
new file mode 100644
index 000000000..cc66f5f33
--- /dev/null
+++ b/charts/openwa/Chart.yaml
@@ -0,0 +1,13 @@
+apiVersion: v2
+name: openwa
+description: OpenWA — WhatsApp API. Single-instance StatefulSet (see values.yaml replicaCount warning).
+type: application
+version: 0.1.0
+appVersion: "0.12.5"
+keywords:
+ - whatsapp
+ - openwa
+ - api
+home: https://github.com/rmyndharis/OpenWA
+sources:
+ - https://github.com/rmyndharis/OpenWA
diff --git a/charts/openwa/README.md b/charts/openwa/README.md
new file mode 100644
index 000000000..de1014ae0
--- /dev/null
+++ b/charts/openwa/README.md
@@ -0,0 +1,39 @@
+# openwa
+
+Helm chart for [OpenWA](https://github.com/rmyndharis/OpenWA) — WhatsApp API.
+
+> **Single instance only.** OpenWA is single-process with in-memory engine state.
+> Keep `replicaCount: 1`; scaling out corrupts WhatsApp session auth. See
+> [docs/13-horizontal-scaling.md](../../docs/13-horizontal-scaling.md).
+
+## Install
+
+```bash
+helm install openwa ./charts/openwa \
+ --set secretEnv.API_MASTER_KEY=$(openssl rand -base64 32)
+```
+
+With `secretEnv.API_MASTER_KEY` left empty the app bootstraps a key into
+`/app/data/.api-key` on the PVC; the post-install NOTES show how to read it.
+
+## Configuration
+
+`env` (→ ConfigMap) and `secretEnv` (→ Secret) are free-form maps: any variable
+from the repo's `.env.example` works, e.g.:
+
+The container port is fixed at 2785; do not set PORT in env (probes and the
+Service targetPort are pinned to it) — service.port changes the Service port.
+
+```bash
+helm install openwa ./charts/openwa \
+ --set env.DATABASE_TYPE=postgres \
+ --set env.DATABASE_HOST=postgres.default.svc \
+ --set secretEnv.DATABASE_USERNAME=openwa \
+ --set secretEnv.DATABASE_PASSWORD=...
+```
+
+Or bring your own Secret: `--set existingSecret=my-openwa-secret`.
+
+All other values (`persistence`, `resources`, `ingress`, `serviceMonitor`, …) are
+documented inline in [values.yaml](values.yaml). The chart does NOT bundle
+PostgreSQL/Redis/MinIO — point `env` at your own, or stay on the SQLite default.
diff --git a/charts/openwa/templates/NOTES.txt b/charts/openwa/templates/NOTES.txt
new file mode 100644
index 000000000..ca9d16969
--- /dev/null
+++ b/charts/openwa/templates/NOTES.txt
@@ -0,0 +1,18 @@
+OpenWA has been installed as release "{{ .Release.Name }}".
+
+ WARNING: replicaCount must stay 1. OpenWA holds live WhatsApp engine state in
+ memory; scaling out corrupts session auth. See docs/13-horizontal-scaling.md.
+
+1. Wait for the pod:
+ kubectl -n {{ .Release.Namespace }} rollout status statefulset/{{ include "openwa.fullname" . }}
+
+2. Get the API key. If secretEnv.API_MASTER_KEY was left empty, the app generated
+ one on first boot and stored it on the PVC:
+ kubectl -n {{ .Release.Namespace }} exec {{ include "openwa.fullname" . }}-0 -- cat /app/data/.api-key
+
+3. Reach the API + dashboard:
+ kubectl -n {{ .Release.Namespace }} port-forward svc/{{ include "openwa.fullname" . }} 2785:{{ .Values.service.port }}
+ then open http://localhost:2785 (dashboard) or call http://localhost:2785/api.
+{{- if .Values.ingress.enabled }}
+ Or via the ingress host: http{{ if .Values.ingress.tls }}s{{ end }}://{{ .Values.ingress.host }}
+{{- end }}
diff --git a/charts/openwa/templates/_helpers.tpl b/charts/openwa/templates/_helpers.tpl
new file mode 100644
index 000000000..e5fa5a019
--- /dev/null
+++ b/charts/openwa/templates/_helpers.tpl
@@ -0,0 +1,45 @@
+{{- define "openwa.name" -}}
+{{- .Chart.Name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{- define "openwa.fullname" -}}
+{{- if contains .Chart.Name .Release.Name }}
+{{- .Release.Name | trunc 63 | trimSuffix "-" }}
+{{- else }}
+{{- printf "%s-%s" .Release.Name .Chart.Name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+{{- end }}
+
+{{- define "openwa.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{- define "openwa.labels" -}}
+helm.sh/chart: {{ include "openwa.chart" . }}
+{{ include "openwa.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{- define "openwa.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "openwa.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
+
+{{- define "openwa.serviceAccountName" -}}
+{{- if .Values.serviceAccount.create }}
+{{- default (include "openwa.fullname" .) .Values.serviceAccount.name }}
+{{- else }}
+{{- default "default" .Values.serviceAccount.name }}
+{{- end }}
+{{- end }}
+
+{{- define "openwa.secretName" -}}
+{{- if .Values.existingSecret }}
+{{- .Values.existingSecret }}
+{{- else }}
+{{- include "openwa.fullname" . }}
+{{- end }}
+{{- end }}
diff --git a/charts/openwa/templates/configmap.yaml b/charts/openwa/templates/configmap.yaml
new file mode 100644
index 000000000..c62728741
--- /dev/null
+++ b/charts/openwa/templates/configmap.yaml
@@ -0,0 +1,10 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+data:
+ {{- range $key, $value := .Values.env }}
+ {{ $key }}: {{ $value | quote }}
+ {{- end }}
diff --git a/charts/openwa/templates/ingress.yaml b/charts/openwa/templates/ingress.yaml
new file mode 100644
index 000000000..dbefb8cdc
--- /dev/null
+++ b/charts/openwa/templates/ingress.yaml
@@ -0,0 +1,33 @@
+{{- if .Values.ingress.enabled }}
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+ {{- with .Values.ingress.annotations }}
+ annotations:
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+spec:
+ {{- if .Values.ingress.className }}
+ ingressClassName: {{ .Values.ingress.className }}
+ {{- end }}
+ rules:
+ - host: {{ .Values.ingress.host | quote }}
+ http:
+ paths:
+ {{- range .Values.ingress.paths }}
+ - path: {{ .path | quote }}
+ pathType: {{ .pathType }}
+ backend:
+ service:
+ name: {{ include "openwa.fullname" $ }}
+ port:
+ name: http
+ {{- end }}
+ {{- with .Values.ingress.tls }}
+ tls:
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+{{- end }}
diff --git a/charts/openwa/templates/pdb.yaml b/charts/openwa/templates/pdb.yaml
new file mode 100644
index 000000000..b9a39a417
--- /dev/null
+++ b/charts/openwa/templates/pdb.yaml
@@ -0,0 +1,13 @@
+{{- if .Values.podDisruptionBudget.enabled }}
+apiVersion: policy/v1
+kind: PodDisruptionBudget
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+spec:
+ minAvailable: {{ .Values.podDisruptionBudget.minAvailable }}
+ selector:
+ matchLabels:
+ {{- include "openwa.selectorLabels" . | nindent 6 }}
+{{- end }}
diff --git a/charts/openwa/templates/secret.yaml b/charts/openwa/templates/secret.yaml
new file mode 100644
index 000000000..279f3db33
--- /dev/null
+++ b/charts/openwa/templates/secret.yaml
@@ -0,0 +1,13 @@
+{{- if not .Values.existingSecret }}
+apiVersion: v1
+kind: Secret
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+type: Opaque
+stringData:
+ {{- range $key, $value := .Values.secretEnv }}
+ {{ $key }}: {{ $value | quote }}
+ {{- end }}
+{{- end }}
diff --git a/charts/openwa/templates/service-headless.yaml b/charts/openwa/templates/service-headless.yaml
new file mode 100644
index 000000000..e3e4dc708
--- /dev/null
+++ b/charts/openwa/templates/service-headless.yaml
@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ include "openwa.fullname" . }}-headless
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+spec:
+ clusterIP: None
+ publishNotReadyAddresses: true
+ selector:
+ {{- include "openwa.selectorLabels" . | nindent 4 }}
+ ports:
+ - name: http
+ port: 2785
+ targetPort: http
diff --git a/charts/openwa/templates/service.yaml b/charts/openwa/templates/service.yaml
new file mode 100644
index 000000000..489d61cf6
--- /dev/null
+++ b/charts/openwa/templates/service.yaml
@@ -0,0 +1,14 @@
+apiVersion: v1
+kind: Service
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+spec:
+ type: {{ .Values.service.type }}
+ selector:
+ {{- include "openwa.selectorLabels" . | nindent 4 }}
+ ports:
+ - name: http
+ port: {{ .Values.service.port }}
+ targetPort: http
diff --git a/charts/openwa/templates/serviceaccount.yaml b/charts/openwa/templates/serviceaccount.yaml
new file mode 100644
index 000000000..a5dbf0b66
--- /dev/null
+++ b/charts/openwa/templates/serviceaccount.yaml
@@ -0,0 +1,12 @@
+{{- if .Values.serviceAccount.create }}
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: {{ include "openwa.serviceAccountName" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+ {{- with .Values.serviceAccount.annotations }}
+ annotations:
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+{{- end }}
diff --git a/charts/openwa/templates/servicemonitor.yaml b/charts/openwa/templates/servicemonitor.yaml
new file mode 100644
index 000000000..a4a5457ba
--- /dev/null
+++ b/charts/openwa/templates/servicemonitor.yaml
@@ -0,0 +1,24 @@
+{{- if .Values.serviceMonitor.enabled }}
+apiVersion: monitoring.coreos.com/v1
+kind: ServiceMonitor
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+ {{- with .Values.serviceMonitor.additionalLabels }}
+ {{- toYaml . | nindent 4 }}
+ {{- end }}
+spec:
+ selector:
+ matchLabels:
+ {{- include "openwa.selectorLabels" . | nindent 6 }}
+ endpoints:
+ - port: http
+ path: /api/metrics
+ interval: {{ .Values.serviceMonitor.interval }}
+ {{- if .Values.serviceMonitor.bearerTokenSecret.name }}
+ bearerTokenSecret:
+ name: {{ .Values.serviceMonitor.bearerTokenSecret.name }}
+ key: {{ .Values.serviceMonitor.bearerTokenSecret.key }}
+ {{- end }}
+{{- end }}
diff --git a/charts/openwa/templates/statefulset.yaml b/charts/openwa/templates/statefulset.yaml
new file mode 100644
index 000000000..922bddf19
--- /dev/null
+++ b/charts/openwa/templates/statefulset.yaml
@@ -0,0 +1,89 @@
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+ name: {{ include "openwa.fullname" . }}
+ labels:
+ {{- include "openwa.labels" . | nindent 4 }}
+spec:
+ serviceName: {{ include "openwa.fullname" . }}-headless
+ replicas: {{ .Values.replicaCount }}
+ selector:
+ matchLabels:
+ {{- include "openwa.selectorLabels" . | nindent 6 }}
+ template:
+ metadata:
+ labels:
+ {{- include "openwa.selectorLabels" . | nindent 8 }}
+ spec:
+ terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
+ serviceAccountName: {{ include "openwa.serviceAccountName" . }}
+ # The app never calls the Kubernetes API — don't mount a token it can't use.
+ automountServiceAccountToken: false
+ {{- with .Values.imagePullSecrets }}
+ imagePullSecrets:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ containers:
+ - name: {{ .Chart.Name }}
+ image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+ imagePullPolicy: {{ .Values.image.pullPolicy }}
+ ports:
+ - name: http
+ containerPort: 2785
+ envFrom:
+ - configMapRef:
+ name: {{ include "openwa.fullname" . }}
+ - secretRef:
+ name: {{ include "openwa.secretName" . }}
+ livenessProbe:
+ httpGet:
+ path: /api/health/live
+ port: http
+ initialDelaySeconds: 30
+ periodSeconds: 10
+ readinessProbe:
+ httpGet:
+ path: /api/health/ready
+ port: http
+ initialDelaySeconds: 10
+ periodSeconds: 5
+ resources:
+ {{- toYaml .Values.resources | nindent 12 }}
+ securityContext:
+ {{- toYaml .Values.containerSecurityContext | nindent 12 }}
+ volumeMounts:
+ - name: data
+ mountPath: /app/data
+ - name: tmp
+ mountPath: /tmp
+ volumes:
+ - name: tmp
+ emptyDir: {}
+ {{- with .Values.nodeSelector }}
+ nodeSelector:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ {{- with .Values.affinity }}
+ affinity:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ {{- with .Values.tolerations }}
+ tolerations:
+ {{- toYaml . | nindent 8 }}
+ {{- end }}
+ volumeClaimTemplates:
+ # volumeClaimTemplates is immutable in the StatefulSet API — only ever put
+ # immutable labels here (selectorLabels), never the chart/app-version labels.
+ - metadata:
+ name: data
+ labels:
+ {{- include "openwa.selectorLabels" . | nindent 10 }}
+ spec:
+ accessModes:
+ {{- toYaml .Values.persistence.accessModes | nindent 10 }}
+ {{- if .Values.persistence.storageClass }}
+ storageClassName: {{ .Values.persistence.storageClass | quote }}
+ {{- end }}
+ resources:
+ requests:
+ storage: {{ .Values.persistence.size }}
diff --git a/charts/openwa/values.yaml b/charts/openwa/values.yaml
new file mode 100644
index 000000000..9ade28c08
--- /dev/null
+++ b/charts/openwa/values.yaml
@@ -0,0 +1,117 @@
+# replicaCount MUST stay 1. OpenWA is a single-process application: live WhatsApp
+# engine state is in-memory, and two pods driving the same session data corrupt the
+# session auth (forced logout / ban). See docs/13-horizontal-scaling.md.
+replicaCount: 1
+
+image:
+ repository: ghcr.io/rmyndharis/openwa
+ # Defaults to the chart's appVersion when empty.
+ tag: ""
+ pullPolicy: IfNotPresent
+
+imagePullSecrets: []
+
+# Non-secret application config, rendered into a ConfigMap and loaded via envFrom.
+# Any variable from .env.example is valid here — that file stays the canonical list.
+# NOTE: the container port is fixed at 2785 (containerPort, probes and the Service
+# targetPort are all pinned to it). Setting PORT here breaks the pod — use
+# service.port to change the Service port instead.
+env:
+ NODE_ENV: production
+ LOG_LEVEL: info
+
+# Secret config, rendered into a chart-managed Secret (stringData). Leave
+# API_MASTER_KEY empty to let the app bootstrap a key into /app/data/.api-key
+# (persists on the PVC) — NOTES.txt after install shows how to read it.
+# If a key exists in both env and secretEnv, the secret value wins (envFrom ordering).
+secretEnv:
+ API_MASTER_KEY: ""
+
+# Name of an existing, operator-managed Secret to load via envFrom instead of the
+# chart-managed one. When set, secretEnv is ignored and no Secret is created.
+existingSecret: ""
+
+service:
+ type: ClusterIP
+ port: 80
+
+persistence:
+ # /app/data holds session auth, the main SQLite DB, media and plugins — losing
+ # this volume loses the linked WhatsApp sessions and the API keys.
+ # Empty storageClass means the cluster's default StorageClass; the PVC pends if
+ # the cluster has none.
+ size: 10Gi
+ storageClass: ""
+ accessModes:
+ - ReadWriteOnce
+
+# Headless Chromium (whatsapp-web.js) is memory-heavy during QR/init; too-tight
+# limits show up as OOMKilled loops at session start.
+resources:
+ requests:
+ memory: 512Mi
+ cpu: 250m
+ limits:
+ memory: 2Gi
+ cpu: 1000m
+
+# Matches docker-compose stop_grace_period: graceful drain + per-engine Chromium
+# teardown can exceed the 30s k8s default.
+terminationGracePeriodSeconds: 45
+
+# Parity with docker-compose hardening. The image entrypoint STARTS AS ROOT to
+# chown /app/data + the XDG dirs, then drops to the openwa user via gosu — so do
+# NOT add runAsNonRoot here; it breaks that pattern.
+containerSecurityContext:
+ readOnlyRootFilesystem: true
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop:
+ - ALL
+ add:
+ - CHOWN
+ - DAC_OVERRIDE
+ - FOWNER
+ - SETGID
+ - SETUID
+
+ingress:
+ enabled: false
+ className: ""
+ annotations: {}
+ host: openwa.example.com
+ paths:
+ - path: /
+ pathType: Prefix
+ tls: []
+ # - secretName: openwa-tls
+ # hosts:
+ # - openwa.example.com
+
+serviceAccount:
+ create: true
+ name: ""
+ annotations: {}
+
+# With replicaCount 1, minAvailable: 1 blocks voluntary eviction (node drains hang
+# until the pod is rescheduled). Opt in only with a matching runbook.
+podDisruptionBudget:
+ enabled: false
+ minAvailable: 1
+
+# Requires METRICS_TOKEN set on the app (via secretEnv); without it /api/metrics
+# returns 404.
+serviceMonitor:
+ enabled: false
+ interval: 30s
+ # Extra labels for the ServiceMonitor — most Prometheus Operators select
+ # ServiceMonitors by a release label (e.g. release: kube-prometheus-stack).
+ additionalLabels: {}
+ # Secret holding the METRICS_TOKEN value for bearer auth.
+ bearerTokenSecret:
+ name: ""
+ key: token
+
+nodeSelector: {}
+tolerations: []
+affinity: {}
diff --git a/docs/10-devops-infrastructure.md b/docs/10-devops-infrastructure.md
index 67e1b2e87..2607ef3d8 100644
--- a/docs/10-devops-infrastructure.md
+++ b/docs/10-devops-infrastructure.md
@@ -273,6 +273,24 @@ volumes:
> [13 - Horizontal Scaling Guide](./13-horizontal-scaling.md) for the `replicas: 1` stance and the
> (unimplemented) session-claim design that would be required first.
+### Helm Chart (Kubernetes)
+
+The maintained way to deploy on Kubernetes is the Helm chart at `charts/openwa/`:
+
+```bash
+helm install openwa ./charts/openwa \
+ --set secretEnv.API_MASTER_KEY=$(openssl rand -base64 32)
+```
+
+It renders a single-replica StatefulSet (`replicaCount: 1` — the same constraint as
+the compose warning above) with a PVC for `/app/data`, the compose hardening mirrored
+(read-only rootfs, dropped capabilities, writable `emptyDir` at `/tmp`), and optional
+Ingress / PodDisruptionBudget / ServiceMonitor. Configuration goes through free-form
+`env` and `secretEnv` maps — any variable from `.env.example` works; see
+`charts/openwa/README.md` and the inline comments in `charts/openwa/values.yaml`.
+The k8s manifests in [13 - Horizontal Scaling Guide](./13-horizontal-scaling.md) are
+an illustrative design sketch; the chart is the authoritative artifact.
+
## 10.3 CI/CD Pipeline
### GitHub Actions Workflow