@@ -27,6 +27,8 @@ summary: >-
27
27
<li >Configure object storage for Loki.</li >
28
28
<li >Query logs using Grafana.</li >
29
29
</ul >
30
+ <p >For reference, <a href =" https://grafana.com/docs/loki/latest/send-data/promtail/#promtail-agent " >Promtail</a > will be deprecated.
31
+ So we introduce Alloy, which has been officially suggested by Grafana Labs as the new agent to collect Kubernetes logs and forward them to Loki.</p >
30
32
<h2 id =" Prerequisites " class =" common-anchor-header " >Prerequisites<button data-href =" #Prerequisites " class =" anchor-icon " translate =" no " >
31
33
<svg translate="no"
32
34
aria-hidden="true"
@@ -145,7 +147,7 @@ helm repo update
145
147
<pre ><code translate =" no " class =" language-shell " >kubectl create ns loki
146
148
helm install --values loki.yaml loki grafana/loki -n loki
147
149
<button class =" copy-code-btn " ></button ></code ></pre >
148
- <h2 id =" Deploy-Promtail " class =" common-anchor-header " >Deploy Promtail <button data-href =" #Deploy-Promtail " class =" anchor-icon " translate =" no " >
150
+ <h2 id =" Deploy-Alloy " class =" common-anchor-header " >Deploy Alloy <button data-href =" #Deploy-Alloy " class =" anchor-icon " translate =" no " >
149
151
<svg translate="no"
150
152
aria-hidden="true"
151
153
focusable="false"
@@ -160,8 +162,8 @@ helm install --values loki.yaml loki grafana/loki -n loki
160
162
d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"
161
163
></path>
162
164
</svg>
163
- </button></h2><p>Promtail is a log collection agent for Loki. It reads logs from Milvus pods and sends them to Loki .</p>
164
- <h3 id =" 1-Create-Promtail -Configuration " class =" common-anchor-header " >1. Create Promtail Configuration<button data-href =" #1-Create-Promtail -Configuration " class =" anchor-icon " translate =" no " >
165
+ </button></h2><p>We will show you Alloy <a href="https://grafana.com/docs/alloy/latest/configure/">Configuration</a> .</p>
166
+ <h3 id =" 1-Create-Alloy -Configuration " class =" common-anchor-header " >1. Create Alloy Configuration<button data-href =" #1-Create-Alloy -Configuration " class =" anchor-icon " translate =" no " >
165
167
<svg translate="no"
166
168
aria-hidden="true"
167
169
focusable="false"
@@ -176,12 +178,87 @@ helm install --values loki.yaml loki grafana/loki -n loki
176
178
d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"
177
179
></path>
178
180
</svg>
179
- </button></h3><p>Create a <code translate="no">promtail.yaml</code> configuration file:</p>
180
- <pre ><code translate =" no " class =" language-yaml " ><span class =" hljs-attr " >config:</span >
181
- <span class =" hljs-attr " >clients:</span >
182
- <span class =" hljs-bullet " >-</span > <span class =" hljs-attr " >url:</span > <span class =" hljs-string " >http://loki-gateway/loki/api/v1/push</span >
181
+ </button></h3><p>We will use the following <code translate="no">alloy.yaml</code> to collect logs of all Kubernetes pods & send them to Loki via loki-gateway:</p>
182
+ <pre ><code translate =" no " class =" language-yaml " ><span class =" hljs-attr " >alloy:</span >
183
+ <span class =" hljs-attr " >enableReporting:</span > <span class =" hljs-literal " >false</span >
184
+ <span class =" hljs-attr " >resources:</span > {}
185
+ <span class =" hljs-attr " >configMap:</span >
186
+ <span class =" hljs-attr " >create:</span > <span class =" hljs-literal " >true</span >
187
+ <span class =" hljs-attr " >content:</span > <span class =" hljs-string " >|-
188
+ loki.write " ; default" ; {
189
+ endpoint {
190
+ url = " ; http://loki-gateway/loki/api/v1/push" ;
191
+ }
192
+ }
193
+ </span >
194
+ <span class =" hljs-string " >discovery.kubernetes</span > <span class =" hljs-string " >" ; pod" ; </span > {
195
+ <span class =" hljs-string " >role</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; pod" ; </span >
196
+ }
197
+
198
+ <span class =" hljs-string " >loki.source.kubernetes</span > <span class =" hljs-string " >" ; pod_logs" ; </span > {
199
+ <span class =" hljs-string " >targets</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >discovery.relabel.pod_logs.output</span >
200
+ <span class =" hljs-string " >forward_to</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >loki.write.default.receiver</span >]
201
+ }
202
+
203
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >Rewrite</span > <span class =" hljs-string " >the</span > <span class =" hljs-string " >label</span > <span class =" hljs-string " >set</span > <span class =" hljs-string " >to</span > <span class =" hljs-string " >make</span > <span class =" hljs-string " >log</span > <span class =" hljs-string " >query</span > <span class =" hljs-string " >easier</span >
204
+ <span class =" hljs-string " >discovery.relabel</span > <span class =" hljs-string " >" ; pod_logs" ; </span > {
205
+ <span class =" hljs-string " >targets</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >discovery.kubernetes.pod.targets</span >
206
+ <span class =" hljs-string " >rule</span > {
207
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_namespace" ; </span >]
208
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
209
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; namespace" ; </span >
210
+ }
211
+
212
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >" ; pod" ; </span > <span class =" hljs-string " >< ; -</span > <span class =" hljs-string " >" ; __meta_kubernetes_pod_name" ; </span >
213
+ <span class =" hljs-string " >rule</span > {
214
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_pod_name" ; </span >]
215
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
216
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; pod" ; </span >
217
+ }
218
+
219
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >" ; container" ; </span > <span class =" hljs-string " >< ; -</span > <span class =" hljs-string " >" ; __meta_kubernetes_pod_container_name" ; </span >
220
+ <span class =" hljs-string " >rule</span > {
221
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_pod_container_name" ; </span >]
222
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
223
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; container" ; </span >
224
+ }
225
+
226
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >" ; app" ; </span > <span class =" hljs-string " >< ; -</span > <span class =" hljs-string " >" ; __meta_kubernetes_pod_label_app_kubernetes_io_name" ; </span >
227
+ <span class =" hljs-string " >rule</span > {
228
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_pod_label_app_kubernetes_io_name" ; </span >]
229
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
230
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; app" ; </span >
231
+ }
232
+
233
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >" ; job" ; </span > <span class =" hljs-string " >< ; -</span > <span class =" hljs-string " >" ; __meta_kubernetes_namespace" ; </span >, <span class =" hljs-string " >" ; __meta_kubernetes_pod_container_name" ; </span >
234
+ <span class =" hljs-string " >rule</span > {
235
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_namespace" ; </span >, <span class =" hljs-string " >" ; __meta_kubernetes_pod_container_name" ; </span >]
236
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
237
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; job" ; </span >
238
+ <span class =" hljs-string " >separator</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; /" ; </span >
239
+ <span class =" hljs-string " >replacement</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; $1" ; </span >
240
+ }
241
+
242
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >L" ; __path__" ; </span > <span class =" hljs-string " >< ; -</span > <span class =" hljs-string " >" ; __meta_kubernetes_pod_uid" ; </span >, <span class =" hljs-string " >" ; __meta_kubernetes_pod_container_name" ; </span >
243
+ <span class =" hljs-string " >rule</span > {
244
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_pod_uid" ; </span >, <span class =" hljs-string " >" ; __meta_kubernetes_pod_container_name" ; </span >]
245
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
246
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; __path__" ; </span >
247
+ <span class =" hljs-string " >separator</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; /" ; </span >
248
+ <span class =" hljs-string " >replacement</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; /var/log/pods/*$1/*.log" ; </span >
249
+ }
250
+
251
+ <span class =" hljs-string " >//</span > <span class =" hljs-string " >" ; container_runtime" ; </span > <span class =" hljs-string " >< ; -</span > <span class =" hljs-string " >" ; __meta_kubernetes_pod_container_id" ; </span >
252
+ <span class =" hljs-string " >rule</span > {
253
+ <span class =" hljs-string " >source_labels</span > <span class =" hljs-string " >=</span > [<span class =" hljs-string " >" ; __meta_kubernetes_pod_container_id" ; </span >]
254
+ <span class =" hljs-string " >action</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; replace" ; </span >
255
+ <span class =" hljs-string " >target_label</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; container_runtime" ; </span >
256
+ <span class =" hljs-string " >regex</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; ^(\\S+):\\/\\/.+$" ; </span >
257
+ <span class =" hljs-string " >replacement</span > <span class =" hljs-string " >=</span > <span class =" hljs-string " >" ; $1" ; </span >
258
+ }
259
+ }
183
260
<button class =" copy-code-btn " ></button ></code ></pre >
184
- <h3 id =" 2-Install-Promtail " class =" common-anchor-header " >2. Install Promtail <button data-href =" #2-Install-Promtail " class =" anchor-icon " translate =" no " >
261
+ <h3 id =" 2-Install-Alloy " class =" common-anchor-header " >2. Install Alloy <button data-href =" #2-Install-Alloy " class =" anchor-icon " translate =" no " >
185
262
<svg translate="no"
186
263
aria-hidden="true"
187
264
focusable="false"
@@ -196,8 +273,7 @@ helm install --values loki.yaml loki grafana/loki -n loki
196
273
d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"
197
274
></path>
198
275
</svg>
199
- </button></h3><p>Install Promtail using Helm:</p>
200
- <pre ><code translate =" no " class =" language-shell " >helm install --values promtail.yaml promtail grafana/promtail -n loki
276
+ </button></h3><pre><code translate="no" class="language-shell">helm install --values promtail.yaml promtail grafana/promtail -n loki
201
277
<button class =" copy-code-btn " ></button ></code ></pre >
202
278
<h2 id =" Query-Logs-with-Grafana " class =" common-anchor-header " >Query Logs with Grafana<button data-href =" #Query-Logs-with-Grafana " class =" anchor-icon " translate =" no " >
203
279
<svg translate="no"
0 commit comments