This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hertzbeat-helm-chart.git
The following commit(s) were added to refs/heads/main by this push:
new d182542 Feat(helm): add support for external database with Kubernetes
secrets integration (#21)
d182542 is described below
commit d182542771a653d6342b302c0f732abbd5c78f07
Author: caio.imperial <[email protected]>
AuthorDate: Mon Aug 17 03:56:22 2026 -0300
Feat(helm): add support for external database with Kubernetes secrets
integration (#21)
* feat(helm): add external database support
* docs(helm): update database configuration defaults and add external
database parameters
* feat(helm): add secret-based external database configuration
* feat(helm): refactor database configuration helpers
---
charts/hertzbeat/README.md | 21 ++++++---
charts/hertzbeat/templates/_helpers.tpl | 51 ++++++++++++++++++++++
charts/hertzbeat/templates/database/configmap.yaml | 4 ++
charts/hertzbeat/templates/database/pvc.yaml | 4 +-
charts/hertzbeat/templates/database/service.yaml | 4 ++
.../hertzbeat/templates/database/statefulset.yaml | 4 ++
charts/hertzbeat/templates/manager/configmap.yaml | 6 +--
charts/hertzbeat/templates/manager/deployment.yaml | 36 +++++++++++++++
charts/hertzbeat/values.yaml | 32 ++++++++++++++
9 files changed, 153 insertions(+), 9 deletions(-)
diff --git a/charts/hertzbeat/README.md b/charts/hertzbeat/README.md
index 94ea620..93aa84d 100644
--- a/charts/hertzbeat/README.md
+++ b/charts/hertzbeat/README.md
@@ -123,30 +123,41 @@ Config Parameter via `--set`, eg: `--set
expose.type=NodePort`
| `collector.affinity` | Node/Pod affinities
| `{}` |
| `collector.podAnnotations` | Annotations to add to the nginx pod
| `{}` |
| **Database** |
| |
-| `database.timezone` | The database system timezone
| `1` |
-| `database.rootPassword` | The database root user password
| `1` |
+| `database.timezone` | The database system timezone
| `Asia/Shanghai` |
+| `database.rootPassword` | The database root user password
| `123456` |
| `database.persistence.enabled` | Enable the data persistence or not
| `true` |
| `database.persistence.resourcePolicy` | Setting it to `keep` to avoid
removing PVCs during a helm delete operation. Leaving it empty will delete PVCs
after the chart deleted. Does not affect PVCs created for internal database and
redis components. | `keep` |
| `database.persistence.existingClaim` | Use the existing PVC which must be
created manually before bound, and specify the `subPath` if the PVC is shared
with other components
| |
| `database.persistence.storageClass` | Specify the `storageClass` used to
provision the volume. Or the default StorageClass will be used (the default).
Set it to `-` to disable dynamic provisioning
| |
| `database.persistence.subPath` | The sub path used in the volume
| |
| `database.persistence.accessMode` | The access mode of the volume
| `ReadWriteOnce` |
-| `database.persistence.size` | The size of the volume
| `5Gi` |
+| `database.persistence.size` | The size of the volume
| `4Gi` |
| `database.persistence.annotations` | The annotations of the volume
| |
| `database.resources` | The [resources] to allocate for
container
| undefined |
| `database.nodeSelector` | Node labels for pod assignment
| `{}` |
| `database.tolerations` | Tolerations for pod assignment
| `[]` |
| `database.affinity` | Node/Pod affinities
| `{}` |
| `database.podAnnotations` | Annotations to add to the nginx pod
| `{}` |
+| **External Database** |
| |
+| `database.external.host.value` | External PostgreSQL host (direct
value). Set to use external database.
| `""` |
+| `database.external.host.valueFrom` | External PostgreSQL host via Secret.
Use `valueFrom.secretKeyRef.name` and `key`.
| `{}` |
+| `database.external.port.value` | External PostgreSQL port (direct
value).
| `5432` |
+| `database.external.port.valueFrom` | External PostgreSQL port via Secret.
| `{}` |
+| `database.external.username.value` | External PostgreSQL username (direct
value).
| `root` |
+| `database.external.username.valueFrom` | External PostgreSQL username via
Secret.
| `{}` |
+| `database.external.password.value` | External PostgreSQL password (direct
value).
| `""` |
+| `database.external.password.valueFrom` | External PostgreSQL password via
Secret.
| `{}` |
+| `database.external.database.value` | External PostgreSQL database name
(direct value).
| `hertzbeat` |
+| `database.external.database.valueFrom` | External PostgreSQL database name
via Secret.
| `{}` |
| **TSDB** |
| |
-| `tsdb.timezone` | The database system timezone
| `1` |
+| `tsdb.timezone` | The database system timezone
| `Asia/Shanghai` |
| `tsdb.persistence.enabled` | Enable the data persistence or not
| `true` |
| `tsdb.persistence.resourcePolicy` | Setting it to `keep` to avoid
removing PVCs during a helm delete operation. Leaving it empty will delete PVCs
after the chart deleted. Does not affect PVCs created for internal database and
redis components. | `keep` |
| `tsdb.persistence.existingClaim` | Use the existing PVC which must be
created manually before bound, and specify the `subPath` if the PVC is shared
with other components
| |
| `tsdb.persistence.storageClass` | Specify the `storageClass` used to
provision the volume. Or the default StorageClass will be used (the default).
Set it to `-` to disable dynamic provisioning
| |
| `tsdb.persistence.subPath` | The sub path used in the volume
| |
| `tsdb.persistence.accessMode` | The access mode of the volume
| `ReadWriteOnce` |
-| `tsdb.persistence.size` | The size of the volume
| `5Gi` |
+| `tsdb.persistence.size` | The size of the volume
| `4Gi` |
| `tsdb.persistence.annotations` | The annotations of the volume
| |
| `tsdb.resources` | The [resources] to allocate for
container
| undefined |
| `tsdb.nodeSelector` | Node labels for pod assignment
| `{}` |
diff --git a/charts/hertzbeat/templates/_helpers.tpl
b/charts/hertzbeat/templates/_helpers.tpl
index 4b64c3a..24c0664 100644
--- a/charts/hertzbeat/templates/_helpers.tpl
+++ b/charts/hertzbeat/templates/_helpers.tpl
@@ -65,3 +65,54 @@ Selector labels
app.kubernetes.io/name: {{ include "hertzbeat.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
+
+{{/*
+Database helper functions - simplifies external database configuration
+*/}}
+{{- define "hertzbeat.db.isExternal" -}}
+{{- $hostValue := .Values.database.external.host.value | default "" -}}
+{{- $hostFrom := .Values.database.external.host.valueFrom.secretKeyRef.key |
default "" -}}
+{{- or $hostValue $hostFrom -}}
+{{- end -}}
+
+{{- define "hertzbeat.db.username" -}}
+{{- if include "hertzbeat.db.isExternal" . -}}
+{{- $usernameFrom :=
.Values.database.external.username.valueFrom.secretKeyRef.key | default "" -}}
+{{- if $usernameFrom -}}
+${DATABASE_USERNAME}
+{{- else -}}
+{{- .Values.database.external.username.value | default "root" -}}
+{{- end -}}
+{{- else -}}
+root
+{{- end -}}
+{{- end -}}
+
+{{- define "hertzbeat.db.password" -}}
+{{- if include "hertzbeat.db.isExternal" . -}}
+{{- $passwordFrom :=
.Values.database.external.password.valueFrom.secretKeyRef.key | default "" -}}
+{{- if $passwordFrom -}}
+${DATABASE_PASSWORD}
+{{- else -}}
+{{- .Values.database.external.password.value | default "" -}}
+{{- end -}}
+{{- else -}}
+{{- .Values.database.rootPassword -}}
+{{- end -}}
+{{- end -}}
+
+{{- define "hertzbeat.db.url" -}}
+{{- if include "hertzbeat.db.isExternal" . -}}
+{{- $hostValue := .Values.database.external.host.value | default "" -}}
+{{- $hostFrom := .Values.database.external.host.valueFrom.secretKeyRef.key |
default "" -}}
+{{- $databaseValue := .Values.database.external.database.value | default
"hertzbeat" -}}
+{{- $portValue := .Values.database.external.port.value | default 5432 -}}
+{{- if $hostValue -}}
+jdbc:postgresql://{{ $hostValue }}:{{ $portValue }}/{{ $databaseValue }}
+{{- else -}}
+jdbc:postgresql://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}
+{{- end -}}
+{{- else -}}
+jdbc:postgresql://{{ include "hertzbeat.database" . }}:5432/hertzbeat
+{{- end -}}
+{{- end -}}
diff --git a/charts/hertzbeat/templates/database/configmap.yaml
b/charts/hertzbeat/templates/database/configmap.yaml
index 4c9c3e9..c281866 100644
--- a/charts/hertzbeat/templates/database/configmap.yaml
+++ b/charts/hertzbeat/templates/database/configmap.yaml
@@ -15,6 +15,9 @@
# specific language governing permissions and limitations
# under the License.
+{{- $externalHostValue := .Values.database.external.host.value | default "" -}}
+{{- $externalHostFrom :=
.Values.database.external.host.valueFrom.secretKeyRef.key | default "" -}}
+{{- if not (or $externalHostValue $externalHostFrom) }}
apiVersion: v1
kind: ConfigMap
metadata:
@@ -34,3 +37,4 @@ data:
EXCEPTION WHEN duplicate_database THEN RAISE NOTICE '%, skipping', SQLERRM
USING ERRCODE = SQLSTATE;
END
$$;
+{{- end }}
diff --git a/charts/hertzbeat/templates/database/pvc.yaml
b/charts/hertzbeat/templates/database/pvc.yaml
index 69f6ad4..51e318e 100644
--- a/charts/hertzbeat/templates/database/pvc.yaml
+++ b/charts/hertzbeat/templates/database/pvc.yaml
@@ -15,7 +15,9 @@
# specific language governing permissions and limitations
# under the License.
-{{- if .Values.database.persistence.enabled }}
+{{- $externalHostValue := .Values.database.external.host.value | default "" -}}
+{{- $externalHostFrom :=
.Values.database.external.host.valueFrom.secretKeyRef.key | default "" -}}
+{{- if and .Values.database.persistence.enabled (not (or $externalHostValue
$externalHostFrom)) }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
diff --git a/charts/hertzbeat/templates/database/service.yaml
b/charts/hertzbeat/templates/database/service.yaml
index e95d860..a12a801 100644
--- a/charts/hertzbeat/templates/database/service.yaml
+++ b/charts/hertzbeat/templates/database/service.yaml
@@ -15,6 +15,9 @@
# specific language governing permissions and limitations
# under the License.
+{{- $externalHostValue := .Values.database.external.host.value | default "" -}}
+{{- $externalHostFrom :=
.Values.database.external.host.valueFrom.secretKeyRef.key | default "" -}}
+{{- if not (or $externalHostValue $externalHostFrom) }}
apiVersion: v1
kind: Service
metadata:
@@ -30,3 +33,4 @@ spec:
selector:
{{- include "hertzbeat.selectorLabels" . | nindent 4 }}
component: database
+{{- end }}
diff --git a/charts/hertzbeat/templates/database/statefulset.yaml
b/charts/hertzbeat/templates/database/statefulset.yaml
index e446d5d..739a4d1 100644
--- a/charts/hertzbeat/templates/database/statefulset.yaml
+++ b/charts/hertzbeat/templates/database/statefulset.yaml
@@ -15,6 +15,9 @@
# specific language governing permissions and limitations
# under the License.
+{{- $externalHostValue := .Values.database.external.host.value | default "" -}}
+{{- $externalHostFrom :=
.Values.database.external.host.valueFrom.secretKeyRef.key | default "" -}}
+{{- if not (or $externalHostValue $externalHostFrom) }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
@@ -114,3 +117,4 @@ spec:
{{/* requests:*/}}
{{/* storage: {{ .Values.database.persistence.size | quote }}*/}}
{{/* {{- end -}}*/}}
+{{- end }}
diff --git a/charts/hertzbeat/templates/manager/configmap.yaml
b/charts/hertzbeat/templates/manager/configmap.yaml
index b3914d1..b4479a2 100644
--- a/charts/hertzbeat/templates/manager/configmap.yaml
+++ b/charts/hertzbeat/templates/manager/configmap.yaml
@@ -97,9 +97,9 @@ data:
datasource:
driver-class-name: org.postgresql.Driver
- username: root
- password: {{ .Values.database.rootPassword }}
- url: jdbc:postgresql://{{ include "hertzbeat.database" .
}}:5432/hertzbeat
+ username: {{ include "hertzbeat.db.username" . }}
+ password: {{ include "hertzbeat.db.password" . }}
+ url: {{ include "hertzbeat.db.url" . }}
hikari:
max-lifetime: 120000
jpa:
diff --git a/charts/hertzbeat/templates/manager/deployment.yaml
b/charts/hertzbeat/templates/manager/deployment.yaml
index 346fad1..b9afaf9 100644
--- a/charts/hertzbeat/templates/manager/deployment.yaml
+++ b/charts/hertzbeat/templates/manager/deployment.yaml
@@ -73,6 +73,42 @@ spec:
name: sureness
resources:
{{- toYaml .Values.manager.resources | nindent 12 }}
+ env:
+ {{- if .Values.database.external.host.valueFrom.secretKeyRef.key }}
+ - name: DATABASE_HOST
+ valueFrom:
+ secretKeyRef:
+ name: {{
.Values.database.external.host.valueFrom.secretKeyRef.name }}
+ key: {{
.Values.database.external.host.valueFrom.secretKeyRef.key }}
+ {{- end }}
+ {{- if .Values.database.external.port.valueFrom.secretKeyRef.key }}
+ - name: DATABASE_PORT
+ valueFrom:
+ secretKeyRef:
+ name: {{
.Values.database.external.port.valueFrom.secretKeyRef.name }}
+ key: {{
.Values.database.external.port.valueFrom.secretKeyRef.key }}
+ {{- end }}
+ {{- if
.Values.database.external.username.valueFrom.secretKeyRef.key }}
+ - name: DATABASE_USERNAME
+ valueFrom:
+ secretKeyRef:
+ name: {{
.Values.database.external.username.valueFrom.secretKeyRef.name }}
+ key: {{
.Values.database.external.username.valueFrom.secretKeyRef.key }}
+ {{- end }}
+ {{- if
.Values.database.external.password.valueFrom.secretKeyRef.key }}
+ - name: DATABASE_PASSWORD
+ valueFrom:
+ secretKeyRef:
+ name: {{
.Values.database.external.password.valueFrom.secretKeyRef.name }}
+ key: {{
.Values.database.external.password.valueFrom.secretKeyRef.key }}
+ {{- end }}
+ {{- if
.Values.database.external.database.valueFrom.secretKeyRef.key }}
+ - name: DATABASE_NAME
+ valueFrom:
+ secretKeyRef:
+ name: {{
.Values.database.external.database.valueFrom.secretKeyRef.name }}
+ key: {{
.Values.database.external.database.valueFrom.secretKeyRef.key }}
+ {{- end }}
volumes:
- name: application
configMap:
diff --git a/charts/hertzbeat/values.yaml b/charts/hertzbeat/values.yaml
index 6614c0b..0474755 100644
--- a/charts/hertzbeat/values.yaml
+++ b/charts/hertzbeat/values.yaml
@@ -86,6 +86,38 @@ database:
tolerations: []
affinity: {}
+ external:
+ host:
+ value: ""
+ valueFrom:
+ secretKeyRef:
+ name: hertzbeat-secret
+ key: ""
+ port:
+ value: 5432
+ valueFrom:
+ secretKeyRef:
+ name: hertzbeat-secret
+ key: ""
+ username:
+ value: "root"
+ valueFrom:
+ secretKeyRef:
+ name: hertzbeat-secret
+ key: ""
+ password:
+ value: ""
+ valueFrom:
+ secretKeyRef:
+ name: hertzbeat-secret
+ key: ""
+ database:
+ value: "hertzbeat"
+ valueFrom:
+ secretKeyRef:
+ name: hertzbeat-secret
+ key: ""
+
tsdb:
image:
repository: victoriametrics/victoria-metrics
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]