安装简单可扩展的 Helm chart
您可以使用 Grafana Cloud 来避免自行安装、维护和扩展 Grafana Loki 实例。创建免费账户即可开始使用,其中包括永久免费访问 1 万指标、50GB 日志、50GB 追踪、500 VUh k6 测试等功能。
此 Helm Chart 将 Grafana Loki 部署到 Kubernetes 集群中,采用简单可扩展模式。
此 chart 配置 Loki 在可扩展模式下运行 read
、write
和 backend
目标。Loki 的简单可扩展部署模式将执行路径分离为 read、write 和 backend 目标。
默认 Helm chart 部署以下组件
- Read 组件 (3 个副本)
- Write 组件 (3 个副本)
- Backend 组件 (3 个副本)
- Loki Canary (1 个 DaemonSet)
- Gateway (1 个 NGINX 副本)
- Minio (可选,如果
minio.enabled=true
) - 索引和 Chunk 缓存 (1 个副本)
注意
我们不推荐使用
filesystem
存储运行可扩展模式。为了本指南的目的,我们将使用 MinIO 作为对象存储来提供一个完整示例。
先决条件
- Helm 3 或更高版本。请参阅安装 Helm。
- 一个正在运行的 Kubernetes 集群(必须至少有 3 个节点)。
为开发和测试部署 Helm chart
以下步骤展示如何使用附带的 MinIO 作为存储后端,以简单可扩展模式部署 Loki Helm chart。我们建议从这里开始进行开发和测试。然后在迁移到生产环境时,使用对象存储提供商配置 Loki。
将Grafana 的 chart 仓库添加到 Helm
helm repo add grafana https://grafana.github.io/helm-charts
更新 chart 仓库
helm repo update
创建配置文件
values.yaml
。以下示例展示如何使用 MinIO 作为存储,以测试模式部署 Lokiloki: schemaConfig: configs: - from: "2024-04-01" store: tsdb object_store: s3 schema: v13 index: prefix: loki_index_ period: 24h ingester: chunk_encoding: snappy querier: # Default is 4, if you have enough memory and CPU you can increase, reduce if OOMing max_concurrent: 4 pattern_ingester: enabled: true limits_config: allow_structured_metadata: true volume_enabled: true deploymentMode: SimpleScalable backend: replicas: 2 read: replicas: 2 write: replicas: 3 # To ensure data durability with replication # Enable minio for storage minio: enabled: true gateway: service: type: LoadBalancer
安装或升级 Loki 部署。
- 安装
helm install --values values.yaml loki grafana/loki
- 升级
helm upgrade --values values.yaml loki grafana/loki
- 安装
对象存储配置
在测试 Loki 与 MinIO 集成后,我们建议使用对象存储提供商来配置 Loki。以下示例展示了如何使用不同的对象存储提供商来配置 Loki
注意
当使用 S3 存储部署 Loki 时,请勿使用默认 bucket 名称;
chunk
、ruler
和admin
。为每个 bucket 选择一个唯一的名称。更多信息请参阅以下安全更新。当您使用 MinIO 时,此注意事项不适用。使用 MinIO 时,我们建议使用默认 bucket 名称。
loki:
schemaConfig:
configs:
- from: "2024-04-01"
store: tsdb
object_store: s3
schema: v13
index:
prefix: loki_index_
period: 24h
storage_config:
aws:
region: <AWS region your bucket is in, for example, `eu-west-2`>
bucketnames: <Your AWS bucket for chunk, for example, `aws-loki-dev-chunk`>
s3forcepathstyle: false
pattern_ingester:
enabled: true
limits_config:
allow_structured_metadata: true
volume_enabled: true
retention_period: 672h # 28 days retention
querier:
max_concurrent: 4
storage:
type: s3
bucketNames:
chunks: <Your AWS bucket for chunk, for example, `aws-loki-dev-chunk`>
ruler: <Your AWS bucket for ruler, for example, `aws-loki-dev-ruler`>
admin: <Your AWS bucket for admin, for example, `aws-loki-dev-admin`>
s3:
# s3 URL can be used to specify the endpoint, access key, secret key, and bucket name this works well for S3 compatible storages or if you are hosting Loki on-premises and want to use S3 as the storage backend. Either use the s3 URL or the individual fields below (AWS endpoint, region, secret).
s3: s3://access_key:secret_access_key@custom_endpoint/bucket_name
# AWS endpoint URL
endpoint: <your-endpoint>
# AWS region where the S3 bucket is located
region: <your-region>
# AWS secret access key
secretAccessKey: <your-secret-access-key>
# AWS access key ID
accessKeyId: <your-access-key-id>
# AWS signature version (e.g., v2 or v4)
signatureVersion: <your-signature-version>
# Forces the path style for S3 (true/false)
s3ForcePathStyle: false
# Allows insecure (HTTP) connections (true/false)
insecure: false
# HTTP configuration settings
http_config: {}
deploymentMode: SimpleScalable
backend:
replicas: 3
read:
replicas: 3
write:
replicas: 3
# Disable minio storage
minio:
enabled: false
loki:
schemaConfig:
configs:
- from: "2024-04-01"
store: tsdb
object_store: azure
schema: v13
index:
prefix: loki_index_
period: 24h
ingester:
chunk_encoding: snappy
tracing:
enabled: true
querier:
max_concurrent: 4
storage:
type: azure
azure:
# Name of the Azure Blob Storage account
accountName: <your-account-name>
# Key associated with the Azure Blob Storage account
accountKey: <your-account-key>
# Comprehensive connection string for Azure Blob Storage account (Can be used to replace endpoint, accountName, and accountKey)
connectionString: <your-connection-string>
# Flag indicating whether to use Azure Managed Identity for authentication
useManagedIdentity: false
# Flag indicating whether to use a federated token for authentication
useFederatedToken: false
# Client ID of the user-assigned managed identity (if applicable)
userAssignedId: <your-user-assigned-id>
# Timeout duration for requests made to the Azure Blob Storage account (in seconds)
requestTimeout: <your-request-timeout>
# Domain suffix of the Azure Blob Storage service endpoint (e.g., core.windows.net)
endpointSuffix: <your-endpoint-suffix>
bucketNames:
chunks: "chunks"
ruler: "ruler"
admin: "admin"
deploymentMode: SimpleScalable
backend:
replicas: 3
read:
replicas: 3
write:
replicas: 3
# Disable minio storage
minio:
enabled: false
要配置其他存储提供商,请参阅Helm Chart 参考。
后续步骤
- 配置 agent 将日志数据发送到 Loki。
- 使用Meta Monitoring Helm chart监控 Loki 部署