From 0e79b3de568dab9fcab0eb5d38ecc94b27a9afc3 Mon Sep 17 00:00:00 2001 From: xasor Date: Fri, 8 Jun 2018 16:35:53 +0100 Subject: [PATCH] [stable/mysql] Add prometheus metrics (#5131) * Add nodeSelector config parameter to mysql chart * Add appVersion * Rerun ci * Add prometheus metrics * Add new chart version * Add metrics to service * Fix hardcode annotations * Fix maintainer name --- stable/mysql/Chart.yaml | 4 ++-- stable/mysql/README.md | 7 +++++- stable/mysql/templates/deployment.yaml | 33 ++++++++++++++++++++++++++ stable/mysql/templates/svc.yaml | 9 +++++++ stable/mysql/values.yaml | 10 ++++++++ 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/stable/mysql/Chart.yaml b/stable/mysql/Chart.yaml index 9eb53a4040..83a4abd157 100644 --- a/stable/mysql/Chart.yaml +++ b/stable/mysql/Chart.yaml @@ -1,5 +1,5 @@ name: mysql -version: 0.6.0 +version: 0.7.0 appVersion: 5.7.14 description: Fast, reliable, scalable, and easy to use open-source relational database system. @@ -13,6 +13,6 @@ sources: - https://github.com/kubernetes/charts - https://github.com/docker-library/mysql maintainers: -- name: Vic Iglesias +- name: viglesiasce email: viglesias@google.com engine: gotpl diff --git a/stable/mysql/README.md b/stable/mysql/README.md index 8717958fa7..dc7d078f14 100644 --- a/stable/mysql/README.md +++ b/stable/mysql/README.md @@ -65,11 +65,16 @@ The following table lists the configurable parameters of the MySQL chart and the | `readinessProbe.failureThreshold` | Minimum consecutive failures for the probe to be considered failed after having succeeded. | 3 | | `persistence.enabled` | Create a volume to store data | true | | `persistence.size` | Size of persistent volume claim | 8Gi RW | -| `nodeSelector` | Node labels for pod assignment | {} | | `persistence.storageClass` | Type of persistent volume claim | nil (uses alpha storage class annotation) | | `persistence.accessMode` | ReadWriteOnce or ReadOnly | ReadWriteOnce | | `persistence.existingClaim` | Name of existing persistent volume | `nil` | | `persistence.subPath` | Subdirectory of the volume to mount | `nil` | +| `nodeSelector` | Node labels for pod assignment | {} | +| `metrics.enabled` | Start a side-car prometheus exporter | `false` | +| `metrics.image` | Exporter image | `prom/mysqld-exporter` | +| `metrics.imageTag` | Exporter image | `v0.10.0` | +| `metrics.imagePullPolicy` | Exporter image pull policy | `IfNotPresent` | +| `metrics.resources` | Exporter resource requests/limit | `nil` | | `resources` | CPU/Memory resource requests/limits | Memory: `256Mi`, CPU: `100m` | | `configurationFiles` | List of mysql configuration files | `nil` | | `ssl.enabled` | Setup and use SSL for MySQL connections | `false` | diff --git a/stable/mysql/templates/deployment.yaml b/stable/mysql/templates/deployment.yaml index c6e7e6915a..5406fdd8e7 100644 --- a/stable/mysql/templates/deployment.yaml +++ b/stable/mysql/templates/deployment.yaml @@ -111,6 +111,39 @@ spec: - name: certificates mountPath: /ssl {{- end }} + {{- if .Values.metrics.enabled }} + - name: metrics + image: "{{ .Values.metrics.image }}:{{ .Values.metrics.imageTag }}" + imagePullPolicy: {{ .Values.metrics.imagePullPolicy | quote }} + {{- if .Values.mysqlAllowEmptyPassword }} + command: [ 'sh', '-c', 'DATA_SOURCE_NAME="root@(localhost:3306)/" /bin/mysqld_exporter' ] + {{- else }} + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "mysql.fullname" . }} + key: mysql-root-password + command: [ 'sh', '-c', 'DATA_SOURCE_NAME="root:$MYSQL_ROOT_PASSWORD@(localhost:3306)/" /bin/mysqld_exporter' ] + {{- end }} + ports: + - name: metrics + containerPort: 9104 + livenessProbe: + httpGet: + path: /metrics + port: metrics + initialDelaySeconds: 15 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /metrics + port: metrics + initialDelaySeconds: 5 + timeoutSeconds: 1 + resources: +{{ toYaml .Values.metrics.resources | indent 10 }} + {{- end }} volumes: {{- if .Values.configurationFiles }} - name: configurations diff --git a/stable/mysql/templates/svc.yaml b/stable/mysql/templates/svc.yaml index 0d38ef90c5..de5669e30f 100644 --- a/stable/mysql/templates/svc.yaml +++ b/stable/mysql/templates/svc.yaml @@ -7,6 +7,10 @@ metadata: chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" release: "{{ .Release.Name }}" heritage: "{{ .Release.Service }}" +{{- if .Values.metrics.enabled }} + annotations: +{{ toYaml .Values.metrics.annotations | indent 4 }} +{{- end }} spec: type: {{ .Values.service.type }} ports: @@ -16,5 +20,10 @@ spec: {{- if .Values.service.nodePort }} nodePort: {{ .Values.service.nodePort }} {{- end }} + {{- if .Values.metrics.enabled }} + - name: metrics + port: 9104 + targetPort: metrics + {{- end }} selector: app: {{ template "mysql.fullname" . }} diff --git a/stable/mysql/values.yaml b/stable/mysql/values.yaml index 0cc0e81f95..9c216670e6 100644 --- a/stable/mysql/values.yaml +++ b/stable/mysql/values.yaml @@ -91,6 +91,16 @@ initializationFiles: # second-db.sql: |- # CREATE DATABASE IF NOT EXISTS second DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; +metrics: + enabled: false + image: prom/mysqld-exporter + imageTag: v0.10.0 + imagePullPolicy: IfNotPresent + resources: {} + annotations: {} + # prometheus.io/scrape: "true" + # prometheus.io/port: "9104" + ## Configure the service ## ref: http://kubernetes.io/docs/user-guide/services/ service: