安装微服务 Helm Chart
此 Helm Chart 在 Kubernetes 上部署 Grafana Loki。
此 Helm Chart 部署 Loki 以在 Kubernetes 集群中以微服务模式运行 Loki。微服务部署模式将 Loki 的组件作为独立进程运行。
默认 Helm Chart 部署以下组件
- Compactor 组件(1 个副本):压缩和处理存储的数据。
- Distributor 组件(3 个副本,maxUnavailable: 2):分发传入请求。更新期间最多允许 2 个副本不可用。
- IndexGateway 组件(2 个副本,maxUnavailable: 1):处理索引。更新期间最多允许 1 个副本不可用。
- Ingester 组件(3 个副本):处理数据摄取。
- Querier 组件(3 个副本,maxUnavailable: 2):处理查询。更新期间最多允许 2 个副本不可用。
- QueryFrontend 组件(2 个副本,maxUnavailable: 1):管理前端查询。更新期间最多允许 1 个副本不可用。
- QueryScheduler 组件(2 个副本):调度查询。
注意
我们不建议在微服务模式下使用
filesystem
存储。为了本指南的目的,我们将使用 MinIO 作为对象存储来提供一个完整的示例。
先决条件
- Helm 3 或更高版本。请参阅 安装 Helm。
- 一个正在运行的 Kubernetes 集群(必须至少有 3 个节点)。
部署 Helm Chart 用于开发和测试
将 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: Distributed ingester: replicas: 3 # To ensure data durability with replication zoneAwareReplication: enabled: false querier: replicas: 3 # Improve query performance via parallelism maxUnavailable: 2 queryFrontend: replicas: 2 maxUnavailable: 1 queryScheduler: replicas: 2 distributor: replicas: 3 maxUnavailable: 2 compactor: replicas: 1 indexGateway: replicas: 2 maxUnavailable: 1 bloomPlanner: replicas: 0 bloomBuilder: replicas: 0 bloomGateway: replicas: 0 backend: replicas: 0 read: replicas: 0 write: replicas: 0 singleBinary: replicas: 0 # This exposes the Loki gateway so it can be written to and queried externaly gateway: service: type: LoadBalancer # Enable minio for storage minio: enabled: true
安装或升级 Loki 部署。
- 安装命令
helm install --values values.yaml loki grafana/loki
- 升级命令
helm upgrade --values values.yaml loki grafana/loki
- 安装命令
验证 Loki 是否正在运行
kubectl get pods -n loki
输出应类似于以下内容
loki-canary-8thrx 1/1 Running 0 167m loki-canary-h965l 1/1 Running 0 167m loki-canary-th8kb 1/1 Running 0 167m loki-chunks-cache-0 2/2 Running 0 167m loki-compactor-0 1/1 Running 0 167m loki-compactor-1 1/1 Running 0 167m loki-distributor-7c9bb8f4dd-bcwc5 1/1 Running 0 167m loki-distributor-7c9bb8f4dd-jh9h8 1/1 Running 0 167m loki-distributor-7c9bb8f4dd-np5dw 1/1 Running 0 167m loki-gateway-77bc447887-qgc56 1/1 Running 0 167m loki-index-gateway-0 1/1 Running 0 167m loki-index-gateway-1 1/1 Running 0 166m loki-ingester-zone-a-0 1/1 Running 0 167m loki-ingester-zone-b-0 1/1 Running 0 167m loki-ingester-zone-c-0 1/1 Running 0 167m loki-minio-0 1/1 Running 0 167m loki-querier-bb8695c6d-bv9x2 1/1 Running 0 167m loki-querier-bb8695c6d-bz2rw 1/1 Running 0 167m loki-querier-bb8695c6d-z9qf8 1/1 Running 0 167m loki-query-frontend-6659566b49-528j5 1/1 Running 0 167m loki-query-frontend-6659566b49-84jtx 1/1 Running 0 167m loki-query-frontend-6659566b49-9wfr7 1/1 Running 0 167m loki-query-scheduler-f6dc4b949-fknfk 1/1 Running 0 167m loki-query-scheduler-f6dc4b949-h4nwh 1/1 Running 0 167m loki-query-scheduler-f6dc4b949-scfwp 1/1 Running 0 167m loki-results-cache-0 2/2 Running 0 167m
对象存储配置
在使用 MinIO 测试 Loki 后,我们建议为 Loki 配置对象存储提供商。以下示例展示了如何使用不同的对象存储提供商配置 Loki
注意
使用 S3 存储部署 Loki 时,切勿使用默认的存储桶名称:
chunk
、ruler
和admin
。请为每个存储桶选择一个唯一的名称。更多信息请参阅此安全更新。此注意事项不适用于使用 MinIO 的情况。使用 MinIO 时,我们建议使用默认存储桶名称。
# Example configuration for Loki with S3 storage
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
ingester:
chunk_encoding: snappy
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 storage 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: Distributed
# Disable minio storage
minio:
enabled: false
ingester:
replicas: 3
zoneAwareReplication:
enabled: false
querier:
replicas: 3
maxUnavailable: 2
queryFrontend:
replicas: 2
maxUnavailable: 1
queryScheduler:
replicas: 2
distributor:
replicas: 3
maxUnavailable: 2
compactor:
replicas: 1
indexGateway:
replicas: 2
maxUnavailable: 1
bloomPlanner:
replicas: 0
bloomBuilder:
replicas: 0
bloomGateway:
replicas: 0
backend:
replicas: 0
read:
replicas: 0
write:
replicas: 0
singleBinary:
replicas: 0
# Example configuration for Loki with Azure Blob Storage
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: Distributed
ingester:
replicas: 3
zoneAwareReplication:
enabled: false
querier:
replicas: 3
maxUnavailable: 2
queryFrontend:
replicas: 2
maxUnavailable: 1
queryScheduler:
replicas: 2
distributor:
replicas: 3
maxUnavailable: 2
compactor:
replicas: 1
indexGateway:
replicas: 2
maxUnavailable: 1
bloomPlanner:
replicas: 0
bloomBuilder:
replicas: 0
bloomGateway:
replicas: 0
backend:
replicas: 0
read:
replicas: 0
write:
replicas: 0
singleBinary:
replicas: 0
要配置其他存储提供商,请参考 Helm Chart 参考。
将 Loki Helm Chart 部署到生产环境
注意
我们正在积极提供更多关于在生产环境中部署 Loki 的指南。
我们建议在 AWS、Azure 或 GCP 等云环境中大规模运行 Loki。以下指南将向您展示如何部署一个最小可用的生产环境。
下一步
- 配置 Agent 向 Loki 发送日志数据。
- 使用 Meta 监控 Helm Chart 监控 Loki 部署