Giter Site home page Giter Site logo

grafana-loki-setup's Introduction

grafana-loki-setup

Grafana Loki Setup Guide in Kubernetes

Single Tenent Model (Using DaemonSet for Log Collector Client(Fluent bit Or Promtail))

  1. Install Grafana loki-distributed chart in loki namespace. It will install loki's mircoservice components.
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
helm upgrade --install loki grafana/loki-distributed -n loki --create-namespace --values=sample-values.yaml
  1. Install Fluent bit for collecting log with proper loki service name.
helm upgrade --install fluent-bit grafana/fluent-bit -n loki \
                      --set loki.serviceName=loki-loki-distributed-distributor.loki.svc

For installing promtail:

helm upgrade -i promtail grafana/promtail -n loki --set config.lokiAddress=http://loki-loki-distributed-distributor.loki.svc:3100/loki/api/v1/push
  1. Port forward grafana service & add loki data source. After that from Explore section in grafana UI, logs can be examined.

Sample:

sample-log

  1. For getting alert configure alert_manager url in .values.loki.config section & add necessary rules in .values.ruler.directories sections.

Sample rules file:

rules.yaml:
  groups:
  - name: should_fire
    rules:
      - alert: KubeDBOperatorHighFailedError
        expr: sum by (container) (rate({namespace="kubedb"} |= "Failed"[1m])) > 0.0001
        for: 1m
        labels:
            severity: warning
        annotations:
            summary: High failed error
  - name: test-rule
    rules: 
      - alert: loki-test-rule
        annotations: 
          message: "testing loki rules"
        expr: 1+1
        for: 1m
        labels: 
          severity: critical

Alert in AlertManager UI:

alert-manager-sample-ui

Setup Loki with GCS as an object storage

1.Prepare secret with GOOGLE_APPLICATIONS_CREDENTIALS.

Example:

kubectl create secret generic -n loki gcs-secret \
                    --from-file=./GOOGLE_SERVICE_ACCOUNT_JSON_KEY
  1. Configure Loki's valuse file for gcs object storage.

Sample .values.loki.schemaConfig:

  schemaConfig:
    configs:
    - from: 2020-09-07
      store: boltdb-shipper
      object_store: gcs
      schema: v11
      index:
        prefix: loki_index_
        period: 24h

Sample .values.loki.storageConfig:

  storageConfig:
    boltdb_shipper:
      shared_store: gcs
      active_index_directory: /var/loki/index
      cache_location: /var/loki/cache
      cache_ttl: 168h
    gcs:
      bucket_name: loki-testing-pulak

Sample .values.ingester section to load gcs secret path as an env.

ingester:
  ...
  ...
  extraEnv:
    - name: GOOGLE_APPLICATION_CREDENTIALS
      value: /var/secrets/google/GOOGLE_SERVICE_ACCOUNT_JSON_KEY
  # -- Environment variables from secrets or configmaps to add to the ingester pods
  extraEnvFrom: []
  # -- Volume mounts to add to the ingester pods
  extraVolumeMounts:
    - name: google-cloud-key
      mountPath: /var/secrets/google
  # -- Volumes to add to the ingester pods
  extraVolumes:
    - name: google-cloud-key
      secret:
        secretName: gcs-secret
  ...
  ...
  persistence:
    # -- Enable creating PVCs which is required when using boltdb-shipper
    enabled: true
    # -- Size of persistent disk
    size: 10Gi
    # -- Storage class to be used.
    # If defined, storageClassName: <storageClass>.
    # If set to "-", storageClassName: "", which disables dynamic provisioning.
    # If empty or set to null, no storageClassName spec is
    # set, choosing the default provisioner (gp2 on AWS, standard on GKE, AWS, and OpenStack).
    storageClass: standard

A full working values file loki-sample-values-gcp.yaml is given for example. If everything goes well, then data will be stored in gcp bucket like this:

gcp-sample

Note: Here GCS bucket will hold the index data as well as compressed log data. BoltDB shipper will upload the new files in every 15 min interval. So, to avoid data loss in case pod crash, ingester should be run with persistence data storage. (Ref: https://grafana.com/docs/loki/latest/operations/storage/boltdb-shipper/)

Data Retention Policy

In loki, Table Manager manages data deletion and retention policy.

To setup custom storage policy in gcs, Lifecycle can be used to delete older data more than a specified days. (Ref: https://cloud.google.com/storage/docs/lifecycle)

Example:

gcs-lifecycle

Setup Loki with Linode Object Storage(AWS S3 compatible) as an object storage

Configure Loki's values file for Linode Object Storage. A full working example is given in sample-values-loki-linode.yaml.

Sample .values.loki.schemaConfig:

  schemaConfig:
    configs:
    - from: 2020-09-07
      store: boltdb-shipper
      object_store: s3
      schema: v11
      index:
        prefix: loki_index_
        period: 24h

Sample .values.loki.storageConfig:

  storageConfig:
    boltdb_shipper:
      shared_store: s3
      active_index_directory: /var/loki/index
      cache_location: /var/loki/cache
      cache_ttl: 168h
    aws:
      s3: s3://access_key:secret_key@endpoint/bucket_name
      s3forcepathstyle: true

References

grafana-loki-setup's People

Contributors

pkbhowmick avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.