DEV Community

Eduardo Lomeli
Eduardo Lomeli

Posted on

Kamal: How to use Grafana Loki as a logging driver

You can easily configure Grafana Loki as a logging driver in your Kamal deployments.

In this guide I'm using Grafana Cloud and Loki Docker driver client.

Install Loki Docker driver in your Kamal hosts

This step can be automated using Kamal docker-setup hook. Which runs right after Docker is installed, usually when you run kamal setup.

docker-setup

This script example is prepared to use multiple destinations.

File location: .kamal/hooks/docker-setup

#!/bin/sh

echo "Docker set up on $KAMAL_HOSTS. Destination $KAMAL_DESTINATION"

# Check if the Loki Docker Driver plug-in is already installed
if ! kamal server exec "docker plugin ls" -d $KAMAL_DESTINATION | grep -q "loki"; then
  echo "Installing Loki Docker Driver plug-in..."
  kamal server exec \
  "docker plugin install grafana/loki-docker-driver:2.9.2 --alias loki --grant-all-permissions" \
  -d $KAMAL_DESTINATION
else
  echo "Loki Docker Driver plug-in is already installed."
fi
Enter fullscreen mode Exit fullscreen mode

Configure Kamal logging driver

deploy.yaml

logging:
  driver: loki
  options:
    loki-url: https://<user_id>:<password>@logs-us-west1.grafana.net/loki/api/v1/push
    loki-batch-size: "400"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)