blob: 75605c27c26cb420ec56098802c1765d39117e62 [file] [log] [blame]
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00001{{- $isSimpleScalable := eq (include "loki.deployment.isScalable" .) "true" -}}
2{{- if $isSimpleScalable }}
3---
4apiVersion: apps/v1
5kind: StatefulSet
6metadata:
7 name: {{ include "loki.writeFullname" . }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -03008 namespace: {{ $.Release.Namespace }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +00009 labels:
10 {{- include "loki.writeLabels" . | nindent 4 }}
11 app.kubernetes.io/part-of: memberlist
Giovanni Tirloni59219b62024-04-09 14:50:25 -030012 {{- if or (not (empty .Values.loki.annotations)) (not (empty .Values.backend.annotations))}}
13 annotations:
14 {{- with .Values.loki.annotations }}
15 {{- toYaml . | nindent 4 }}
16 {{- end }}
17 {{- with .Values.write.annotations }}
18 {{- toYaml . | nindent 4 }}
19 {{- end }}
20 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000021spec:
Giovanni Tirloni59219b62024-04-09 14:50:25 -030022{{- if not .Values.write.autoscaling.enabled }}
Mohammed Naser65cda132024-05-02 14:34:08 -040023 {{- if eq .Values.deploymentMode "SingleBinary" }}
24 replicas: 0
25 {{- else }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000026 replicas: {{ .Values.write.replicas }}
Mohammed Naser65cda132024-05-02 14:34:08 -040027 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -030028{{- end }}
29 podManagementPolicy: {{ .Values.write.podManagementPolicy }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000030 updateStrategy:
31 rollingUpdate:
32 partition: 0
33 serviceName: {{ include "loki.writeFullname" . }}-headless
34 revisionHistoryLimit: {{ .Values.loki.revisionHistoryLimit }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -030035 {{- if and (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) (.Values.write.persistence.enableStatefulSetAutoDeletePVC) (.Values.write.persistence.volumeClaimsEnabled) }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000036 {{/*
37 Data on the write nodes is easy to replace, so we want to always delete PVCs to make
38 operation easier, and will rely on re-fetching data when needed.
39 */}}
40 persistentVolumeClaimRetentionPolicy:
41 whenDeleted: Delete
42 whenScaled: Delete
43 {{- end }}
44 selector:
45 matchLabels:
46 {{- include "loki.writeSelectorLabels" . | nindent 6 }}
47 template:
48 metadata:
49 annotations:
Giovanni Tirloni59219b62024-04-09 14:50:25 -030050 checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +000051 {{- with .Values.loki.podAnnotations }}
52 {{- toYaml . | nindent 8 }}
53 {{- end }}
54 {{- with .Values.write.podAnnotations }}
55 {{- toYaml . | nindent 8 }}
56 {{- end }}
57 labels:
58 {{- include "loki.writeSelectorLabels" . | nindent 8 }}
59 {{- with .Values.loki.podLabels }}
60 {{- toYaml . | nindent 8 }}
61 {{- end }}
62 {{- with .Values.write.podLabels }}
63 {{- toYaml . | nindent 8 }}
64 {{- end }}
65 {{- with .Values.write.selectorLabels }}
66 {{- tpl (toYaml .) $ | nindent 8 }}
67 {{- end }}
68 app.kubernetes.io/part-of: memberlist
69 spec:
70 serviceAccountName: {{ include "loki.serviceAccountName" . }}
71 automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
72 {{ include "loki.enableServiceLinks" . }}
73 {{- with .Values.imagePullSecrets }}
74 imagePullSecrets:
75 {{- toYaml . | nindent 8 }}
76 {{- end }}
77 {{- include "loki.writePriorityClassName" . | nindent 6 }}
78 securityContext:
79 {{- toYaml .Values.loki.podSecurityContext | nindent 8 }}
80 terminationGracePeriodSeconds: {{ .Values.write.terminationGracePeriodSeconds }}
81 {{- if .Values.write.initContainers }}
82 initContainers:
83 {{- with .Values.write.initContainers }}
84 {{- toYaml . | nindent 8 }}
85 {{- end }}
86 {{- end }}
87 containers:
88 - name: loki
89 image: {{ include "loki.image" . }}
90 imagePullPolicy: {{ .Values.loki.image.pullPolicy }}
91 args:
92 - -config.file=/etc/loki/config/config.yaml
93 - -target={{ .Values.write.targetModule }}
94 {{- with .Values.write.extraArgs }}
95 {{- toYaml . | nindent 12 }}
96 {{- end }}
97 ports:
98 - name: http-metrics
Giovanni Tirloni59219b62024-04-09 14:50:25 -030099 containerPort: {{ .Values.loki.server.http_listen_port }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000100 protocol: TCP
101 - name: grpc
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300102 containerPort: {{ .Values.loki.server.grpc_listen_port }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000103 protocol: TCP
104 - name: http-memberlist
105 containerPort: 7946
106 protocol: TCP
107 {{- with .Values.write.extraEnv }}
108 env:
109 {{- toYaml . | nindent 12 }}
110 {{- end }}
111 {{- with .Values.write.extraEnvFrom }}
112 envFrom:
113 {{- toYaml . | nindent 12 }}
114 {{- end }}
115 securityContext:
116 {{- toYaml .Values.loki.containerSecurityContext | nindent 12 }}
117 readinessProbe:
118 {{- toYaml .Values.loki.readinessProbe | nindent 12 }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300119 {{- if .Values.write.lifecycle }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000120 lifecycle:
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300121 {{- toYaml .Values.write.lifecycle | nindent 12 }}
122 {{- else if .Values.write.autoscaling.enabled }}
123 lifecycle:
124 preStop:
125 httpGet:
126 path: "/ingester/shutdown?terminate=false"
127 port: http-metrics
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000128 {{- end }}
129 volumeMounts:
130 - name: config
131 mountPath: /etc/loki/config
132 - name: runtime-config
133 mountPath: /etc/loki/runtime-config
134 - name: data
135 mountPath: /var/loki
136 {{- if .Values.enterprise.enabled }}
137 - name: license
138 mountPath: /etc/loki/license
Mohammed Naser65cda132024-05-02 14:34:08 -0400139 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000140 {{- with .Values.write.extraVolumeMounts }}
141 {{- toYaml . | nindent 12 }}
142 {{- end }}
143 resources:
144 {{- toYaml .Values.write.resources | nindent 12 }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300145 {{- with .Values.write.extraContainers }}
146 {{- toYaml . | nindent 8}}
147 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000148 {{- with .Values.write.affinity }}
149 affinity:
Mohammed Naser65cda132024-05-02 14:34:08 -0400150 {{- toYaml . | nindent 8 }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000151 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300152 {{- with .Values.write.dnsConfig }}
153 dnsConfig:
154 {{- tpl . $ | nindent 8 }}
155 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000156 {{- with .Values.write.nodeSelector }}
157 nodeSelector:
158 {{- toYaml . | nindent 8 }}
159 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300160 {{- with .Values.write.topologySpreadConstraints }}
161 topologySpreadConstraints:
162 {{- toYaml . | nindent 8 }}
163 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000164 {{- with .Values.write.tolerations }}
165 tolerations:
166 {{- toYaml . | nindent 8 }}
167 {{- end }}
168 volumes:
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300169 {{- if not .Values.write.persistence.volumeClaimsEnabled }}
170 - name: data
171 {{- toYaml .Values.write.persistence.dataVolumeParameters | nindent 10 }}
172 {{- end}}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000173 - name: config
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300174 {{- include "loki.configVolume" . | nindent 10 }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000175 - name: runtime-config
176 configMap:
177 name: {{ template "loki.name" . }}-runtime
178 {{- if .Values.enterprise.enabled }}
179 - name: license
180 secret:
181 {{- if .Values.enterprise.useExternalLicense }}
182 secretName: {{ .Values.enterprise.externalLicenseName }}
183 {{- else }}
184 secretName: enterprise-logs-license
185 {{- end }}
186 {{- end }}
187 {{- with .Values.write.extraVolumes }}
188 {{- toYaml . | nindent 8 }}
189 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300190 {{- if .Values.write.persistence.volumeClaimsEnabled }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000191 volumeClaimTemplates:
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300192 - apiVersion: v1
193 kind: PersistentVolumeClaim
194 metadata:
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000195 name: data
Mohammed Naser7d1623e2024-06-17 09:12:39 -0400196 {{- with .Values.write.persistence.annotations }}
197 annotations:
198 {{- toYaml . | nindent 10 }}
199 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000200 spec:
201 accessModes:
202 - ReadWriteOnce
203 {{- with .Values.write.persistence.storageClass }}
204 storageClassName: {{ if (eq "-" .) }}""{{ else }}{{ . }}{{ end }}
205 {{- end }}
206 resources:
207 requests:
208 storage: {{ .Values.write.persistence.size | quote }}
209 {{- with .Values.write.persistence.selector }}
210 selector:
211 {{- toYaml . | nindent 10 }}
212 {{- end }}
Giovanni Tirloni59219b62024-04-09 14:50:25 -0300213 {{- with .Values.write.extraVolumeClaimTemplates }}
214 {{- toYaml . | nindent 4 }}
215 {{- end }}
216 {{- end }}
Mohammed Naser8a2c8fb2023-02-19 17:23:55 +0000217{{- end }}