Skip to content

Commit a854829

Browse files
committed
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. The name of the pvc can also be set, however this is not documented in values.yaml, this may be required for multiple installations of OpenFaaS within the same cluster for testing purposes. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent fe581ba commit a854829

File tree

4 files changed

+84
-18
lines changed

4 files changed

+84
-18
lines changed

chart/openfaas/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ For legacy scaling in OpenFaaS Community Edition.
680680
| ----------------------- | ---------------------------------- | ---------------------------------------------------------- |
681681
| `alertmanager.create` | Create the AlertManager component | `true` |
682682
| `alertmanager.image` | Container image used for alertmanager | See [values.yaml](./values.yaml) |
683-
| `alertmanager.resources` | Resource limits and requests for alertmanager pods | See [values.yaml](./values.
684-
683+
| `alertmanager.resources` | Resource limits and requests for alertmanager pods | See [values.yaml](./values.yaml) |
685684

686685
### Prometheus (built-in, for autoscaling and metrics)
687686

@@ -693,3 +692,8 @@ For legacy scaling in OpenFaaS Community Edition.
693692
| `prometheus.retention.size` | The maximum number of bytes of storage blocks to retain. Units supported: B, KB, MB, GB, TB, PB, EB. 0 meaning disabled. See: [Prometheus storage](https://prometheus.io/docs/prometheus/latest/storage/#operational-aspects)| `0` |
694693
| `prometheus.resources` | Resource limits and requests for prometheus containers | See [values.yaml](./values.yaml) |
695694
| `prometheus.recordingRules` | Custom recording rules for autoscaling. | `[]` |
695+
| `prometheus.pvc` | Persistent volume claim for Prometheus used so that metrics survive restarts of the Pod and upgrades of the chart | `{}` |
696+
| `prometheus.pvc.enabled` | Enable persistent volume claim for Prometheus | `false` |
697+
| `prometheus.pvc.storageClassName` | Storage class for Prometheus PVC, set to `""` for the default/standard class to be picked | `""` |
698+
| `prometheus.pvc.size` | Size of the Prometheus PVC, 60-100Gi may be a better fit for a busy production environment | `10Gi` |
699+
| `prometheus.pvc.name` | Name of the Prometheus PVC, required for multiple installations within the same cluster | `""` |

chart/openfaas/templates/prometheus-dep.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ metadata:
1414
namespace: {{ .Release.Namespace | quote }}
1515
spec:
1616
replicas: 1
17+
strategy:
18+
type: Recreate
1719
selector:
1820
matchLabels:
1921
app: prometheus
@@ -119,8 +121,20 @@ spec:
119121
path: prometheus-rules.yml
120122
mode: 0644
121123
{{- end }}
124+
125+
{{- if and .Values.prometheus.pvc.enabled .Values.openfaasPro }}
126+
- name: prom-data
127+
persistentVolumeClaim:
128+
{{- if .Values.prometheus.pvc.name }}
129+
claimName: {{.Values.prometheus.pvc.name}}
130+
{{- else }}
131+
claimName: prometheus-data
132+
{{- end }}
133+
{{- else }}
122134
- name: prom-data
123135
emptyDir: {}
136+
{{- end }}
137+
124138
{{- with .Values.nodeSelector }}
125139
nodeSelector:
126140
{{ toYaml . | indent 8 }}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{- $functionNs := default .Release.Namespace .Values.functionNamespace }}
2+
{{- if .Values.openfaasPro }}
3+
{{- if and .Values.prometheus.create .Values.prometheus.pvc.enabled }}
4+
---
5+
apiVersion: v1
6+
kind: PersistentVolumeClaim
7+
metadata:
8+
labels:
9+
app: {{ template "openfaas.name" . }}
10+
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
11+
component: prometheus
12+
heritage: {{ .Release.Service }}
13+
release: {{ .Release.Name }}
14+
{{- if .Values.prometheus.pvc.name }}
15+
name: {{.Values.prometheus.pvc.name}}
16+
{{- else }}
17+
name: prometheus-data
18+
{{- end }}
19+
namespace: {{ .Release.Namespace | quote }}
20+
spec:
21+
accessModes:
22+
- ReadWriteOnce
23+
resources:
24+
requests:
25+
storage: {{ .Values.prometheus.pvc.size | quote }}
26+
{{- with .Values.prometheus.pvc.storageClassName }}
27+
storageClassName: {{ . | quote }}
28+
{{- end }}
29+
{{- end }}
30+
{{- end }}

chart/openfaas/values.yaml

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,11 @@ iam:
359359
url: https://kubernetes.default.svc.cluster.local
360360
tokenExpiry: 2h
361361

362+
## Prometheus is required for metrics and autoscaling
363+
##
364+
## It is bundled into OpenFaaS to be used only as an internal component
365+
## if you wish to retain the metrics for a longer period, you should
366+
## scrape this instance from an external Prometheus server
362367
prometheus:
363368
image: prom/prometheus:v2.54.0
364369
create: true
@@ -371,22 +376,19 @@ prometheus:
371376
annotations: {}
372377
recordingRules: []
373378

374-
alertmanager:
375-
image: prom/alertmanager:v0.27.0
376-
create: true
377-
resources:
378-
requests:
379-
memory: "25Mi"
380-
cpu: "50m"
381-
limits:
382-
memory: "50Mi"
383-
384-
stan:
385-
# Image used for the NATS Streaming when using the deprecated
386-
# support in the Community Edition (CE)
387-
image: nats-streaming:0.25.6
388-
389-
# NATS (required for async)
379+
# Set to true to enable persistent storage for the Prometheus Pod
380+
# otherwise, the data will be lost when the Pod is restarted
381+
pvc:
382+
enabled: false
383+
# You may want to set this higher for production, or lower for development/staging.
384+
size: 30Gi
385+
# Leave the storageClassName blank for the default storage class
386+
# using the string "default" does not necessarily mean the default
387+
# storage class
388+
storageClassName:
389+
390+
## NATS is used for OpenFaaS Pro and is required for:
391+
## asynchronous invocations, billing & auditing webhooks
390392
nats:
391393
channel: "faas-request"
392394
# Stream replication is set to 1 by default. This is only recommended for development.
@@ -405,6 +407,22 @@ nats:
405407
memory: "120Mi"
406408
cpu: "100m"
407409

410+
## alertmanager is only used for OpenFaaS CE
411+
alertmanager:
412+
image: prom/alertmanager:v0.27.0
413+
create: true
414+
resources:
415+
requests:
416+
memory: "25Mi"
417+
cpu: "50m"
418+
limits:
419+
memory: "50Mi"
420+
421+
## stan is only used for OpenFaaS CE and will be removed in
422+
## a fture release, having already been deprecated by the NATS team
423+
stan:
424+
image: nats-streaming:0.25.6
425+
408426
# ingress configuration
409427
ingress:
410428
enabled: false

0 commit comments

Comments
 (0)