菜单
文档breadcrumb arrow Grafana Lokibreadcrumb arrow 设置breadcrumb arrow 安装breadcrumb arrow 使用 Tanka 安装
开源

Tanka

您可以使用 Grafana Cloud 来避免自行安装、维护和扩展 Grafana Loki 实例。 创建免费账户以开始使用,其中包含永久免费的 1万个指标、50GB 日志、50GB 追踪、500 VUh k6 测试等。

TankaKsonnet 的重新实现,由 Grafana Labs 在 Ksonnet 被弃用后创建。Grafana Labs 使用 Tanka 在生产环境中运行 Grafana Loki。

Tanka 安装在微服务模式下运行 Loki 集群。

先决条件

安装最新版本的 Tanka(v0.31.0 或更新版本)以使用 tk env 命令。Tanka 的预构建二进制文件可在 Tanka 发布 URL 中找到。

在您的配置仓库中,如果您还没有 Tanka 应用程序,请创建一个文件夹并在其中运行 tk init。然后为 Loki 创建一个环境并提供要部署到的 Kubernetes API 服务器 URL(例如,https://:6443

mkdir <application name>
cd <application name>
tk init
tk env add environments/loki --namespace=loki --server=<Kubernetes API server>

安装 jsonnet-bundler (jb),请在 Tanka 的安装文档中找到适用于您平台的说明。

部署

使用 jb(v0.6.0 或更新版本)下载并安装 Loki 和 Promtail 模块

bash
jb init  # not required if you already ran `tk init`
jb install github.com/grafana/loki/production/ksonnet/loki@main
jb install github.com/grafana/loki/production/ksonnet/promtail@main

修改 environments/loki/main.jsonnet 的 YAML 内容,更新这些变量

  • 更新 usernamepassword 和相应的 htpasswd 变量值。
  • 根据您的对象存储类型,更新 S3 或 GCS 变量值。有关更多配置详情,请参阅 storage_config
  • 从配置中移除不属于您设置的 S3 或 GCS 对象存储变量。
  • 更新 Promtail 配置中 container_root_path 变量的值,使其反映 Docker 守护进程的根路径。运行 docker info | grep "Root Dir" 获取您的根路径。
  • 更新 Loki schema_config 部分的 from 值,使其不超过当前日期之前的 14 天。from 日期表示 schema_config 部分有效的起始日期。例如,如果今天是 2021-01-15,则将 from 设置为 2021-01-01。此建议基于 Loki 默认接受过去 14 天内的日志行。reject_old_samples_max_age 配置变量控制接受范围。
jsonnet
local gateway = import 'loki/gateway.libsonnet';
local loki = import 'loki/loki.libsonnet';
local promtail = import 'promtail/promtail.libsonnet';

loki + promtail + gateway {
  _config+:: {
    namespace: 'loki',
    htpasswd_contents: 'loki:$apr1$H4yGiGNg$ssl5/NymaGFRUvxIV1Nyr.',

    // S3 variables -- Remove if not using s3
    storage_backend: 's3,dynamodb',
    s3_access_key: 'key',
    s3_secret_access_key: 'secret access key',
    s3_address: 'url',
    s3_bucket_name: 'loki-test',
    dynamodb_region: 'region',

    // GCS variables -- Remove if not using gcs
    storage_backend: 'bigtable,gcs',
    bigtable_instance: 'instance',
    bigtable_project: 'project',
    gcs_bucket_name: 'bucket',

    //Update the object_store and from fields
    loki+: {
      schema_config: {
        configs: [{
          from: 'YYYY-MM-DD',
          store: 'boltdb-shipper',
          object_store: 'my-object-storage-backend-type',
          schema: 'v11',
          index: {
            prefix: '%s_index_' % $._config.table_prefix,
            period: '%dh' % $._config.index_period_hours,
          },
        }],
      },
    },

    //Update the container_root_path if necessary
    promtail_config+: {
      clients: [{
        scheme:: 'http',
        hostname:: 'gateway.%(namespace)s.svc' % $._config,
        username:: 'loki',
        password:: 'password',
        container_root_path:: '/var/lib/docker',
      }],
    },

    replication_factor: 3,
    consul_replicas: 1,
  },
}

运行 tk show environments/loki 以查看将要部署到集群的清单。运行 tk apply environments/loki 以部署清单。要从集群中删除环境,请运行 tk delete environments/loki