From 73d820d7c3fcbf3bc81c729cc74f4445519bf34d Mon Sep 17 00:00:00 2001 From: David McKay Date: Thu, 5 Mar 2020 18:38:40 +0000 Subject: [PATCH] feat: Add InfluxDB2 Chart --- charts/influxdb2/.helmignore | 21 ++++++ charts/influxdb2/Chart.yaml | 7 ++ charts/influxdb2/README.md | 56 ++++++++++++++++ charts/influxdb2/templates/NOTES.txt | 5 ++ charts/influxdb2/templates/_helpers.tpl | 53 +++++++++++++++ .../influxdb2/templates/job-setup-admin.yaml | 44 +++++++++++++ .../templates/persistent-volume-claim.yaml | 21 ++++++ charts/influxdb2/templates/secret.yaml | 9 +++ charts/influxdb2/templates/service.yaml | 16 +++++ charts/influxdb2/templates/statefulset.yaml | 66 +++++++++++++++++++ charts/influxdb2/values.yaml | 51 ++++++++++++++ 11 files changed, 349 insertions(+) create mode 100644 charts/influxdb2/.helmignore create mode 100644 charts/influxdb2/Chart.yaml create mode 100644 charts/influxdb2/README.md create mode 100644 charts/influxdb2/templates/NOTES.txt create mode 100644 charts/influxdb2/templates/_helpers.tpl create mode 100644 charts/influxdb2/templates/job-setup-admin.yaml create mode 100644 charts/influxdb2/templates/persistent-volume-claim.yaml create mode 100644 charts/influxdb2/templates/secret.yaml create mode 100644 charts/influxdb2/templates/service.yaml create mode 100644 charts/influxdb2/templates/statefulset.yaml create mode 100644 charts/influxdb2/values.yaml diff --git a/charts/influxdb2/.helmignore b/charts/influxdb2/.helmignore new file mode 100644 index 00000000..f0c13194 --- /dev/null +++ b/charts/influxdb2/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/influxdb2/Chart.yaml b/charts/influxdb2/Chart.yaml new file mode 100644 index 00000000..02223fd7 --- /dev/null +++ b/charts/influxdb2/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +appVersion: 2.0.0-beta + +name: influxdb +description: A Helm chart for InfluxDB v2 +type: application +version: 1.0.0 diff --git a/charts/influxdb2/README.md b/charts/influxdb2/README.md new file mode 100644 index 00000000..b3abc9fc --- /dev/null +++ b/charts/influxdb2/README.md @@ -0,0 +1,56 @@ +# InfluxDB + +**Warning**: This chart, as well as the software it deploys, is in a BETA phase. + +If you're considering deploying this, please also consider using our [Slack channel](https://www.influxdata.com/slack) to get support when needed. + +## An Open-Source Time Series Database + +[InfluxDB](https://github.com/influxdata/influxdb) is an open source time series database built by the folks over at [InfluxData](https://influxdata.com) with no external dependencies. It's useful for recording metrics, events, and performing analytics. + +## QuickStart + +```bash +helm repo add influxdata https://helm.influxdata.com/ +helm upgrade --install influxdb influxdata/influxdb2 --namespace monitoring +``` + +> **Tip**: `helm upgrade --install [RELEASE] [CHART] [FLAGS]` can be shortened : `helm upgrade -i [RELEASE] [CHART] [FLAGS]` + +## Introduction + +This chart bootstraps an InfluxDB v2 statefulset and service on a Kubernetes cluster using the Helm Package manager. + +## Prerequisites + +- Kubernetes 1.4+ +- PV provisioner support in the underlying infrastructure (optional) + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```bash +helm upgrade --install my-release influxdata/influxdb2 +``` + +The command deploys InfluxDB on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```bash +helm uninstall my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + + +## Persistence + +The [InfluxDB](https://quay.io/influxdb/influxdb:2.0.0-beta) image stores data in the `/root/.influxdbv2` directory in the container. + +If persistence is enabled, a [Persistent Volume](http://kubernetes.io/docs/user-guide/persistent-volumes/) associated with Statefulset will be provisioned. The volume is created using dynamic volume provisioning. In case of a disruption e.g. a node drain, kubernetes ensures that the same volume will be reatached to the Pod, preventing any data loss. Althought, when persistence is not enabled, InfluxDB data will be stored in an empty directory thus, in a Pod restart, data will be lost. diff --git a/charts/influxdb2/templates/NOTES.txt b/charts/influxdb2/templates/NOTES.txt new file mode 100644 index 00000000..d86fc3aa --- /dev/null +++ b/charts/influxdb2/templates/NOTES.txt @@ -0,0 +1,5 @@ +InfluxDB 2 is deployed as a StatefulSet on your cluster. + +You can access it by using the service name: {{ template "influxdb.fullname" . }} + +Admin password and token are available in the secret: {{ template "influxdb.fullname" . }}-auth diff --git a/charts/influxdb2/templates/_helpers.tpl b/charts/influxdb2/templates/_helpers.tpl new file mode 100644 index 00000000..71126c2f --- /dev/null +++ b/charts/influxdb2/templates/_helpers.tpl @@ -0,0 +1,53 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "influxdb.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "influxdb.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "influxdb.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "influxdb.labels" -}} +app.kubernetes.io/name: {{ include "influxdb.name" . }} +helm.sh/chart: {{ include "influxdb.chart" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end -}} + +{{/* +Selector labels +*/}} +{{- define "influxdb.selectorLabels" -}} +app.kubernetes.io/name: {{ include "influxdb.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} diff --git a/charts/influxdb2/templates/job-setup-admin.yaml b/charts/influxdb2/templates/job-setup-admin.yaml new file mode 100644 index 00000000..9cb8e06c --- /dev/null +++ b/charts/influxdb2/templates/job-setup-admin.yaml @@ -0,0 +1,44 @@ +apiVersion: batch/v1 +kind: Job +metadata: + labels: + {{- include "influxdb.labels" . | nindent 4 }} + name: {{ template "influxdb.fullname" . }}-create-admin-user + annotations: + "helm.sh/hook": post-install + "helm.sh/hook-delete-policy": hook-succeeded + "helm.sh/hook-delete-policy": "before-hook-creation" +spec: + activeDeadlineSeconds: 90 + template: + metadata: + labels: + {{- include "influxdb.labels" . | nindent 8 }} + spec: + containers: + - name: {{ template "influxdb.fullname" . }}-create-admin-user + image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}" + env: + - name: INFLUXDB_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "influxdb.fullname" . }}-auth + key: admin-password + - name: INFLUXDB_TOKEN + valueFrom: + secretKeyRef: + name: {{ template "influxdb.fullname" . }}-auth + key: admin-token + command: + - bash + args: + - -c + - | + influx setup -f \ + --host http://{{ template "influxdb.fullname" . }} \ + -o {{ .Values.adminUser.organization }} \ + -b {{ .Values.adminUser.bucket }} \ + -u {{ .Values.adminUser.user }} \ + -p ${INFLUXDB_PASSWORD} \ + -t ${INFLUXDB_TOKEN} + restartPolicy: OnFailure diff --git a/charts/influxdb2/templates/persistent-volume-claim.yaml b/charts/influxdb2/templates/persistent-volume-claim.yaml new file mode 100644 index 00000000..d6cf6437 --- /dev/null +++ b/charts/influxdb2/templates/persistent-volume-claim.yaml @@ -0,0 +1,21 @@ +{{- if and (.Values.persistence.enabled) (not .Values.persistence.useExisting) }} +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: "{{- if not (empty .Values.persistence.name) }}{{ .Values.persistence.name }}{{- else }}{{ template "influxdb.fullname" . }}{{- end }}" + labels: + {{- include "influxdb.labels" . | nindent 4 }} +spec: + accessModes: + - {{ .Values.persistence.accessMode | quote }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} +{{- if .Values.persistence.storageClass }} +{{- if (eq "-" .Values.persistence.storageClass) }} + storageClassName: "" +{{- else }} + storageClassName: "{{ .Values.persistence.storageClass }}" +{{- end }} +{{- end }} +{{- end }} diff --git a/charts/influxdb2/templates/secret.yaml b/charts/influxdb2/templates/secret.yaml new file mode 100644 index 00000000..481ec1a3 --- /dev/null +++ b/charts/influxdb2/templates/secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + labels: + {{- include "influxdb.labels" . | nindent 4 }} + name: {{ template "influxdb.fullname" . }}-auth +data: + admin-password: {{ randAlphaNum 32 | b64enc | quote }} + admin-token: {{ randAlphaNum 32 | b64enc | quote }} diff --git a/charts/influxdb2/templates/service.yaml b/charts/influxdb2/templates/service.yaml new file mode 100644 index 00000000..1ed0cf2c --- /dev/null +++ b/charts/influxdb2/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "influxdb.fullname" . }} + labels: + {{- include "influxdb.labels" . | nindent 4 }} + app.kubernetes.io/component: backup +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: 9999 + protocol: TCP + name: http + selector: + {{- include "influxdb.selectorLabels" . | nindent 4 }} diff --git a/charts/influxdb2/templates/statefulset.yaml b/charts/influxdb2/templates/statefulset.yaml new file mode 100644 index 00000000..8037f0a1 --- /dev/null +++ b/charts/influxdb2/templates/statefulset.yaml @@ -0,0 +1,66 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ template "influxdb.fullname" . }} + labels: + {{ include "influxdb.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + {{- include "influxdb.selectorLabels" . | nindent 6 }} + serviceName: "{{ include "influxdb.fullname" . }}" + template: + metadata: + labels: + {{- include "influxdb.selectorLabels" . | nindent 8 }} + spec: + volumes: + - name: data + {{- if .Values.persistence.enabled }} + {{- if not (empty .Values.persistence.name) }} + persistentVolumeClaim: + claimName: {{ .Values.persistence.name }} + {{- else }} + persistentVolumeClaim: + claimName: {{ template "influxdb.fullname" . }} + {{- end }} + {{- else }} + emptyDir: {} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 9999 + protocol: TCP + livenessProbe: + httpGet: + path: /health + port: http + readinessProbe: + httpGet: + path: /health + port: http + volumeMounts: + - name: data + mountPath: /root/.influxdbv2 + resources: + {{ toYaml .Values.resources | indent 12 }} + + {{- with .Values.nodeSelector }} + nodeSelector: + {{ toYaml . | indent 8 }} + {{- end }} + + {{- with .Values.affinity }} + affinity: + {{ toYaml . | indent 8 }} + {{- end }} + + {{- with .Values.tolerations }} + tolerations: + {{ toYaml . | indent 8 }} + {{- end }} diff --git a/charts/influxdb2/values.yaml b/charts/influxdb2/values.yaml new file mode 100644 index 00000000..a4039094 --- /dev/null +++ b/charts/influxdb2/values.yaml @@ -0,0 +1,51 @@ +image: + repository: quay.io/influxdb/influxdb + pullPolicy: IfNotPresent + +nameOverride: "" +fullnameOverride: "" + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +## Create default user through Kubernetes job +## Defaults indicated below +## +adminUser: + organization: "influxdata" + bucket: "default" + user: "admin" + +## Persist data to a persistent volume +## +persistence: + enabled: true + ## If true will use an existing PVC instead of creating one + # useExisting: false + ## Name of existing PVC to be used in the influx deployment + # name: + ## influxdb data Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + ## + # storageClass: "-" + accessMode: ReadWriteOnce + size: 50Gi