Skip to content

Commit

Permalink
feat: add distributed mode to loki helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorwhitney committed Jan 31, 2024
1 parent 541b109 commit df50d2f
Show file tree
Hide file tree
Showing 58 changed files with 4,442 additions and 23 deletions.
19 changes: 19 additions & 0 deletions production/helm/loki/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,28 @@ Installed components:
{{- if .Values.minio.enabled }}
* minio
{{- end }}
{{- if eq (include "loki.deployment.isScalable" .) "true" }}
* read
* write
{{- if not .Values.read.legacyReadTarget }}
* backend
{{- end }}
{{- else }}
{{- if .Values.compactor.enabled }}
* compactor
{{- end }}
{{- if .Values.indexGateway.enabled }}
* index gateway
{{- end }}
{{- if .Values.queryScheduler.enabled }}
* query scheduler
{{- end }}
{{- if .Values.ruler.enabled }}
* ruler
{{- end }}
* distributor
* ingester
* querier
* query frontend
{{- end }}
{{- end }}
28 changes: 27 additions & 1 deletion production/helm/loki/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Params:
Return if deployment mode is simple scalable
*/}}
{{- define "loki.deployment.isScalable" -}}
{{- and (eq (include "loki.isUsingObjectStorage" . ) "true") (eq (int .Values.singleBinary.replicas) 0) }}
{{- $nonZeroScalableReplicas := (or (gt (int .Values.backend.replicas) 0) (gt (int .Values.read.replicas) 0) (gt (int .Values.write.replicas) 0)) }}
{{- and (eq (include "loki.isUsingObjectStorage" . ) "true") (eq (int .Values.singleBinary.replicas) 0) ($nonZeroScalableReplicas) }}
{{- end -}}

