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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay