From 5bd01c267635f88d3745999a94565e86aa4b72fc Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Thu, 29 Aug 2024 17:16:02 +0100 Subject: [PATCH] Add storage for Prometheus using a PersistentVolumeClaim Prior to this change, Prometheus' timeseries data would be lost whenever the chart was upgraded, the Prometheus Pod was rescheduled, or restarted due to a configuration change. Tested with a blank storageClassName with KinD, and the local path provisioner. After creating load with hey, and restarting Prometheus, the invocation metrics remained available. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- chart/openfaas/templates/prometheus-dep.yaml | 13 ++++- chart/openfaas/templates/prometheus-pvc.yaml | 28 +++++++++++ chart/openfaas/values.yaml | 50 +++++++++++++------- 3 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 chart/openfaas/templates/prometheus-pvc.yaml diff --git a/chart/openfaas/templates/prometheus-dep.yaml b/chart/openfaas/templates/prometheus-dep.yaml index a227ee431..5a5c7f573 100644 --- a/chart/openfaas/templates/prometheus-dep.yaml +++ b/chart/openfaas/templates/prometheus-dep.yaml @@ -119,8 +119,19 @@ spec: path: prometheus-rules.yml mode: 0644 {{- end }} + +{{- if .Values.prometheus.pvc.enabled }} - name: prom-data - emptyDir: {} + persistentVolumeClaim: + {{- if .Values.prometheus.pvc.name }} + claimName: {{.Values.prometheus.pvc.name}} + {{- else }} + claimName: prometheus-data + {{- end }} +{{- else }} + +{{- end }} + {{- with .Values.nodeSelector }} nodeSelector: {{ toYaml . | indent 8 }} diff --git a/chart/openfaas/templates/prometheus-pvc.yaml b/chart/openfaas/templates/prometheus-pvc.yaml new file mode 100644 index 000000000..730c5466a --- /dev/null +++ b/chart/openfaas/templates/prometheus-pvc.yaml @@ -0,0 +1,28 @@ +{{- $functionNs := default .Release.Namespace .Values.functionNamespace }} +{{- if and .Values.prometheus.create .Values.prometheus.pvc.enabled }} +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + labels: + app: {{ template "openfaas.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version }} + component: prometheus + heritage: {{ .Release.Service }} + release: {{ .Release.Name }} +{{- if .Values.prometheus.pvc.name }} + name: {{.Values.prometheus.pvc.name}} +{{- else }} + name: prometheus-data +{{- end }} + namespace: {{ .Release.Namespace | quote }} +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .Values.prometheus.pvc.size | quote }} + {{- with .Values.prometheus.pvc.storageClassName }} + storageClassName: {{ . | quote }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/chart/openfaas/values.yaml b/chart/openfaas/values.yaml index 014f40fd4..7c726b813 100644 --- a/chart/openfaas/values.yaml +++ b/chart/openfaas/values.yaml @@ -359,6 +359,11 @@ iam: url: https://kubernetes.default.svc.cluster.local tokenExpiry: 2h +## Prometheus is required for metrics and autoscaling +## +## It is bundled into OpenFaaS to be used only as an internal component +## if you wish to retain the metrics for a longer period, you should +## scrape this instance from an external Prometheus server prometheus: image: prom/prometheus:v2.54.0 create: true @@ -371,22 +376,19 @@ prometheus: annotations: {} recordingRules: [] -alertmanager: - image: prom/alertmanager:v0.27.0 - create: true - resources: - requests: - memory: "25Mi" - cpu: "50m" - limits: - memory: "50Mi" - -stan: - # Image used for the NATS Streaming when using the deprecated - # support in the Community Edition (CE) - image: nats-streaming:0.25.6 - -# NATS (required for async) + # Set to true to enable persistent storage for the Prometheus Pod + # otherwise, the data will be lost when the Pod is restarted + pvc: + enabled: false + # You may want to set this higher for production + size: 10Gi + # Leave the storageClassName blank for the default storage class + # using the string "default" does not necessarily mean the default + # storage class + storageClassName: + +## NATS is used for OpenFaaS Pro and is required for: +## asynchronous invocations, billing & auditing webhooks nats: channel: "faas-request" # Stream replication is set to 1 by default. This is only recommended for development. @@ -405,6 +407,22 @@ nats: memory: "120Mi" cpu: "100m" +## alertmanager is only used for OpenFaaS CE +alertmanager: + image: prom/alertmanager:v0.27.0 + create: true + resources: + requests: + memory: "25Mi" + cpu: "50m" + limits: + memory: "50Mi" + +## stan is only used for OpenFaaS CE and will be removed in +## a fture release, having already been deprecated by the NATS team +stan: + image: nats-streaming:0.25.6 + # ingress configuration ingress: enabled: false