Grafana Alloy

Prerequisites

This guide assumes you have the following prerequisites in place:

Grafana Alloy

Grafana Alloy is the successor to Promtail. Use it in conjunction with Loki to collect and visualize logs from your Kubernetes cluster.

Installation

  1. Create the following directory structure for Grafana Alloy:

    grafana-alloy/
    ├── alloy-repo.yml
    └── alloy-release.yml
  2. Create the alloy-repo.yml file with the following content:

    ---
    apiVersion: source.toolkit.fluxcd.io/v1
    kind: HelmRepository
    metadata:
      name: grafana
      namespace: flux-system
    spec:
      interval: 6h
      url: https://grafana.github.io/helm-charts
  3. Create the alloy-release.yml file with the following content:

    ---
    apiVersion: helm.toolkit.fluxcd.io/v2
    kind: HelmRelease
    metadata:
      name: alloy
      namespace: monitoring
    spec:
      interval: 6h
      chart:
        spec:
          chart: alloy
          version: "1.6.2"
          sourceRef:
            kind: HelmRepository
            name: grafana
            namespace: flux-system
      values:
        alloy:
          configMap:
            content: |
              discovery.kubernetes "pods" {
                role = "pod"
              }
    
              discovery.relabel "pods" {
                targets = discovery.kubernetes.pods.targets
                rule {
                  source_labels = ["__meta_kubernetes_namespace"]
                  target_label  = "namespace"
                }
                rule {
                  source_labels = ["__meta_kubernetes_pod_name"]
                  target_label  = "pod"
                }
                rule {
                  source_labels = ["__meta_kubernetes_pod_container_name"]
                  target_label  = "container"
                }
                rule {
                  source_labels = ["__meta_kubernetes_node_name"]
                  target_label  = "node"
                }
              }
    
              loki.source.kubernetes "pods" {
                targets    = discovery.relabel.pods.output
                forward_to = [loki.write.default.receiver]
              }
    
              loki.write "default" {
                endpoint {
                  url = "http://loki.monitoring.svc.cluster.local:3100/loki/api/v1/push"
                }
              }
  4. Commit and push the files to your Git repository. Flux will deploy Grafana Alloy to your cluster.