Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helm chart #107

Merged
merged 14 commits into from
Dec 17, 2018
11 changes: 11 additions & 0 deletions production/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Currently there are four ways to try out Loki, in order from easier to hardest:
- [Using our free hosted demo](#free-hosted-demo)
- [Running it locally with Docker](#run-locally-using-docker)
- [Building from source](#build-and-run-from-source)
- [Run on Kubernetes with Helm](#run-on-kubernetes-with-helm)
- [Using our Ksonnet config to run a fully-blown production setup](ksonnet/)
- [Using Helm to deploy on Kubernetes](helm/)

## Free Hosted Demo

Expand Down Expand Up @@ -35,6 +37,15 @@ To test locally, we recommend using the docker-compose.yaml file in this directo

For instructions on how to use loki, see [our usage docs](../docs/usage.md).

## Run on Kubernetes with Helm

From within a local checkout of the loki repo, run:

```bash
$ helm install --name loki ./production/helm --namespace monitoring
```


## Build and Run From Source

Loki can be run in a single host, no-dependencies mode using the following commands.
Expand Down
13 changes: 13 additions & 0 deletions production/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: loki
version: 0.0.1
appVersion: 0.0.1
kubeVersion: "^1.10.0-0"
description: "Loki: like Prometheus, but for logs."
home: https://grafana.com/loki
icon: https://github.com/grafana/loki/raw/master/docs/logo.png
sources:
- https://github.com/grafana/loki
maintainers:
- name: TDB
email: TBD@gmail.com
engine: gotpl
22 changes: 22 additions & 0 deletions production/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Deploy Loki to Kubernetes with Helm

## Prerequisites

Make sure you have the helm configure on your cluster:

```
$ helm init
```

Clone `grafana/loki` repository and navigate to `production helm` directory:

```
$ git clone https://github.com/grafana/loki.git
$ cd loki/production/helm
```

## Deploying Loki and Promtail to your cluster.

```
$ helm install . -n loki --namespace <YOUR-NAMESPACE>
```
43 changes: 43 additions & 0 deletions production/helm/templates/loki/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "loki.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 "loki.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 "loki.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "loki.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "loki.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
43 changes: 43 additions & 0 deletions production/helm/templates/loki/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "loki.fullname" . }}
labels:
app: {{ template "loki.name" . }}
chart: {{ template "loki.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
loki.yaml: |
auth_enabled: {{ .Values.loki.configauth_enabled }}

server:
http_listen_port: {{ .Values.loki.service.port }}

ingester:
lifecycler:
ring:
store: {{ .Values.loki.config.ingester.lifecycler.ring.store }}
replication_factor: {{ .Values.loki.config.ingester.lifecycler.ring.replication_factor }}

{{- if .Values.loki.config.schema_configs }}
schema_config:
configs:
{{- range .Values.loki.config.schema_configs }}
- from: {{ .from }}
store: {{ .store }}
object_store: {{ .object_store }}
schema: {{ .schema }}
index:
prefix: {{ .index.prefix }}
period: {{ .index.period }}
{{- end -}}
{{- end -}}

{{- if .Values.loki.config.storage_configs }}
storage_config:
{{- range .Values.loki.config.storage_configs }}
{{ .name }}:
directory: {{ .directory }}
{{- end -}}
{{- end -}}
79 changes: 79 additions & 0 deletions production/helm/templates/loki/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: {{ template "loki.fullname" . }}
labels:
app: {{ template "loki.name" . }}
chart: {{ template "loki.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.loki.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
replicas: {{ .Values.loki.replicas }}
selector:
matchLabels:
app: {{ template "loki.name" . }}
release: {{ .Release.Name }}
strategy:
type: {{ .Values.loki.deploymentStrategy }}
{{- if ne .Values.loki.deploymentStrategy "RollingUpdate" }}
rollingUpdate: null
{{- end }}
template:
metadata:
labels:
app: {{ template "loki.name" . }}
release: {{ .Release.Name }}
{{- with .Values.loki.podAnnotations }}
annotations:
{{ toYaml . | indent 8 }}
{{- end }}
spec:
serviceAccountName: {{ template "loki.serviceAccountName" . }}
{{- if .Values.loki.priorityClassName }}
priorityClassName: {{ .Values.loki.priorityClassName }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.loki.image.repository }}:{{ .Values.loki.image.tag }}"
imagePullPolicy: {{ .Values.loki.image.pullPolicy }}
args:
- "-config.file=/etc/loki/loki.yaml"
volumeMounts:
- name: config
mountPath: /etc/loki
ports:
- name: {{ template "loki.name" . }}
containerPort: {{ .Values.loki.service.port }}
protocol: TCP
{{- with .Values.loki.livenessProbe }}
livenessProbe:
{{ toYaml . | indent 12 }}
{{- end }}
{{- with .Values.loki.readinessProbe }}
readinessProbe:
{{ toYaml . | indent 12 }}
{{- end }}
{{- with .Values.loki.resources }}
resources:
{{ toYaml . | indent 12 }}
{{- end }}
{{- with .Values.loki.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.loki.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.loki.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
- name: config
configMap:
name: {{ template "loki.fullname" . }}
28 changes: 28 additions & 0 deletions production/helm/templates/loki/podsecuritypolicy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.rbac.pspEnabled }}
apiVersion: extensions/v1beta1
kind: PodSecurityPolicy
metadata:
name: {{ template "loki.fullname" . }}
labels:
app: {{ template "loki.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
spec:
privileged: false
allowPrivilegeEscalation: false
volumes:
- 'configMap'
hostNetwork: false
hostIPC: false
hostPID: false
runAsUser:
rule: 'RunAsAny'
seLinux:
rule: 'RunAsAny'
supplementalGroups:
rule: 'RunAsAny'
fsGroup:
rule: 'RunAsAny'
readOnlyRootFilesystem: false
{{- end }}
18 changes: 18 additions & 0 deletions production/helm/templates/loki/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
name: {{ template "loki.fullname" . }}
labels:
app: {{ template "loki.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- if .Values.rbac.pspEnabled }}
rules:
- apiGroups: ['extensions']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames: [{{ template "loki.fullname" . }}]
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions production/helm/templates/loki/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: {{ template "loki.fullname" . }}
labels:
app: {{ template "loki.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "loki.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "loki.serviceAccountName" . }}
{{- end -}}
25 changes: 25 additions & 0 deletions production/helm/templates/loki/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "loki.fullname" . }}
labels:
app: {{ template "loki.name" . }}
chart: {{ template "loki.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.loki.service.labels }}
{{ toYaml .Values.loki.service.labels | indent 4 }}
{{- end }}
{{- with .Values.loki.service.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
ports:
- name: {{ template "loki.name" . }}
port: {{ .Values.loki.service.port }}
protocol: TCP
targetPort: {{ .Values.loki.service.port }}
selector:
app: {{ template "loki.name" . }}
release: {{ .Release.Name }}
11 changes: 11 additions & 0 deletions production/helm/templates/loki/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.serviceAccount.create }}
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: {{ template "loki.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "loki.serviceAccountName" . }}
{{- end }}
43 changes: 43 additions & 0 deletions production/helm/templates/promtail/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "promtail.name" -}}
{{- default .Chart.Name .Values.promtail.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 "promtail.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.promtail.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 "promtail.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create the name of the service account
*/}}
{{- define "promtail.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "promtail.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
Loading