Deploy the Loki Helm chart on Azure
This guide shows how to deploy a minimally viable Loki in microservice mode on Azure using the Helm chart. In order to successfully complete this guide, you must have the necessary tools and permissions to deploy resources on Azure, such as:
- Full access to AKS (Azure Kubernetes Service)
- Full access to Azure Blob Storage
- Sufficient permissions to create federated credentials and roles in Azure AD (Active Directory)
There are three primary ways to authenticate Loki with Azure:
- Hard coding a connection string - this is the simplest method but is not recommended for production environments.
- Manged identity
- Federated token
In this guide, we will use the federated token method to deploy Loki on Azure. This method is more secure than hard coding a connection string and is more suitable for production environments.
Considerations
Caution
This guide was accurate at the time it was last updated on 8th of January, 2025. As cloud providers frequently update their services and offerings, as a best practice, you should refer to the Azure documentation before creating your storage account and assigning roles.
AD Role: In this tutorial we will create a role in Azure Active Directory (Azure AD) to allow Loki to read and write from Azure Blob Storage. This role will be assigned to the Loki service account. You may want to adjust the permissions based on your requirements.
Authentication: Grafana Loki comes with a basic authentication layer. The Loki gateway (NGINX) is exposed to the internet using basic authentication in this example. NGINX can also be replaced with other open-source reverse proxies. Refer to Authentication for more information.
Retention: The retention period is set to 28 days in the
values.yaml
file. You may wish to adjust this based on your requirements.Costs: Running Loki on Azure will incur costs. Make sure to monitor your usage and costs to avoid any unexpected bills. In this guide we have used a simple AKS cluster with 3 nodes and
Standard_E2ds_v5
instances. You may wish to adjust the instance types and number of nodes based on your workload.
Prerequisites
- Helm 3 or above. Refer to Installing Helm. This should be installed on your local machine.
- Kubectl installed on your local machine. Refer to Install and Set Up kubectl.
- Azure CLI installed on your local machine. Refer to Installing the Azure CLI. This is a requirement for following this guide as all resources will be created using the Azure CLI.
AKS minimum requirements
Before creating an AKS cluster in Azure you need to create a resource group. You can create a resource group using the Azure CLI:
az group create --name <INSERT-NAME> -location <INSERT-AZURE-REGION>
Caution
These AKS requirements are the minimum specification needed to deploy Loki using this guide. You may wish to adjust the instance types based on your Azure environment and workload. If you choose to do so, we cannot guarantee that this sample configuration will still meet your needs.
In this guide, we deploy Loki using
Standard_E2ds_v5
instances. This is to make sure we remain within the free tier limits for Azure. Which allows us to deploy up to 10 vCPUs within a region. We recommend for large production workloads to scale these nodes up toStandard_D4_v5
.
The minimum requirements for deploying Loki on AKS are:
- Kubernetes version
1.30
or above. 3
nodes for the AKS cluster.- Instance type depends on your workload. A good starting point for a production cluster in the free tier is
Standard_E2ds_v5
instances and for large production workloadsStandard_D4_v5
instances.
Here is how to create an AKS cluster with the minimum requirements:
az aks create \
--resource-group <MY_RESOURCE_GROUP_NAME> \
--name <MY_AKS_CLUSTER_NAME> \
--node-count 3 \
--node-vm-size Standard_E2ds_v5 \
--generate-ssh-keys \
--enable-workload-identity \
--enable-oidc-issuer
Note in the above command we have enabled workload identity and OIDC issuer. This is required for the Loki service account to authenticate with Azure AD. If you have already created an AKS cluster, you can enable these features using the following command:
az aks update \
--resource-group <MY_RESOURCE_GROUP_NAME> \
--name <MY_AKS_CLUSTER_NAME> \
--enable-workload-identity \
--enable-oidc-issuer
The Azure CLI also lets you bind the AKS cluster to kubectl. You can do this by running the following command:
az aks get-credentials --resource-group <MY_RESOURCE_GROUP_NAME> --name <MY_AKS_CLUSTER_NAME>
Configuring Azure Blob Storage
Tip
Consider using unique bucket names rather than:
chunk
,ruler
, andadmin
. Although Azure Blog Storage is not directly affected by this security update it is a best practice to use unique container names for buckets.
Before deploying Loki, you need to create two Azure storage containers; one to store logs (chunks), the second to store alert rules. You can create the containers using the Azure CLI. Containers must exist inside a storage account.
Note
GEL customers will require a third container to store the admin data. This container is not required for OSS users.
Create a storage account:
az storage account create \ --name <NAME> \ --location <REGION> \ --sku Standard_ZRS \ --encryption-services blob \ --resource-group <MY_RESOURCE_GROUP_NAME>
Replace the placeholders with your desired values.
Create the containers for chunks and ruler:
az storage container create --account-name <STORAGE-ACCOUNT-NAME> --name <CHUNK-BUCKET-NAME> --auth-mode login && \ az storage container create --account-name <STORAGE-ACCOUNT-NAME> --name <RULER-BUCKET-NAME> --auth-mode login
Make sure
--account-name
matches the account you just created
With the storage account and containers created, you can now proceed to creating the Azure AD role and federated credentials.
Creating the Azure AD role and federated credentials
The recommended way to authenticate Loki with Azure Blob Storage is to use federated credentials. This method is more secure than hard coding a connection string directly into the Loki configuration. In this next section, we will create an Azure AD role and federated credentials for Loki to allow it to read and write from Azure Blob Storage:
Locate the OpenID Connect (OIDC) issuer URL:
az aks show \ --resource-group <MY_RESOURCE_GROUP_NAME> \ --name <MY_AKS_CLUSTER_NAME> \ --query "oidcIssuerProfile.issuerUrl" \ -o tsv
This command will return the OIDC issuer URL. You will need this URL to create the federated credentials.
Generate a
credentials.json
file with the following content:{ "name": "LokiFederatedIdentity", "issuer": "<OIDC-ISSUER-URL>", "subject": "system:serviceaccount:loki:loki", "description": "Federated identity for Loki accessing Azure resources", "audiences": [ "api://AzureADTokenExchange" ] }
Replace
<OIDC-ISSUER-URL>
with the OIDC issuer URL you found in the previous step.Make sure you to save the
credentials.json
file before continuing.Next generate an Azure directory
app
. We will use this to assign our federated credentials to:az ad app create \ --display-name loki \ --query appId \ -o tsv
This will return the app ID. Save this for later use. If you need to find the app ID later you can run the following command:
az ad app list --display-name loki --query "[].appId" -o tsv
The app requires a service principal to authenticate with Azure AD. Create a service principal for the app:
az ad sp create --id <APP-ID>
Replace
<APP-ID>
with the app ID you generated in the previous step.Next assign the federated credentials to the app:
az ad app federated-credential create \ --id <APP-ID> \ --parameters credentials.json
Replace
<APP-ID>
with the app ID you generated in the previous step.Lastly add a role assignment to the app:
az role assignment create \ --role "Storage Blob Data Contributor" \ --assignee <APP-ID> \ --scope /subscriptions/<SUBSCRIPTION-ID>/resourceGroups/<RESOURCE-GROUP>/providers/Microsoft.Storage/storageAccounts/<STORAGE-ACCOUNT-NAME>
Replace the placeholders with your actual values.
Now that you have created the Azure AD role and federated credentials, you can proceed to deploying Loki using the Helm chart.
Deploying the Helm chart
The following steps require the use of helm
and kubectl
. Make sure you have run the az
command to bind your AKS cluster to kubectl
:
az aks get-credentials --resource-group <MY_RESOURCE_GROUP_NAME> --name <MY_AKS_CLUSTER_NAME>
Before we can deploy the Loki Helm chart, we need to add the Grafana chart repository to Helm. This repository contains the Loki Helm chart.
Add the Grafana chart repository to Helm:
helm repo add grafana https://grafana.github.io/helm-charts
Update the chart repository:
helm repo update
Create a new namespace for Loki:
kubectl create namespace loki
Loki basic authentication
Loki by default does not come with any authentication. Since we will be deploying Loki to Azure and exposing the gateway to the internet, we recommend adding at least basic authentication. In this guide we will give Loki a username and password:
To start we will need create a
.htpasswd
file with the username and password. You can use thehtpasswd
command to create the file:Tip
If you don’t have the
htpasswd
command installed, you can install it usingbrew
orapt-get
oryum
depending on your OS.htpasswd -c .htpasswd <username>
This will create a file called
auth
with the usernameloki
. You will be prompted to enter a password.Create a Kubernetes secret with the
.htpasswd
file:kubectl create secret generic loki-basic-auth --from-file=.htpasswd -n loki
This will create a secret called
loki-basic-auth
in theloki
namespace. We will reference this secret in the Loki Helm chart configuration.Create a
canary-basic-auth
secret for the canary:kubectl create secret generic canary-basic-auth \ --from-literal=username=<USERNAME> \ --from-literal=password=<PASSWORD> \ -n loki
We create a literal secret with the username and password for Loki canary to authenticate with the Loki gateway. Make sure to replace the placeholders with your desired username and password.
Loki Helm chart configuration
Create a values.yaml
file choosing the configuration options that best suit your requirements. Below there is an example of values.yaml
files for the Loki Helm chart in microservices mode.
Caution
Make sure to replace the placeholders with your actual values.
It is critical to define a valid values.yaml
file for the Loki deployment. To remove the risk of misconfiguration, let’s break down the configuration options to keep in mind when deploying to Azure:
Loki Config vs. Values Config:
- The
values.yaml
file contains a section calledloki
, which contains a direct representation of the Loki configuration file. - This section defines the Loki configuration, including the schema, storage, and querier configuration.
- The key configuration to focus on for chunks is the
storage_config
section, where you define the Azure container name and storage account. This tells Loki where to store the chunks. - The
ruler
section defines the configuration for the ruler, including the Azure container name and storage account. This tells Loki where to store the alert and recording rules. - For the full Loki configuration, refer to the Loki Configuration documentation.
- The
Storage:
- Defines where the Helm chart stores data.
- Set the type to
azure
since we are using Azure Blob Storage. - Configure the container names for the chunks and ruler to match the containers created earlier.
- The
azure
section specifies the storage account name and also setsuseFederatedToken
totrue
. This tells Loki to use federated credentials for authentication.
Service Account:
- The
serviceAccount
section is used to define the federated workload identity Loki will use to authenticate with Azure AD. - We set the
azure.workload.identity/client-id
annotation to the app ID of the Azure AD app.
- The
Gateway:
- Defines how the Loki gateway will be exposed.
- We are using a
LoadBalancer
service type in this configuration.
Deploy Loki
Now that you have created the values.yaml
file, you can deploy Loki using the Helm chart.
Deploy using the newly created
values.yaml
file:helm install --values values.yaml loki grafana/loki -n loki --create-namespace
It is important to create a namespace called
loki
as our federated credentials were generated with the valuesystem:serviceaccount:loki:loki
. This translates to theloki
service account in theloki
namespace. This is configurable but make sure to update the federated credentials file first.Verify the deployment:
kubectl get pods -n loki
You should see the Loki pods running.
Find the Loki gateway service
The Loki gateway service is a load balancer service that exposes the Loki gateway to the internet. This is where you will write logs to and query logs from. By default NGINX is used as the gateway.
Caution
The Loki gateway service is exposed to the internet. We provide basic authentication using a username and password in this tutorial. Refer to the Authentication documentation for more information.
To find the Loki gateway service, run the following command:
kubectl get svc -n loki
You should see the Loki gateway service with an external IP address. This is the address you will use to write to and query Loki.
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
loki-gateway LoadBalancer 10.100.201.74 134.236.21.145 80:30707/TCP 46m
Congratulations! You have successfully deployed Loki on Azure using the Helm chart. Before we finish, let’s test the deployment.
Testing Your Loki Deployment
k6 is one of the fastest ways to test your Loki deployment. This will allow you to both write and query logs to Loki. To get started with k6, follow the steps below:
Install k6 with the Loki extension on your local machine. Refer to Installing k6 and the xk6-loki extension.
Create a
azure-test.js
file with the following content:Replace
<EXTERNAL-IP>
with the external IP address of the Loki Gateway service.This script will write logs to Loki and query logs from Loki. It will write logs in a random format between 800KB and 2MB and query logs in a random format over the last 5 minutes.
Run the test:
./k6 run azure-test.js
This will run the test and output the results. You should see the test writing logs to Loki and querying logs from Loki.
Now that you have successfully deployed Loki in microservices mode on Microsoft Azure, you may wish to explore the following: