From 580957e8f95d47fda6dcd7ccd38696b41a3369dc Mon Sep 17 00:00:00 2001 From: Jonathan Chauncey Date: Mon, 13 Mar 2017 12:54:44 -0400 Subject: [PATCH] feat(influxdb): Use stable/influxdb chart closes #180 * This moves to using the influxdb chart in the stable repository * Sets the version to 0.4.0 * Adds two pre-upgrade hooks to the base monitor chart. These hooks allow the chart to migrate data from the old volume mount location to the new one provided by the influxdb chart. * If `influxdb_location` is set to `off-cluster` it will delete the deployment resource using a post-install or post-upgrade hook. --- .gitignore | 1 + .../templates/monitor-grafana-deployment.yaml | 4 +- charts/monitor/charts/influxdb/Chart.yaml | 7 -- .../templates/monitor-influxdb-api-svc.yaml | 21 ------ .../monitor-influxdb-creds-secret.yaml | 14 ---- .../monitor-influxdb-deployment.yaml | 69 ------------------- .../templates/monitor-influxdb-pvc.yaml | 20 ------ .../templates/monitor-influxdb-ui-svc.yaml | 21 ------ .../templates/monitor-telegraf-daemon.yaml | 4 +- charts/monitor/migrate.yaml | 40 +++++++++++ charts/monitor/requirements.lock | 10 +++ charts/monitor/requirements.yaml | 9 +++ .../templates/hook-delete-influxdb.yaml | 36 ++++++++++ charts/monitor/templates/hook-kill-pods.yaml | 36 ++++++++++ .../monitor/templates/hook-migrate-data.yaml | 57 +++++++++++++++ .../hook-post-migration-cleanup.yaml | 37 ++++++++++ ...onitor-telegraf-influxdb-creds-secret.yaml | 14 ++++ charts/monitor/values.yaml | 24 +++---- 18 files changed, 256 insertions(+), 168 deletions(-) delete mode 100644 charts/monitor/charts/influxdb/Chart.yaml delete mode 100644 charts/monitor/charts/influxdb/templates/monitor-influxdb-api-svc.yaml delete mode 100644 charts/monitor/charts/influxdb/templates/monitor-influxdb-creds-secret.yaml delete mode 100644 charts/monitor/charts/influxdb/templates/monitor-influxdb-deployment.yaml delete mode 100644 charts/monitor/charts/influxdb/templates/monitor-influxdb-pvc.yaml delete mode 100644 charts/monitor/charts/influxdb/templates/monitor-influxdb-ui-svc.yaml create mode 100644 charts/monitor/migrate.yaml create mode 100644 charts/monitor/requirements.lock create mode 100644 charts/monitor/requirements.yaml create mode 100644 charts/monitor/templates/hook-delete-influxdb.yaml create mode 100644 charts/monitor/templates/hook-kill-pods.yaml create mode 100644 charts/monitor/templates/hook-migrate-data.yaml create mode 100644 charts/monitor/templates/hook-post-migration-cleanup.yaml create mode 100644 charts/monitor/templates/monitor-telegraf-influxdb-creds-secret.yaml diff --git a/.gitignore b/.gitignore index e8ec15a..4335ae1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ influxdb/manifests/*.tmp.yaml chronograf/manifests/*.tmp.yaml grafana/manifests/*.tmp.yaml rootfs/usr/bin/telegraf +charts/monitor/charts/*.tgz \ No newline at end of file diff --git a/charts/monitor/charts/grafana/templates/monitor-grafana-deployment.yaml b/charts/monitor/charts/grafana/templates/monitor-grafana-deployment.yaml index b61cf52..58fe288 100644 --- a/charts/monitor/charts/grafana/templates/monitor-grafana-deployment.yaml +++ b/charts/monitor/charts/grafana/templates/monitor-grafana-deployment.yaml @@ -59,8 +59,8 @@ spec: name: influxdb-creds key: password {{- else }} - - name: "INFLUXDB_URLS" - value: http://$(DEIS_MONITOR_INFLUXAPI_SERVICE_HOST):$(DEIS_MONITOR_INFLUXAPI_SERVICE_PORT_TRANSPORT) + - name: DEIS_MONITOR_INFLUXAPI_SERVICE_HOST + value: {{.Release.Name}}-influxdb.{{.Release.Namespace}}.svc.cluster.local {{- end }} - name: "BIND_PORT" value: "3500" diff --git a/charts/monitor/charts/influxdb/Chart.yaml b/charts/monitor/charts/influxdb/Chart.yaml deleted file mode 100644 index a300431..0000000 --- a/charts/monitor/charts/influxdb/Chart.yaml +++ /dev/null @@ -1,7 +0,0 @@ -name: influxdb -home: https://github.com/deis/monitor/tree/master/influxdb -version: -description: Monitoring for Deis Workflow. -maintainers: - - name: Deis Team - email: engineering@deis.com diff --git a/charts/monitor/charts/influxdb/templates/monitor-influxdb-api-svc.yaml b/charts/monitor/charts/influxdb/templates/monitor-influxdb-api-svc.yaml deleted file mode 100644 index 0946bc0..0000000 --- a/charts/monitor/charts/influxdb/templates/monitor-influxdb-api-svc.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{- if eq .Values.global.influxdb_location "on-cluster" }} -apiVersion: v1 -kind: Service -metadata: - name: deis-monitor-influxapi - labels: - heritage: deis - app: deis-monitor-influxapi - router.deis.io/routable: "true" - annotations: - router.deis.io/domains: influxapi - router.deis.io/connectTimeout: "10" - router.deis.io/tcpTimeout: "1200" -spec: - ports: - - port: 80 - name: transport - targetPort: transport - selector: - app: deis-monitor-influxdb -{{- end }} diff --git a/charts/monitor/charts/influxdb/templates/monitor-influxdb-creds-secret.yaml b/charts/monitor/charts/influxdb/templates/monitor-influxdb-creds-secret.yaml deleted file mode 100644 index 6b7d914..0000000 --- a/charts/monitor/charts/influxdb/templates/monitor-influxdb-creds-secret.yaml +++ /dev/null @@ -1,14 +0,0 @@ -{{- if eq .Values.global.influxdb_location "off-cluster" }} -apiVersion: v1 -kind: Secret -metadata: - name: influxdb-creds - labels: - heritage: deis -type: Opaque -data: - url: {{ .Values.url | b64enc }} - database: {{ .Values.database | b64enc }} - user: {{ .Values.user | b64enc }} - password: {{ .Values.password | b64enc }} -{{- end }} diff --git a/charts/monitor/charts/influxdb/templates/monitor-influxdb-deployment.yaml b/charts/monitor/charts/influxdb/templates/monitor-influxdb-deployment.yaml deleted file mode 100644 index b5c5f6f..0000000 --- a/charts/monitor/charts/influxdb/templates/monitor-influxdb-deployment.yaml +++ /dev/null @@ -1,69 +0,0 @@ -{{- if eq .Values.global.influxdb_location "on-cluster" }} -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: deis-monitor-influxdb - labels: - heritage: deis - annotations: - component.deis.io/version: {{ .Values.docker_tag }} -spec: - replicas: 1 - strategy: - type: Recreate - selector: - matchLabels: - app: deis-monitor-influxdb - template: - metadata: - labels: - app: deis-monitor-influxdb - spec: - containers: - - name: deis-monitor-influxdb - image: quay.io/{{.Values.org}}/influxdb:{{.Values.docker_tag}} - imagePullPolicy: {{.Values.pull_policy}} -{{- if or (.Values.limits_cpu) (.Values.limits_memory)}} - resources: - limits: -{{- if (.Values.limits_cpu) }} - cpu: {{.Values.limits_cpu}} -{{- end}} -{{- if (.Values.limits_memory) }} - memory: {{.Values.limits_memory}} -{{- end}} -{{- end}} - ports: - - containerPort: 8083 - name: admin - - containerPort: 8086 - name: transport - protocol: TCP - - containerPort: 8084 - name: ssltransport - protocol: TCP - livenessProbe: - httpGet: - path: /ping - port: 8086 - initialDelaySeconds: 1 - timeoutSeconds: 1 - readinessProbe: - httpGet: - path: /ping - port: 8086 - initialDelaySeconds: 1 - timeoutSeconds: 1 -{{- if .Values.persistence.enabled }} - volumeMounts: - - name: influxdb-data - mountPath: /data - # Allow user influxdb to write to /data - securityContext: - fsGroup: 1001 - volumes: - - name: influxdb-data - persistentVolumeClaim: - claimName: deis-monitor-influxdb -{{- end }} -{{- end }} diff --git a/charts/monitor/charts/influxdb/templates/monitor-influxdb-pvc.yaml b/charts/monitor/charts/influxdb/templates/monitor-influxdb-pvc.yaml deleted file mode 100644 index 22a8d1a..0000000 --- a/charts/monitor/charts/influxdb/templates/monitor-influxdb-pvc.yaml +++ /dev/null @@ -1,20 +0,0 @@ -{{- if .Values.persistence.enabled }} -kind: PersistentVolumeClaim -apiVersion: v1 -metadata: - name: deis-monitor-influxdb - labels: - heritage: deis - annotations: - {{- if .Values.persistence.storageClass }} - volume.beta.kubernetes.io/storage-class: {{ .Values.persistence.storageClass | quote }} - {{- else }} - volume.alpha.kubernetes.io/storage-class: default - {{- end }} -spec: - accessModes: - - {{ .Values.persistence.accessMode | quote }} - resources: - requests: - storage: {{ .Values.persistence.size | quote }} -{{- end }} diff --git a/charts/monitor/charts/influxdb/templates/monitor-influxdb-ui-svc.yaml b/charts/monitor/charts/influxdb/templates/monitor-influxdb-ui-svc.yaml deleted file mode 100644 index 0b1c074..0000000 --- a/charts/monitor/charts/influxdb/templates/monitor-influxdb-ui-svc.yaml +++ /dev/null @@ -1,21 +0,0 @@ -{{- if eq .Values.global.influxdb_location "on-cluster" }} -apiVersion: v1 -kind: Service -metadata: - name: deis-monitor-influxui - labels: - heritage: deis - app: deis-monitor-influxui - router.deis.io/routable: "true" - annotations: - router.deis.io/domains: influx - router.deis.io/connectTimeout: "10" - router.deis.io/tcpTimeout: "1200" -spec: - ports: - - port: 80 - name: admin - targetPort: admin - selector: - app: deis-monitor-influxdb -{{- end }} diff --git a/charts/monitor/charts/telegraf/templates/monitor-telegraf-daemon.yaml b/charts/monitor/charts/telegraf/templates/monitor-telegraf-daemon.yaml index 4ea070b..5f60630 100644 --- a/charts/monitor/charts/telegraf/templates/monitor-telegraf-daemon.yaml +++ b/charts/monitor/charts/telegraf/templates/monitor-telegraf-daemon.yaml @@ -55,9 +55,9 @@ spec: key: password {{- else }} - name: "INFLUXDB_URLS" - value: "\"http://$(DEIS_MONITOR_INFLUXAPI_SERVICE_HOST):$(DEIS_MONITOR_INFLUXAPI_SERVICE_PORT_TRANSPORT)\"" + value: "\"http://{{.Release.Name}}-influxdb.{{.Release.Namespace}}.svc.cluster.local:8086\"" - name: "INFLUXDB_INPUT_URLS" - value: "\"http://$(DEIS_MONITOR_INFLUXAPI_SERVICE_HOST):$(DEIS_MONITOR_INFLUXAPI_SERVICE_PORT_TRANSPORT)/debug/vars\"" + value: "\"http://{{.Release.Name}}-influxdb.{{.Release.Namespace}}.svc.cluster.local:8086/debug/vars\"" - name: "ENABLE_INFLUXDB_INPUT" value: "true" {{- end }} diff --git a/charts/monitor/migrate.yaml b/charts/monitor/migrate.yaml new file mode 100644 index 0000000..37a3fc6 --- /dev/null +++ b/charts/monitor/migrate.yaml @@ -0,0 +1,40 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: deis-monitor-migrate-data + annotations: + "helm.sh/hook": "pre-upgrade" + "helm.sh/hook-weight": "0" +spec: + template: + spec: + restartPolicy: Never + containers: + - name: deis-monitor-migrate-data + image: "lachlanevenson/k8s-kubectl" + command: ["/bin/sh", "-c"] + args: ["(if [ -d /var/lib/influxdb/data/_internal ]; then \ + echo 'Nothing to migrate!'; \ + else \ + echo Creating directories; \ + mkdir /var/lib/influxdb/data; \ + (if [ -d /var/lib/influxdb/db/wal ]; then \ + echo 'Moving data from /db/wal'; \ + mv /var/lib/influxdb/db/wal /var/lib/influxdb; \ + else \ + echo 'Directory /var/lib/influxdb/db/wal does not exist!'; \ + fi); \ + (if [ -d /var/lib/influxdb/db/_internal ]; then \ + echo 'Moving data from /db/*'; \ + mv /var/lib/influxdb/db/* /var/lib/influxdb/data; \ + else \ + echo 'Directory /var/lib/influxdb/db does not exist!'; \ + fi); + fi)"] + volumeMounts: + - name: data + mountPath: /var/lib/influxdb + volumes: + - name: data + persistentVolumeClaim: + claimName: deis-monitor-influxdb diff --git a/charts/monitor/requirements.lock b/charts/monitor/requirements.lock new file mode 100644 index 0000000..93a2a49 --- /dev/null +++ b/charts/monitor/requirements.lock @@ -0,0 +1,10 @@ +dependencies: +- condition: "" + enabled: false + import-values: null + name: influxdb + repository: http://127.0.0.1:8879 + tags: null + version: 0.4.1 +digest: sha256:b034be0df67d05c3f222f01f996fed5d2a70bbc4033500cb5dfd82b5b84651d2 +generated: 2017-04-20T13:08:49.746407575-04:00 diff --git a/charts/monitor/requirements.yaml b/charts/monitor/requirements.yaml new file mode 100644 index 0000000..3a165ad --- /dev/null +++ b/charts/monitor/requirements.yaml @@ -0,0 +1,9 @@ + # dependencies: + # - name: influxdb + # version: "0.4.0" + # repository: https://kubernetes-charts.storage.googleapis.com + + dependencies: + - name: influxdb + version: "0.4.1" + repository: http://127.0.0.1:8879 \ No newline at end of file diff --git a/charts/monitor/templates/hook-delete-influxdb.yaml b/charts/monitor/templates/hook-delete-influxdb.yaml new file mode 100644 index 0000000..c00c95e --- /dev/null +++ b/charts/monitor/templates/hook-delete-influxdb.yaml @@ -0,0 +1,36 @@ +{{- if eq .Values.global.influxdb_location "off-cluster" }} +apiVersion: batch/v1 +kind: Job +metadata: + name: deis-monitor-delete-influxdb-deployment-{{ randAlphaNum 5 | lower }} + labels: + app: "deis-monitor-delete-influxdb-deployment" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + annotations: + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-weight": "-10" +spec: + template: + metadata: + name: "{{.Release.Name}}" + labels: + app: "deis-monitor-delete-influxdb-deployment" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + spec: + restartPolicy: Never + containers: + - name: deis-monitor-delete-influxdb-deployment + image: "lachlanevenson/k8s-kubectl" + command: ["/bin/sh", "-c"] + args: ["(kubectl delete deploy {{.Release.Name}}-influxdb) \ + || \ + true"] + - name: deis-monitor-delete-telegraf-pods + image: "lachlanevenson/k8s-kubectl" + command: ["/bin/sh", "-c"] + args: ["kubectl get pods | grep deis-monitor-telegraf | awk '{print $1}' | xargs kubectl delete pod \ + || \ + true"] +{{- end }} \ No newline at end of file diff --git a/charts/monitor/templates/hook-kill-pods.yaml b/charts/monitor/templates/hook-kill-pods.yaml new file mode 100644 index 0000000..8cc29d5 --- /dev/null +++ b/charts/monitor/templates/hook-kill-pods.yaml @@ -0,0 +1,36 @@ +{{ $tillerVersion := semver .Capabilities.TillerVersion.SemVer }} +{{ $comparingVersion := semver "2.3.0" }} + +{{- if gt ($tillerVersion | $comparingVersion.Compare) -1 }} +{{- if .Values.influxdb.persistence.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: deis-monitor-kill-pods-{{ randAlphaNum 5 | lower }} + labels: + app: "deis-monitor-kill-pods" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "-10" +spec: + template: + metadata: + name: "{{.Release.Name}}" + labels: + app: "deis-monitor-kill-pods" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + spec: + restartPolicy: Never + containers: + - name: deis-monitor-kill-pods + image: "lachlanevenson/k8s-kubectl" + command: ["/bin/sh", "-c"] + args: ["((kubectl delete daemonset deis-monitor-telegraf || true) && + (kubectl delete deploy deis-monitor-influxdb || true) && + (kubectl delete deploy deis-workflow-influxdb || true) && + sleep 30) || true"] +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/monitor/templates/hook-migrate-data.yaml b/charts/monitor/templates/hook-migrate-data.yaml new file mode 100644 index 0000000..59114c2 --- /dev/null +++ b/charts/monitor/templates/hook-migrate-data.yaml @@ -0,0 +1,57 @@ +{{ $tillerVersion := semver .Capabilities.TillerVersion.SemVer }} +{{ $comparingVersion := semver "2.3.0" }} + +{{- if gt ($tillerVersion | $comparingVersion.Compare) -1 }} +{{- if .Values.influxdb.persistence.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: deis-monitor-migrate-data-{{ randAlphaNum 5 | lower }} + labels: + app: "deis-monitor-migrate-data" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "0" +spec: + template: + metadata: + name: "{{.Release.Name}}" + labels: + app: "deis-monitor-migrate-data" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + spec: + restartPolicy: Never + containers: + - name: deis-monitor-migrate-data + image: "lachlanevenson/k8s-kubectl" + command: ["/bin/sh", "-c"] + args: ["(if [ -d {{ .Values.influxdb.config.storage_directory }}/data/_internal ]; then \ + echo 'Nothing to migrate!'; \ + else \ + echo Creating directories; \ + mkdir {{ .Values.influxdb.config.storage_directory }}/data; \ + (if [ -d {{ .Values.influxdb.config.storage_directory }}/db/wal ]; then \ + echo 'Moving data from /db/wal'; \ + mv {{ .Values.influxdb.config.storage_directory }}/db/wal {{ .Values.influxdb.config.storage_directory }}; \ + else \ + echo 'Directory {{ .Values.influxdb.config.storage_directory }}/db/wal does not exist!'; \ + fi); \ + (if [ -d {{ .Values.influxdb.config.storage_directory }}/db/_internal ]; then \ + echo 'Moving data from /db/*'; \ + mv {{ .Values.influxdb.config.storage_directory }}/db/* {{ .Values.influxdb.config.storage_directory }}/data; \ + else \ + echo 'Directory {{ .Values.influxdb.config.storage_directory }}/db does not exist!'; \ + fi); + fi)"] + volumeMounts: + - name: data + mountPath: {{ .Values.influxdb.config.storage_directory }} + volumes: + - name: data + persistentVolumeClaim: + claimName: deis-monitor-influxdb +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/monitor/templates/hook-post-migration-cleanup.yaml b/charts/monitor/templates/hook-post-migration-cleanup.yaml new file mode 100644 index 0000000..5137e94 --- /dev/null +++ b/charts/monitor/templates/hook-post-migration-cleanup.yaml @@ -0,0 +1,37 @@ +{{ $tillerVersion := semver .Capabilities.TillerVersion.SemVer }} +{{ $comparingVersion := semver "2.3.0" }} + +{{- if gt ($tillerVersion | $comparingVersion.Compare) -1 }} +{{- if .Values.influxdb.persistence.enabled }} +apiVersion: batch/v1 +kind: Job +metadata: + name: deis-monitor-migration-cleanup-{{ randAlphaNum 5 | lower }} + labels: + app: "deis-monitor-migration-cleanup" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + annotations: + "helm.sh/hook": pre-upgrade + "helm.sh/hook-weight": "10" +spec: + template: + metadata: + name: "{{.Release.Name}}" + labels: + app: "deis-monitor-migration-cleanup" + heritage: "{{ .Release.Service }}" + release: "{{ .Release.Name }}" + spec: + restartPolicy: Never + containers: + - name: deis-monitor-migration-cleanup + image: "lachlanevenson/k8s-kubectl" + command: ["/bin/sh", "-c"] + args: ["kubectl delete svc deis-monitor-influxui \ + || \ + kubectl delete svc deis-monitor-influxapi \ + || \ + true"] +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/monitor/templates/monitor-telegraf-influxdb-creds-secret.yaml b/charts/monitor/templates/monitor-telegraf-influxdb-creds-secret.yaml new file mode 100644 index 0000000..9cbad43 --- /dev/null +++ b/charts/monitor/templates/monitor-telegraf-influxdb-creds-secret.yaml @@ -0,0 +1,14 @@ +{{- if eq .Values.global.influxdb_location "off-cluster" }} +apiVersion: v1 +kind: Secret +metadata: + name: influxdb-creds + labels: + heritage: deis +type: Opaque +data: + url: {{ .Values.influxdb.url | b64enc }} + database: {{ .Values.influxdb.database | b64enc }} + user: {{ .Values.influxdb.user | b64enc }} + password: {{ .Values.influxdb.password | b64enc }} +{{- end }} \ No newline at end of file diff --git a/charts/monitor/values.yaml b/charts/monitor/values.yaml index 50189e5..375e970 100644 --- a/charts/monitor/values.yaml +++ b/charts/monitor/values.yaml @@ -8,27 +8,27 @@ grafana: enabled: false accessMode: ReadWriteOnce size: 5Gi -influxdb: + +telegraf: org: "deisci" pull_policy: "Always" docker_tag: canary # limits_cpu: "100m" # limits_memory: "50Mi" + +influxdb: + # Configure the following ONLY if using an off-cluster Influx database url: "my.influx.url" database: "kubernetes" user: "user" password: "password" + # Configure the following ONLY if you want persistence for on-cluster influxdb + # GCP PDs and EBS volumes are supported only persistence: - enabled: false - accessMode: ReadWriteOnce - size: 20Gi -telegraf: - org: "deisci" - pull_policy: "Always" - docker_tag: canary - # limits_cpu: "100m" - # limits_memory: "50Mi" - + enabled: false # Set to true to enable persistence + name: deis-monitor-influxdb + size: 20Gi # PVC size + global: # Set the location of Workflow's influxdb cluster # @@ -47,4 +47,4 @@ global: # Valid values are: # - on-cluster: Run Redis within the Kubernetes cluster # - off-cluster: Run Redis outside the Kubernetes cluster (configure in loggerRedis section) - logger_redis_location: "on-cluster" + logger_redis_location: "on-cluster" \ No newline at end of file