{{/*
Expand All @@ -61,6 +62,15 @@ Return if deployment mode is single binary
{{- or (eq (include "loki.isUsingObjectStorage" . ) "false") ($nonZeroReplicas) }}
{{- end -}}

{{/*
Return if deployment mode is distributed
*/}}
{{- define "loki.deployment.isDistributed" -}}
{{- $zeroScalableReplicas := (and (eq (int .Values.backend.replicas) 0) (eq (int .Values.read.replicas) 0) (eq (int .Values.write.replicas) 0)) }}
{{- and (eq (include "loki.isUsingObjectStorage" . ) "true") ($zeroScalableReplicas) }}
{{- 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).
Expand Down Expand Up @@ -897,3 +907,19 @@ enableServiceLinks: false
{{- end -}}
{{- printf "%s" $schedulerAddress }}
{{- end }}


{{- define "loki.config.checksum" -}}
checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
{{- end -}}

{{/*
Return the appropriate apiVersion for PodDisruptionBudget.
*/}}
{{- define "loki.pdb.apiVersion" -}}
{{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">=1.21-0" .Capabilities.KubeVersion.Version) -}}
{{- print "policy/v1" -}}
{{- else -}}
{{- print "policy/v1beta1" -}}
{{- end -}}
{{- end -}}
5 changes: 3 additions & 2 deletions production/helm/loki/templates/backend/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if and (not .Values.rbac.namespaced) (not .Values.rbac.useExistingRole) }}
{{- $isSimpleScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
{{- if and $isSimpleScalable (not .Values.rbac.namespaced) (not .Values.rbac.useExistingRole) }}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand All @@ -17,4 +18,4 @@ rules:
{{- else }}
rules: []
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if and (not .Values.rbac.namespaced) }}
{{- $isSimpleScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
{{- if and $isSimpleScalable (not .Values.rbac.namespaced) }}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand All @@ -21,4 +22,4 @@ roleRef:
name: {{ .Values.rbac.useExistingRole }}
{{- end }}
apiGroup: rbac.authorization.k8s.io
{{- end -}}
{{- end -}}
81 changes: 81 additions & 0 deletions production/helm/loki/templates/compactor/_helpers-compactor.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{{/*
compactor fullname
*/}}
{{- define "loki.compactorFullname" -}}
{{ include "loki.fullname" . }}-compactor
{{- end }}

{{/*
compactor common labels
*/}}
{{- define "loki.compactorLabels" -}}
{{ include "loki.labels" . }}
app.kubernetes.io/component: compactor
{{- end }}

{{/*
compactor selector labels
*/}}
{{- define "loki.compactorSelectorLabels" -}}
{{ include "loki.selectorLabels" . }}
app.kubernetes.io/component: compactor
{{- end }}

{{/*
compactor image
*/}}
{{- define "loki.compactorImage" -}}
{{- $dict := dict "loki" .Values.loki.image "service" .Values.compactor.image "global" .Values.global.image "defaultVersion" .Chart.AppVersion -}}
{{- include "loki.lokiImage" $dict -}}
{{- end }}

{{/*
compactor readinessProbe
*/}}
{{- define "loki.compactor.readinessProbe" -}}
{{- with .Values.compactor.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 2 }}
{{- else }}
{{- with .Values.loki.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
compactor livenessProbe
*/}}
{{- define "loki.compactor.livenessProbe" -}}
{{- with .Values.compactor.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 2 }}
{{- else }}
{{- with .Values.loki.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end }}
{{- end -}}

{{/*
compactor priority class name
*/}}
{{- define "loki.compactorPriorityClassName" }}
{{- $pcn := coalesce .Values.global.priorityClassName .Values.compactor.priorityClassName -}}
{{- if $pcn }}
priorityClassName: {{ $pcn }}
{{- end }}
{{- end }}

{{/*
Create the name of the compactor service account
*/}}
{{- define "loki.compactorServiceAccountName" -}}
{{- if .Values.compactor.serviceAccount.create -}}
{{ default (print (include "loki.serviceAccountName" .) "-compactor") .Values.compactor.serviceAccount.name }}
{{- else -}}
{{ default (include "loki.serviceAccountName" .) .Values.compactor.serviceAccount.name }}
{{- end -}}
{{- end -}}
161 changes: 161 additions & 0 deletions production/helm/loki/templates/compactor/deployment-compactor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{{/* {{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}} */}}
{{/* {{- if and $isDistributed .Values.compactor.enabled }} */}}
{{- if eq .Values.compactor.kind "Deployment"}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "loki.compactorFullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "loki.compactorLabels" . | nindent 4 }}
{{- with .Values.loki.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: 1
revisionHistoryLimit: {{ .Values.loki.revisionHistoryLimit }}
strategy:
type: Recreate
selector:
matchLabels:
{{- include "loki.compactorSelectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- include "loki.config.checksum" . | nindent 8 }}
{{- with .Values.loki.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compactor.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "loki.compactorSelectorLabels" . | nindent 8 }}
app.kubernetes.io/part-of: memberlist
{{- with .Values.loki.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compactor.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "loki.serviceAccountName" . }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compactor.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- include "loki.compactorPriorityClassName" . | nindent 6 }}
securityContext:
{{- toYaml .Values.loki.podSecurityContext | nindent 8 }}
terminationGracePeriodSeconds: {{ .Values.compactor.terminationGracePeriodSeconds }}
{{- with .Values.compactor.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: compactor
image: {{ include "loki.image" . }}
imagePullPolicy: {{ .Values.loki.image.pullPolicy }}
{{- if or .Values.loki.command .Values.compactor.command }}
command:
- {{ coalesce .Values.compactor.command .Values.loki.command | quote }}
{{- end }}
args:
- -config.file=/etc/loki/config/config.yaml
- -target=compactor
- -boltdb.shipper.compactor.working-directory=/var/loki/compactor
{{- with .Values.compactor.extraArgs }}
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: 3100
protocol: TCP
- name: grpc
containerPort: 9095
protocol: TCP
- name: http-memberlist
containerPort: 7946
protocol: TCP
{{- with .Values.compactor.extraEnv }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.compactor.extraEnvFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
{{- toYaml .Values.loki.containerSecurityContext | nindent 12 }}
readinessProbe:
{{- toYaml .Values.loki.readinessProbe | nindent 12 }}
livenessProbe:
{{- toYaml .Values.loki.livenessProbe | nindent 12 }}
volumeMounts:
- name: temp
mountPath: /tmp
- name: config
mountPath: /etc/loki/config
- name: runtime-config
mountPath: /etc/loki/runtime-config
- name: data
mountPath: /var/loki
{{- with .Values.compactor.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
resources:
{{- toYaml .Values.compactor.resources | nindent 12 }}
{{- if .Values.compactor.extraContainers }}
{{- toYaml .Values.compactor.extraContainers | nindent 8}}
{{- end }}
{{- with .Values.compactor.affinity }}
affinity:
{{- tpl . $ | nindent 8 }}
{{- end }}
{{- with .Values.compactor.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.compactor.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: temp
emptyDir: {}
- name: config
{{- if .Values.loki.existingSecretForConfig }}
secret:
secretName: {{ .Values.loki.existingSecretForConfig }}
{{- else }}
{{- include "loki.configVolume" . | nindent 10 }}
{{- end }}
- name: runtime-config
configMap:
name: {{ template "loki.name" . }}-runtime
{{- if .Values.enterprise.enabled }}
- name: license
secret:
{{- if .Values.enterprise.useExternalLicense }}
secretName: {{ .Values.enterprise.externalLicenseName }}
{{- else }}
secretName: enterprise-logs-license
{{- end }}
{{- end }}
- name: data
{{- if .Values.compactor.persistence.enabled }}
persistentVolumeClaim:
claimName: data-{{ include "loki.compactorFullname" . }}
{{- else }}
emptyDir: {}
{{- end }}
{{- with .Values.compactor.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{/* {{- end }} */}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- $isDistributed := eq (include "loki.deployment.isDistributed" .) "true" -}}
{{- if and $isDistributed .Values.compactor.enabled .Values.compactor.persistence.enabled }}
{{- if eq .Values.compactor.kind "Deployment"}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-{{ include "loki.compactorFullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "loki.compactorLabels" . | nindent 4 }}
{{- with .Values.compactor.persistence.annotations }}
annotations:
{{- . | toYaml | nindent 4 }}
{{- end }}
spec:
accessModes:
- ReadWriteOnce
{{- with .Values.compactor.persistence.storageClass }}
storageClassName: {{ if (eq "-" .) }}""{{ else }}{{ . }}{{ end }}
{{- end }}
resources:
requests:
storage: "{{ .Values.compactor.persistence.size }}"
{{- end }}
{{- end }}
Loading

0 comments on commit df50d2f

Please sign in to comment.