安装单体 Helm chart
您可以使用 Grafana Cloud 来避免安装、维护和扩展您自己的 Grafana Loki 实例。创建免费账户开始使用,包含永久免费的 1 万指标、50GB 日志、50GB 追踪、500VUh k6 测试等。
此 Helm Chart 安装将在 Kubernetes 集群中以单体模式部署 Grafana Loki。
先决条件
- Helm 3 或更高版本。请参阅安装 Helm。
- 一个正在运行的 Kubernetes 集群。
单副本或多副本
有两种方式可以在单体模式下部署 Loki
- 单副本:使用单个副本运行 Loki。此模式适用于测试和开发,或者如果您计划将 Loki 作为元监控系统运行。
- 多副本:使用多个副本运行 Loki。此模式适用于高可用性。与微服务模式相比,此模式经济性较差,但操作更简单。我们建议运行至少三个副本以实现高可用性。
选择好要部署的副本数量后,选择下面相应的 values.yaml
配置文件,然后继续部署步骤。
单副本
使用单副本部署 Helm chart 会部署以下组件
- Loki (1 个副本)
- Loki Canary (1 个 DaemonSet)
- Loki Gateway (1 个 NGINX 副本)
- Loki Chunk 和 Result Cache (1 个 DaemonSet)
- Minio(可选,如果
minio.enabled=true
)
创建配置文件 values.yaml
注意
如果您只使用 1 个副本,则必须指定
commonConfig.replication_factor: 1
,否则请求将失败。
loki:
commonConfig:
replication_factor: 1
schemaConfig:
configs:
- from: "2024-04-01"
store: tsdb
object_store: s3
schema: v13
index:
prefix: loki_index_
period: 24h
pattern_ingester:
enabled: true
limits_config:
allow_structured_metadata: true
volume_enabled: true
ruler:
enable_api: true
minio:
enabled: true
deploymentMode: SingleBinary
singleBinary:
replicas: 1
# Zero out replica counts of other deployment modes
backend:
replicas: 0
read:
replicas: 0
write:
replicas: 0
ingester:
replicas: 0
querier:
replicas: 0
queryFrontend:
replicas: 0
queryScheduler:
replicas: 0
distributor:
replicas: 0
compactor:
replicas: 0
indexGateway:
replicas: 0
bloomCompactor:
replicas: 0
bloomGateway:
replicas: 0
在此配置中,我们将 Loki 与 MinIO 一起部署作为对象存储。我们建议通过云提供商配置对象存储或将 Loki 指向 MinIO 集群用于生产部署。
多副本
使用多副本部署 Helm chart 会部署以下组件
- Loki (3 个副本)
- Loki Canary (1 个 DaemonSet)
- Loki Gateway (1 个 NGINX 副本)
- Loki Chunk 和 Result Cache (1 个 DaemonSet)
- Minio(可选,如果
minio.enabled=true
)
创建配置文件 values.yaml
注意
如果您将
singleBinary.replicas
值设置为 2 或更多,此 chart 会将 Loki 配置为以单一二进制文件以复制、高可用模式运行。运行单个二进制文件的副本时,您必须配置对象存储。
loki:
commonConfig:
replication_factor: 3
schemaConfig:
configs:
- from: "2024-04-01"
store: tsdb
object_store: s3
schema: v13
index:
prefix: loki_index_
period: 24h
pattern_ingester:
enabled: true
limits_config:
allow_structured_metadata: true
volume_enabled: true
ruler:
enable_api: true
minio:
enabled: true
deploymentMode: SingleBinary
singleBinary:
replicas: 3
# Zero out replica counts of other deployment modes
backend:
replicas: 0
read:
replicas: 0
write:
replicas: 0
ingester:
replicas: 0
querier:
replicas: 0
queryFrontend:
replicas: 0
queryScheduler:
replicas: 0
distributor:
replicas: 0
compactor:
replicas: 0
indexGateway:
replicas: 0
bloomCompactor:
replicas: 0
bloomGateway:
replicas: 0
在此配置中,我们需要确保将 commonConfig.replication_factor
和 singleBinary.replicas
更新为所需的副本数量。我们将 Loki 与 MinIO 一起部署作为对象存储。我们建议通过云提供商配置对象存储或将 Loki 指向 MinIO 集群用于生产部署。
为开发和测试部署 Helm chart
将Grafana 的 chart 仓库添加到 Helm
helm repo add grafana https://grafana.github.io/helm-charts
更新 chart 仓库
helm repo update
使用配置文件
values.yaml
部署 Lokihelm install loki grafana/loki -f values.yaml
安装或升级 Loki 部署。
- 安装
helm install --values values.yaml loki grafana/loki
- 升级
helm upgrade --values values.yaml loki grafana/loki
- 安装
验证 Loki 正在运行
kubectl get pods -n loki
对象存储配置
在使用 MinIO 测试 Loki 后,我们建议使用对象存储提供商配置 Loki。以下示例显示了如何使用不同的对象存储提供商配置 Loki
注意
使用 S3 存储部署 Loki 时不要使用默认 bucket 名称;
chunk
、ruler
和admin
。为每个 bucket 选择一个唯一的名称。有关更多信息,请参阅以下安全更新。当您使用 MinIO 时,此注意事项不适用。使用 MinIO 时,我们建议使用默认 bucket 名称。
loki:
commonConfig:
replication_factor: 3
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 exaxmple, `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
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 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: {}
# Disable minio storage
minio:
enabled: false
deploymentMode: SingleBinary
singleBinary:
replicas: 3
persistence:
storageClass: gp2
accessModes:
- ReadWriteOnce
size: 30Gi
# Zero out replica counts of other deployment modes
backend:
replicas: 0
read:
replicas: 0
write:
replicas: 0
ingester:
replicas: 0
querier:
replicas: 0
queryFrontend:
replicas: 0
queryScheduler:
replicas: 0
distributor:
replicas: 0
compactor:
replicas: 0
indexGateway:
replicas: 0
bloomCompactor:
replicas: 0
bloomGateway:
replicas: 0
loki:
schemaConfig:
configs:
- from: "2024-04-01"
store: tsdb
object_store: azure
schema: v13
index:
prefix: loki_index_
period: 24h
ingester:
chunk_encoding: snappy
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"
# Disable minio storage
minio:
enabled: false
deploymentMode: SingleBinary
singleBinary:
replicas: 3
persistence:
storageClass: gp2
accessModes:
- ReadWriteOnce
size: 30Gi
# Zero out replica counts of other deployment modes
backend:
replicas: 0
read:
replicas: 0
write:
replicas: 0
ingester:
replicas: 0
querier:
replicas: 0
queryFrontend:
replicas: 0
queryScheduler:
replicas: 0
distributor:
replicas: 0
compactor:
replicas: 0
indexGateway:
replicas: 0
bloomCompactor:
replicas: 0
bloomGateway:
replicas: 0
要配置其他存储提供商,请参阅Helm Chart 参考。
将 Loki Helm chart 部署到生产环境
注意
我们正在积极提供更多关于在生产环境中部署 Loki 的指南。
我们建议在 AWS、Azure 或 GCP 等云环境中大规模运行 Loki。以下指南将向您展示如何部署一个最低可行生产环境。
后续步骤
- 配置一个代理来将日志数据发送到 Loki。
- 使用元监控 Helm chart 监控 Loki 部署。