From d2b669ae713f5fb3430b100c4a366e3328f9e72e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Mon, 23 Nov 2026 21:21:41 +0100 Subject: [PATCH] feat(deploy): optional bundled Redis in the Helm chart redis.bundled.enabled adds a single Redis for trying UptimeSebi out, like the bundled TimescaleDB: password generated and kept, append-only file on a volume so sessions and schedules survive restarts, read-only root filesystem, kept with its volume on uninstall and adopted by a reinstall. Your own Redis, directly or through Sentinel, stays the way for production. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- .gitea/workflows/ci.yaml | 2 + README.md | 4 +- deploy/helm/uptimesebi/templates/NOTES.txt | 6 +- deploy/helm/uptimesebi/templates/_helpers.tpl | 14 +- deploy/helm/uptimesebi/templates/redis.yaml | 122 ++++++++++++++++++ deploy/helm/uptimesebi/values.yaml | 19 ++- 6 files changed, 158 insertions(+), 9 deletions(-) create mode 100644 deploy/helm/uptimesebi/templates/redis.yaml diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index d238551..1103a01 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -58,6 +58,8 @@ jobs: --set checker.enabled=true --set checker.token=usa_x --set statuspage.enabled=true --set statuspage.token=usa_y \ --set 'statuspage.hosts={status.example.com}' --set statuspage.ingress.enabled=true \ --set redis.sentinel.master=m --set 'redis.sentinel.addrs={s1:26379}' --set redis.sentinel.password=p >/dev/null + helm template t "$chart" --set publicURL=https://uptime.example.com --set secretKeys.value=k1:test \ + --set database.bundled.enabled=true --set redis.bundled.enabled=true --set redis.bundled.persistence.enabled=false >/dev/null if helm template t "$chart" $base >/dev/null 2>&1; then echo "rendered without a database" >&2; exit 1; fi # The install script the API serves must stay POSIX sh for Alpine, # Debian and Raspberry Pi OS; the test renders and checks it. diff --git a/README.md b/README.md index 86b7d7c..3a3459f 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ All settings are environment variables; [`.env.example`](.env.example) lists the ### Kubernetes -The Helm chart in [`deploy/helm/uptimesebi`](deploy/helm/uptimesebi) runs the console and API, and optionally a checker and status page servers in the cluster. Bring your own PostgreSQL with TimescaleDB and your own Redis (directly or through Sentinel); Redis is not bundled. Each release publishes the chart: +The Helm chart in [`deploy/helm/uptimesebi`](deploy/helm/uptimesebi) runs the console and API, and optionally a checker and status page servers in the cluster. Bring your own PostgreSQL with TimescaleDB and your own Redis (directly or through Sentinel). Each release publishes the chart: ```sh helm repo add uptimesebi https://git.zb-server.de/api/packages/zb-server/helm @@ -137,7 +137,7 @@ helm install uptime uptimesebi/uptimesebi -n uptime --create-namespace \ --set ingress.enabled=true --set ingress.tls.enabled=true ``` -Every setting can come from an existing secret instead (`existingSecret`); [`values.yaml`](deploy/helm/uptimesebi/values.yaml) explains them all. Migrations run as a hook before each install and upgrade. To try it out without a database of your own, `--set database.bundled.enabled=true` adds a single TimescaleDB without backups. Pods run unprivileged with a read-only root filesystem; the API pods need amd64 nodes, checkers and status page servers run on ARM too. +Every setting can come from an existing secret instead (`existingSecret`); [`values.yaml`](deploy/helm/uptimesebi/values.yaml) explains them all. Migrations run as a hook before each install and upgrade. To try it out without a database and Redis of your own, `--set database.bundled.enabled=true --set redis.bundled.enabled=true` adds a single TimescaleDB and Redis, without backups or high availability. Pods run unprivileged with a read-only root filesystem; the API pods need amd64 nodes, checkers and status page servers run on ARM too. Run as many API, checker and status page instances as you need; they share no local state. The supported setups are: diff --git a/deploy/helm/uptimesebi/templates/NOTES.txt b/deploy/helm/uptimesebi/templates/NOTES.txt index 75a51be..e932d24 100644 --- a/deploy/helm/uptimesebi/templates/NOTES.txt +++ b/deploy/helm/uptimesebi/templates/NOTES.txt @@ -11,8 +11,8 @@ Console: {{ .Values.publicURL }} Checkers and status page servers outside the cluster: create them in the console (Settings -> Regions) and install them with the command shown there. -{{- if .Values.database.bundled.enabled }} +{{- if or .Values.database.bundled.enabled .Values.redis.bundled.enabled }} -The bundled database is meant for trying UptimeSebi out: it has no backups -and no high availability. Its volume and password are kept on uninstall. +The bundled {{ if .Values.database.bundled.enabled }}database{{ end }}{{ if and .Values.database.bundled.enabled .Values.redis.bundled.enabled }} and {{ end }}{{ if .Values.redis.bundled.enabled }}Redis{{ end }} are meant for trying UptimeSebi out: no backups +and no high availability. Their volumes and passwords are kept on uninstall. {{- end }} diff --git a/deploy/helm/uptimesebi/templates/_helpers.tpl b/deploy/helm/uptimesebi/templates/_helpers.tpl index 08737ba..9c8d6d6 100644 --- a/deploy/helm/uptimesebi/templates/_helpers.tpl +++ b/deploy/helm/uptimesebi/templates/_helpers.tpl @@ -72,7 +72,7 @@ where $secret is the chart's secret holding values under the last argument. {{- $data := dict -}} {{- if and .Values.secretKeys.value (not .Values.secretKeys.existingSecret) }}{{ $_ := set $data "secret-keys" .Values.secretKeys.value }}{{ end -}} {{- if and .Values.database.url (not .Values.database.existingSecret) (not .Values.database.bundled.enabled) }}{{ $_ := set $data "database-url" .Values.database.url }}{{ end -}} -{{- if and .Values.redis.url (not .Values.redis.existingSecret) }}{{ $_ := set $data "redis-url" .Values.redis.url }}{{ end -}} +{{- if and .Values.redis.url (not .Values.redis.existingSecret) (not .Values.redis.bundled.enabled) }}{{ $_ := set $data "redis-url" .Values.redis.url }}{{ end -}} {{- if and .Values.redis.sentinel.password (not .Values.redis.sentinel.existingSecret) }}{{ $_ := set $data "redis-sentinel-password" .Values.redis.sentinel.password }}{{ end -}} {{- if and .Values.smtp.url (not .Values.smtp.existingSecret) }}{{ $_ := set $data "smtp-url" .Values.smtp.url }}{{ end -}} {{- if and .Values.checker.token (not .Values.checker.existingSecret) }}{{ $_ := set $data "checker-token" .Values.checker.token }}{{ end -}} @@ -124,7 +124,15 @@ $secret being the chart secret to read values from. {{- else }} {{ include "uptimesebi.secretEnv" (list $secret "UPTIME_DATABASE_URL" .Values.database.existingSecret .Values.database.existingSecretKey "database-url") }} {{- end }} -{{- if .Values.redis.sentinel.master }} +{{- if .Values.redis.bundled.enabled }} +- name: UPTIME_REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: {{ include "uptimesebi.fullname" . }}-redis + key: password +- name: UPTIME_REDIS_URL + value: {{ printf "redis://:$(UPTIME_REDIS_PASSWORD)@%s-redis:6379/0" (include "uptimesebi.fullname" .) | quote }} +{{- else if .Values.redis.sentinel.master }} - name: UPTIME_REDIS_SENTINEL_MASTER value: {{ .Values.redis.sentinel.master | quote }} - name: UPTIME_REDIS_SENTINEL_ADDRS @@ -139,7 +147,7 @@ $secret being the chart secret to read values from. {{- else if or .Values.redis.url .Values.redis.existingSecret }} {{ include "uptimesebi.secretEnv" (list $secret "UPTIME_REDIS_URL" .Values.redis.existingSecret .Values.redis.existingSecretKey "redis-url") }} {{- else }} -{{- fail "set redis.url, redis.existingSecret or redis.sentinel.master: Redis is not bundled" }} +{{- fail "set redis.url, redis.existingSecret, redis.sentinel.master or redis.bundled.enabled" }} {{- end }} {{- if or .Values.secretKeys.value .Values.secretKeys.existingSecret }} {{ include "uptimesebi.secretEnv" (list $secret "UPTIME_SECRET_KEYS" .Values.secretKeys.existingSecret .Values.secretKeys.existingSecretKey "secret-keys") }} diff --git a/deploy/helm/uptimesebi/templates/redis.yaml b/deploy/helm/uptimesebi/templates/redis.yaml new file mode 100644 index 0000000..64a3cfd --- /dev/null +++ b/deploy/helm/uptimesebi/templates/redis.yaml @@ -0,0 +1,122 @@ +{{- if .Values.redis.bundled.enabled }} +{{- $name := printf "%s-redis" (include "uptimesebi.fullname" .) }} +{{- $existing := lookup "v1" "Secret" .Release.Namespace $name }} +{{- $password := .Values.redis.bundled.password }} +{{- if and (not $password) $existing }}{{ $password = index $existing.data "password" | b64dec }}{{ end }} +{{- if not $password }}{{ $password = randAlphaNum 32 }}{{ end }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ $name }} + labels: + {{- include "uptimesebi.labels" . | nindent 4 }} + app.kubernetes.io/component: redis + annotations: + # Uninstalling keeps the password along with the kept volume. + helm.sh/resource-policy: keep +type: Opaque +stringData: + password: {{ $password | quote }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $name }} + labels: + {{- include "uptimesebi.labels" . | nindent 4 }} + app.kubernetes.io/component: redis +spec: + selector: + {{- include "uptimesebi.selector" (list . "redis") | nindent 4 }} + ports: + - name: redis + port: 6379 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ $name }} + labels: + {{- include "uptimesebi.labels" . | nindent 4 }} + app.kubernetes.io/component: redis +spec: + serviceName: {{ $name }} + replicas: 1 + selector: + matchLabels: + {{- include "uptimesebi.selector" (list . "redis") | nindent 6 }} + template: + metadata: + labels: + {{- include "uptimesebi.selector" (list . "redis") | nindent 8 }} + spec: + automountServiceAccountToken: false + securityContext: + runAsNonRoot: true + runAsUser: 999 + runAsGroup: 999 + fsGroup: 999 + seccompProfile: + type: RuntimeDefault + containers: + - name: redis + image: {{ printf "%s:%s" .Values.redis.bundled.image.repository .Values.redis.bundled.image.tag }} + command: [redis-server] + args: + - --requirepass + - $(REDIS_PASSWORD) + - --appendonly + - {{ ternary "yes" "no" .Values.redis.bundled.persistence.enabled | quote }} + - --save + - "" + env: + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: {{ $name }} + key: password + - name: REDISCLI_AUTH + valueFrom: + secretKeyRef: + name: {{ $name }} + key: password + ports: + - name: redis + containerPort: 6379 + readinessProbe: + exec: + command: [redis-cli, ping] + periodSeconds: 5 + livenessProbe: + tcpSocket: + port: redis + periodSeconds: 20 + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + resources: + {{- toYaml .Values.redis.bundled.resources | nindent 12 }} + volumeMounts: + - name: data + mountPath: /data + {{- if not .Values.redis.bundled.persistence.enabled }} + volumes: + - name: data + emptyDir: {} + {{- end }} + {{- if .Values.redis.bundled.persistence.enabled }} + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: [ReadWriteOnce] + {{- with .Values.redis.bundled.persistence.storageClass }} + storageClassName: {{ . }} + {{- end }} + resources: + requests: + storage: {{ .Values.redis.bundled.persistence.size }} + {{- end }} +{{- end }} diff --git a/deploy/helm/uptimesebi/values.yaml b/deploy/helm/uptimesebi/values.yaml index b54a8b9..a5383ed 100644 --- a/deploy/helm/uptimesebi/values.yaml +++ b/deploy/helm/uptimesebi/values.yaml @@ -68,7 +68,7 @@ database: resources: {} # -- Redis -- -# Redis is not bundled: point to your own, directly or through Sentinel. +# Point to your own Redis, directly or through Sentinel, or bundle one. redis: # redis://:password@host:6379/0 or rediss:// for TLS. @@ -82,6 +82,23 @@ redis: password: "" existingSecret: "" existingSecretKey: redis-sentinel-password + # A single Redis in the cluster, for trying UptimeSebi out. Without high + # availability: for production use your own Redis. + bundled: + enabled: false + image: + repository: redis + tag: 8-alpine + # Generated on install if empty, then kept; letters and digits only, + # it goes into a URL. + password: "" + # Sessions, schedules and rate limits survive restarts on a volume; + # without one a restart signs everyone out. + persistence: + enabled: true + size: 1Gi + storageClass: "" + resources: {} # -- Migrations --