「Loki」- Official Helm Chart | on Kubernetes

认识

官网:https://github.com/grafana/loki/tree/main/production/helm/loki
文档:https://grafana.com/docs/loki/latest/setup/install/helm/
仓库:https://github.com/grafana/loki/tree/main/production/helm

Helm chart for Grafana Loki and Grafana Enterprise Logs supporting monolithic, simple scalable, and microservices modes. 简而言之,该 Helm Chart 用于部署 Grafana Loki OSS 服务。

补充说明:loki-distributed | https://github.com/grafana/helm-charts/tree/main/charts/loki-distributed | Deprecation Notice | This chart is deprecated and will no longer receive updates or support. Please consider using the loki chart instead, which provides comprehensive features and ongoing maintenance.

性质

  • 提供 Monolithic 部署模式
  • 提供 Simple Scalable 部署模式
  • 提供 Microservices 部署模式

构建

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update grafana

helm search repo grafana/loki
helm pull grafana/loki

应用

Install the microservice Helm chart

nameOverride: loki
fullnameOverride: loki

deploymentMode: Distributed

loki.storage.type: s3

gateway.basicAuth:
gateway.ingress:

loki.commonConfig.replication_factor: 1 // https://github.com/grafana/loki/issues/8899

helm upgrade –install loki ./loki…

Release "loki" does not exist. Installing it now.
NAME: loki
LAST DEPLOYED: Wed Nov 12 20:23:18 2025
NAMESPACE: observing-system
STATUS: deployed
REVISION: 1
NOTES:
***********************************************************************
 Welcome to Grafana Loki
 Chart version: 6.46.0
 Chart Name: loki
 Loki version: 3.5.7
***********************************************************************

** Please be patient while the chart is being deployed **

Tip:

  Watch the deployment status using the command: kubectl get pods -w --namespace observing-system

If pods are taking too long to schedule make sure pod affinity can be fulfilled in the current cluster.

***********************************************************************
Installed components:
***********************************************************************
* gateway
* compactor
* index gateway
* query scheduler
* ruler
* distributor
* ingester
* querier
* query frontend


***********************************************************************
Sending logs to Loki
***********************************************************************

Loki has been configured with a gateway (nginx) to support reads and writes from a single component.

You can send logs from inside the cluster using the cluster DNS:

http://loki-gateway.observing-system.svc.cluster.local/loki/api/v1/push

You can test to send data from outside the cluster by port-forwarding the gateway to your local machine:

  kubectl port-forward --namespace observing-system svc/loki-gateway 3100:80 &

And then using http://127.0.0.1:3100/loki/api/v1/push URL as shown below:

```
curl -H "Content-Type: application/json" -XPOST -s "http://127.0.0.1:3100/loki/api/v1/push"  \
--data-raw "{\"streams\": [{\"stream\": {\"job\": \"test\"}, \"values\": [[\"$(date +%s)000000000\", \"fizzbuzz\"]]}]}" \
-H X-Scope-OrgId:foo
```

Then verify that Loki did receive the data using the following command:

```
curl "http://127.0.0.1:3100/loki/api/v1/query_range" --data-urlencode 'query={job="test"}' -H X-Scope-OrgId:foo | jq .data.result
```

***********************************************************************
Connecting Grafana to Loki
***********************************************************************

If Grafana operates within the cluster, you'll set up a new Loki datasource by utilizing the following URL:

http://loki-gateway.observing-system.svc.cluster.local/

***********************************************************************
Multi-tenancy
***********************************************************************

Loki is configured with auth enabled (multi-tenancy) and expects tenant headers (`X-Scope-OrgID`) to be set for all API calls.

You must configure Grafana's Loki datasource using the `HTTP Headers` section with the `X-Scope-OrgID` to target a specific tenant.
For each tenant, you can create a different datasource.

The agent of your choice must also be configured to propagate this header.
For example, when using Promtail you can use the `tenant` stage. https://grafana.com/docs/loki/latest/send-data/promtail/stages/tenant/

When not provided with the `X-Scope-OrgID` while auth is enabled, Loki will reject reads and writes with a 404 status code `no org id`.

You can also use a reverse proxy, to automatically add the `X-Scope-OrgID` header as suggested by https://grafana.com/docs/loki/latest/operations/authentication/

For more information, read our documentation about multi-tenancy: https://grafana.com/docs/loki/latest/operations/multi-tenancy/

> When using curl you can pass `X-Scope-OrgId` header using `-H X-Scope-OrgId:foo` option, where foo can be replaced with the tenant of your choice.