Deploying PLG stack on kubernetes

Deploying PLG stack on kubernetes

2022-10-11 | devops, kubernetes, infrastructure

Objective #

Deploy the Promtail-Loki-Grafana stack on a Kubernetes cluster using Helm. Heavily based on the video guide and docs found in references.

Set up the required helm charts #

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

To save the default values of a helm chart, run:

helm show values grafana/loki-stack > values.yaml

Update helm values file #

# P of the PLG stack - Promtail
promtail:
  enabled: true
  config:
    logLevel: info
    serverPort: 3101
    clients:
      - url: http://{{ .Release.Name }}:3100/loki/api/v1/push

# L of the PLG stack - Loki
loki:
  enabled: true
  persistence:
    enabled: false # disabled!
    # storageClassName: nfs-client # if following the same tutorial
    # size: 1Gi # as above
  isDefault: true
  url: http://{{(include "loki.serviceName" .)}}:{{ .Values.loki.service.port }}
  readinessProbe:
    httpGet:
      path: /ready
      port: http-metrics
    initialDelaySeconds: 45
  livenessProbe:
    httpGet:
      path: /ready
      port: http-metrics
    initialDelaySeconds: 45
  datasource:
    jsonData: {}
    uid: ""

# G of the PLG stack - Grafana
grafana:
  enabled: true
  sidecar:
    datasources:
      enabled: true
      maxLines: 1000
  image:
    tag: 8.3.5
  adminPassword: "very secret admin pass"

Update values file to serve Grafana from a non-root URL #

grafana:
  # other options as previous
  grafana.ini:
    server:
      domain: example.com
      root_url: https://example.com/grafana/
      serve_from_sub_path: true

Run the installation commands #

helm install loki-stack grafana/loki-stack --values loki-stack-values.yaml -n loki --create-namespace

Ingress configuration #

Finally, an ingress resource needs to be created with the path configuration matching the earlier root_url’s value, e.g.

# ingress resource definition
  rules:
  - host: example.com
    http:
      paths:
      - path: /grafana/
        pathType: Prefix
        backend:
          service:
            name: loki-stack-grafana
            port:
              number: 80

References #