Skip to content

Commit

Permalink
Add storage for Prometheus using a PersistentVolumeClaim
Browse files Browse the repository at this point in the history
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) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Aug 29, 2024
1 parent fe581ba commit 5bd01c2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
13 changes: 12 additions & 1 deletion chart/openfaas/templates/prometheus-dep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
28 changes: 28 additions & 0 deletions chart/openfaas/templates/prometheus-pvc.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
50 changes: 34 additions & 16 deletions chart/openfaas/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 5bd01c2

Please sign in to comment.