Skip to content
This repository was archived by the owner on Jan 5, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions kapacitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## QuickStart

```bash
$ helm install stable/kapacitor --name foo --namespace bar
$ helm install --wait stable/kapacitor --name foo --namespace bar
```

## Introduction
Expand All @@ -24,7 +24,7 @@ This chart bootstraps A Kapacitor deployment and service on a Kubernetes cluster
To install the chart with the release name `my-release`:

```bash
$ helm install --name my-release stable/kapacitor
$ helm install --wait --name my-release stable/kapacitor
```

The command deploys Kapacitor on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
Expand Down Expand Up @@ -65,8 +65,23 @@ $ helm install --name my-release -f values.yaml stable/kapacitor

> **Tip**: You can use the default [values.yaml](values.yaml)

## Automatic TICK script installation

TICK scripts can be installed from a specified directory via a Kubernetes job
with Helm `post-install` and `post-upgrade` hooks. It's disabled by default. To
enable use:

```bash
helm install --name my-release \
--set "install_tick_scripts.enabled=true" \
--set "install_tick_scripts.tick_dir=/tick" \
-f values.yaml stable/kapacitor
```

Or modify the default values in `values.yaml`.

## Persistence

The [Kapacitor](https://hub.docker.com/_/kapacitor/) image stores data in the `/var/lib/kapacitor` directory in the container.

The chart optionally mounts a [Persistent Volume](kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning.
The chart optionally mounts a [Persistent Volume](kubernetes.io/docs/user-guide/persistent-volumes/) volume at this location. The volume is created using dynamic volume provisioning.
74 changes: 74 additions & 0 deletions kapacitor/templates/tickscript-init-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{if .Values.install_tick_scripts.enabled }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}-init
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
init.sh: |-
#!/usr/bin/env bash
export KAPACITOR_URL="{{ template "fullname" . }}.{{ .Release.Namespace }}:9092"
ls -al $TICK_DIR
kapacitor list tasks

echo "Loading TICK files from $TICK_DIR"
for f in ${TICK_DIR}/*.tick
do
name="$(basename $f)"
name="${name/.tick/}"
kapacitor define $name \
-type batch \
-dbrp telegraf.autogen \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a better solution to hardcoding the type and dbrp of the task? In the past I have parsed the type and dbrp values from comments at the top of the TICKscript. Part of the work in influxdata/kapacitor#1313 will be to standardize that behavior.

For example

// kapacitor:type=stream
// kapacitor:dbrp=telegraf.autogen

or

// kapacitor:type=batch
// kapacitor:dbrp=mydatabase.autogen

Something along those lines is what I was thinking, but that will probably not be the final result of influxdata/kapacitor#1313.

Technically it is possible to have multiple dbrps values but you can probably leave that out for now as it is uncommon.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my purposes I don't (yet) need it to vary, which is why I hardcoded it. I figured I could bake it into the dir structure if I needed to parameterize it someday, e.g. $TICK_DIR/telegraf/autogen/foo.tick. If you want to bake it into the TICK script itself and parse it out in kapacitor, sounds good to me 😁.

-tick $f
kapacitor enable $name
done
echo DONE
kapacitor list tasks
---
apiVersion: batch/v1
kind: Job
metadata:
name: {{ template "fullname" . }}-init-job
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name | quote }}
heritage: {{ .Release.Service | quote }}
app: {{ template "fullname" . }}
annotations:
"helm.sh/hook": post-install,post-upgrade
spec:
template:
metadata:
name: "{{.Release.Name}}"
labels:
heritage: {{.Release.Service | quote }}
release: {{.Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
spec:
restartPolicy: OnFailure
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["bash", "/init/init.sh"]
env:
- name: TICK_DIR
value: "{{ .Values.install_tick_scripts.tick_dir }}"
volumeMounts:
- name: alerts
mountPath: /tick
- name: init
mountPath: /init
volumes:
- name: alerts
configMap:
name: {{ template "fullname" . }}-alerts
- name: init
configMap:
name: {{ template "fullname" . }}-init
{{- end }}
8 changes: 8 additions & 0 deletions kapacitor/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ resources:
## ref: https://docs.influxdata.com/kapacitor/v1.1/introduction/getting_started/
##
influxURL: http://data-influxdb.tick:8086


## A Kubernetes Job can be used to install TICK scripts from a specified
## tick_dir directory, if enabled.
##
install_tick_scripts:
enabled: false
tick_dir: /tick