Skip to content

Install Grafana Loki-Stack Helmchart in Azure Kubernetes Services (AKS)

Introduction

Grafana Loki is a powerful log aggregation system that allows users to collect, store, and query logs in a highly efficient and scalable manner. When integrated with Kubernetes, Grafana Loki provides a seamless solution for monitoring and analyzing logs within AKS clusters. By leveraging Helm charts, the deployment process becomes streamlined and reproducible, ensuring consistent setups across different environments.

In this tutorial, I will guide you through the process of installing Grafana Loki-Stack using Helmchart in an AKS cluster.

Objective

In this exercise we will accomplish & learn how to implement following:

  • Step 1: Login into Azure
  • Step 2. Connect to AKS Cluster
  • Step 3. Add Grafana Loki-Stack Helm Repository
  • Step 4. Install Grafana Loki-Stack Helmchart
  • Step 5. Verify Grafana Loki-Stack Resources in AKS
  • Step 6. Access Grafana Loki-Stack Dashboard Locally - port forwarding
  • Step 7. Configure Ingress for Grafana Loki-Stack

Prerequisites

Before you begin, ensure you have the following prerequisites:

  • An Azure account with access to AKS.
  • Azure CLI installed on your local machine.
  • kubectl installed on your local machine.
  • Helm installed on your local machine.

Step 1: Login into Azure

Verify that you are logged into the right Azure subscription before start anything in visual studio code

# Login to Azure
az login 

# Shows current Azure subscription
az account show

# Lists all available Azure subscriptions
az account list

# Sets Azure subscription to desired subscription using ID
az account set -s "anji.keesari"

Follow the on-screen instructions to complete the login process.

Step 2: Connect to AKS Cluster

Once logged in and set your subscription then connect to your AKS cluster. with your AKS cluster name:

Use the az aks get-credentials command to connect to the AKS cluster.

# Azure Kubernetes Service Cluster User Role
az aks get-credentials -g "rg-aks-dev" -n "aks-cluster1-dev"

# Azure Kubernetes Service Cluster Admin Role
az aks get-credentials -g "rg-aks-dev" -n "aks-cluster1-dev" --admin

# get nodes
kubectl get no
kubectl get namespace -A

Step 3: Add Grafana Loki-Stack Helm Repository

Before installing Grafana Loki-Stack, you need to add the Helm repository for Grafana Loki-Stack:

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

Alt text

Alt text

Alt text

helm list -aA
helm list --namespace grafana
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
loki-stack      loki-stack      1               2024-03-16 17:22:22.273156 -0700 PDT    deployed        loki-stack-2.10.2       v2.9.3  

Step 4: Install Grafana Loki-Stack Helmchart

Now, you can install Grafana Loki-Stack using Helmchart. Execute the following command:

Let's first see the values:

helm show values grafana/loki-stack > C:\Source\Repos\IaC\terraform\loki-stack-values.yaml

Alt text

# use this command if you need to create namespace along with helm install
helm upgrade --install loki-stack --values loki-stack-values.yaml grafana/loki-stack --namespace loki-stack --create-namespace --version 2.10.2

# use this command if you already have namespace created
helm upgrade --install loki-stack --values loki-stack-values.yaml grafana/loki-stack --version 2.10.2
Alt text

This command installs Grafana Loki-Stack in your AKS cluster. You can customize the installation by providing values files or using Helm chart options.

Step 5: Verify Grafana Loki-Stack Resources in AKS

To verify that Grafana Loki-Stack has been successfully installed, you can list the Kubernetes resources:

kubectl get all -n loki-stack
kubectl get all,configmap,secret -n loki-stack
kubectl get pods -n loki-stack

Alt text

You should see Grafana Loki-Stack pods and services running in your cluster.

Step 6: Access Grafana Loki-Stack Dashboard Locally

To access the Grafana Loki-Stack dashboard locally, you need to create a port forward:

kubectl port-forward svc/loki-stack -n loki-stack 3100:3100
http://localhost:3100/ready

To access the Grafana dashboard locally, you need to create a port forward:

kubectl port-forward svc/loki-stack-grafana -n loki-stack 3000:3000
http://localhost:3000/login

Now, you can access Grafana & Loki-Stack by opening your web browser. Use the default username (admin) to log in.

You need to retrieve the admin password by running the following commands:

# bash
kubectl get secret --namespace loki-stack grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo
# pwsh
kubectl get secret --namespace loki-stack grafana -o jsonpath="{.data.admin-password}" | ForEach-Object { [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_)) }

After running the above commands, you should be able to access Grafana Loki-Stack at http://localhost:3000 in your web browser. Log in using the username admin and the password obtained from the previous command.

Grafana > Login page Alt text

Grafana > Welcome page Alt text

Grafana > Connection page Alt text

Grafana > Dashboard page Alt text

Loki > ready state

Alt text

Loki > Metrics

Alt text

Loki > Config

Alt text

Loki > Labels

Alt text

Grafana > Loki data source - added by default

Alt text

Loki > access pod logs

Alt text

Other Loki endpoints for testing:

Step 7: Configure Ingress for Grafana Loki-Stack

If you want to access Grafana externally, you can configure Ingress. First, create an Ingress resource:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-ingress
spec:
  rules:
  - host: yourdomain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: loki-stack-grafana
            port:
              number: 80

Apply the Ingress configuration:

kubectl apply -f grafana-ingress.yaml

loki Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: loki-ingress
spec:
  rules:
  - host: yourdomain.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: loki-stack
            port:
              number: 3100

Apply the Ingress configuration:

kubectl apply -f loki-ingress.yaml
Replace yourdomain.com with your actual domain name.

clean up resources:

helm delete loki-stack -n loki-stack
helm delete grafana -n grafana

Conclusion

You have successfully installed Grafana Loki-Stack using Helmchart in Azure Kubernetes Services. The integration of Grafana Loki into Azure Kubernetes Services using Helm charts simplifies the deployment process and empowers users with powerful log monitoring capabilities, enhancing observability within Kubernetes clusters.

Reference