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

Image of Wix Studio

2025: Your year to build apps that sell

Dive into hands-on resources and actionable strategies designed to help you build and sell apps on the Wix App Market.

Get started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay