From 0374372baea59356b08d8d9bb5d699d133353965 Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Wed, 21 Dec 2016 20:31:05 +0100 Subject: [PATCH] postgresql: optional prometheus metrics exporter (#260) * postgresql: optional prometheus metrics exporter * split metrics.image into image and imageTag * bump postgresql chart to 0.3.0 * Adding myself as maintainer for the postgresql chart --- stable/postgresql/Chart.yaml | 3 ++- stable/postgresql/README.md | 8 ++++++++ stable/postgresql/templates/deployment.yaml | 13 +++++++++++++ stable/postgresql/templates/svc.yaml | 5 +++++ stable/postgresql/values.yaml | 10 ++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/stable/postgresql/Chart.yaml b/stable/postgresql/Chart.yaml index 3a3fecdaa6..ce394deb84 100644 --- a/stable/postgresql/Chart.yaml +++ b/stable/postgresql/Chart.yaml @@ -1,5 +1,5 @@ name: postgresql -version: 0.2.2 +version: 0.3.0 description: Chart for PostgreSQL keywords: - postgresql @@ -12,4 +12,5 @@ sources: - https://github.com/docker-library/postgres maintainers: - name: swordbeta +- name: databus23 engine: gotpl diff --git a/stable/postgresql/README.md b/stable/postgresql/README.md index 44c5edd852..f70aad3bb9 100644 --- a/stable/postgresql/README.md +++ b/stable/postgresql/README.md @@ -56,6 +56,11 @@ The following tables lists the configurable parameters of the PostgresSQL chart | `persistence.accessMode` | Use volume as ReadOnly or ReadWrite | `ReadWriteOnce` | | `persistence.size` | Size of data volume | `8Gi` | | `resources` | CPU/Memory resource requests/limits | Memory: `256Mi`, CPU: `100m` | +| `metrics.enabled` | Start a side-car prometheus exporter | `false` | +| `metrics.image` | Exporter image | `wrouesnel/postgres_exporter` | +| `metrics.imageTag` | Exporter image | `v0.1.1` | +| `metrics.imagePullPolicy` | Exporter image pull policy | `IfNotPresent` | +| `metrics.resources` | Exporter resource requests/limit | Memory: `256Mi`, CPU: `100m` | The above parameters map to the env variables defined in [postgres](http://github.com/docker-library/postgres). For more information please refer to the [postgres](http://github.com/docker-library/postgres) image documentation. @@ -82,3 +87,6 @@ $ helm install --name my-release -f values.yaml stable/postgresql The [postgres](https://github.com/docker-library/postgres) image stores the PostgreSQL data and configurations at the `/var/lib/postgresql/data/pgdata` path of the container. The chart mounts a [Persistent Volume](http://kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning. + +## Metrics +The chart optionally can start a metrics exporter for [prometheus](https://prometheus.io). The metrics endpoint (port 9187) is not exposed and it is expected that the metrics are collected from inside the k8s cluster using something similar as the described in the [example Prometheus scrape configuration](https://github.com/prometheus/prometheus/blob/master/documentation/examples/prometheus-kubernetes.yml). diff --git a/stable/postgresql/templates/deployment.yaml b/stable/postgresql/templates/deployment.yaml index 2ab56a68d0..8b091ee5d7 100644 --- a/stable/postgresql/templates/deployment.yaml +++ b/stable/postgresql/templates/deployment.yaml @@ -67,6 +67,19 @@ spec: volumeMounts: - name: data mountPath: /var/lib/postgresql/data/pgdata +{{- if .Values.metrics.enabled }} + - name: metrics + image: "{{ .Values.metrics.image }}:{{ .Values.metrics.imageTag }}" + imagePullPolicy: {{ default "" .Values.metrics.imagePullPolicy | quote }} + env: + - name: DATA_SOURCE_NAME + value: postgresql://postgres@localhost:5432?sslmode=disable + ports: + - name: metrics + containerPort: 9187 + resources: +{{ toYaml .Values.metrics.resources | indent 10 }} +{{- end }} volumes: - name: data {{- if .Values.persistence.enabled }} diff --git a/stable/postgresql/templates/svc.yaml b/stable/postgresql/templates/svc.yaml index 789e1a152e..5052d07ea9 100644 --- a/stable/postgresql/templates/svc.yaml +++ b/stable/postgresql/templates/svc.yaml @@ -7,6 +7,11 @@ metadata: chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" +{{- if .Values.metrics.enabled }} + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9187" +{{- end }} spec: ports: - name: postgresql diff --git a/stable/postgresql/values.yaml b/stable/postgresql/values.yaml index 96fd9ae6dc..0873307130 100644 --- a/stable/postgresql/values.yaml +++ b/stable/postgresql/values.yaml @@ -28,6 +28,16 @@ persistence: accessMode: ReadWriteOnce size: 8Gi +metrics: + enabled: false + image: wrouesnel/postgres_exporter + imageTag: v0.1.1 + imagePullPolicy: IfNotPresent + resources: + requests: + memory: 256Mi + cpu: 100m + ## Configure resource requests and limits ## ref: http://kubernetes.io/docs/user-guide/compute-resources/ ##