Installing Loki with Tanka

Tanka is a reimplementation ofKsonnet that Grafana Labs created after Ksonnet wasdeprecated. Tanka is used by Grafana Labs to run Loki in production.

Prerequisites

Grab the latest version of Tanka (at least version v0.5.0) for the tk envcommands. Prebuilt binaries for Tanka can be found at the Tanka releasesURL.

In your config repo, if you don’t have a Tanka application, create a folder andcall tk init inside of it. Then create an environment for Loki and provide theURL for the Kubernetes API server to deploy to (e.g., https://localhost:6443):

  1. $ mkdir <application name>
  2. $ cd <application name>
  3. $ tk init
  4. $ tk env add environments/loki --namespace=loki --server=<Kubernetes API server>

Deploying

Grab the Loki module using jb:

  1. $ go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
  2. $ jb install github.com/grafana/loki/production/ksonnet/loki

Be sure to replace the username, password and the relevant htpasswd contents.Making sure to set the value for username, password, and htpasswd properly,replace the contents of environments/loki/main.jsonnet with:

  1. local gateway = import 'loki/gateway.libsonnet';
  2. local loki = import 'loki/loki.libsonnet';
  3. local promtail = import 'promtail/promtail.libsonnet';
  4. loki + promtail + gateway {
  5. _config+:: {
  6. namespace: 'loki',
  7. htpasswd_contents: 'loki:$apr1$H4yGiGNg$ssl5/NymaGFRUvxIV1Nyr.',
  8. promtail_config: {
  9. scheme: 'http',
  10. hostname: 'gateway.%(namespace)s.svc' % $._config,
  11. username: 'loki',
  12. password: 'password',
  13. container_root_path: '/var/lib/docker',
  14. },
  15. replication_factor: 3,
  16. consul_replicas: 1,
  17. },
  18. }

Notice that container_root_path is your own data root for the Docker Daemon,run docker info | grep "Root Dir" to get it.

Run tk show environments/loki to see the manifests that will be deployed to the cluster andfinally run tk apply environments/loki to deploy it.