FestiveHydra235
FestiveHydra235

Reputation: 633

Kubernetes: How to setup Promtail as a sidecar in order to read custom log paths

Does anyone know how to configure Promtail to watch and tail custom log paths in a Kubernetes pod? I have a deployment that creates customized log files in a directory like so /var/log/myapp. I found some documentation here that says to deploy Promtail as a sidecar to the container you want to collect logs from. I was hoping someone could explain how this method works in practice. Does it need to be done as a sidecar or could it be done as a Daemonset? Or if you have alternative solution that has proven to work could please show me an example.

Upvotes: 2

Views: 5588

Answers (2)

kloudkid
kloudkid

Reputation: 53

This post is about deploying Promtail as a sidecar container (first approach). There are some downsides to this approach however, as it requires having Promtail deployed to each Pod on which the application runs.

The other alternative is to use the Daemonset together with a streaming sidecar container.

I read here about a third variant using persistent volumes on the node itself.

Upvotes: 0

Bazhikov
Bazhikov

Reputation: 841

Posting comment as the community wiki answer for better visibility:


Below information is taken from README.md from the GitHun repo provided by atlee19:

This docs assume:

  • you have loki and grafana already deployed. Please refered to official documentation for installation

  • The logfile you want to scrape is in JSON format

This Helm chart deploy a application pod with 2 containers: - a Golang app writing logs in a separate file. - a Promtail that read that log file and send it to loki.

The file path can be updated via the ./helm/values.yaml file.

sidecar.labels is a map where you can add the labels that will be added to your log entry in Loki.

Example:

  • Logfile located at /home/slog/creator.log
  • Adding labels
    • job: promtail-sidecar
    • test: golang
sidecar:
  logfile:
    path: /home/slog
    filename: creator.log
  labels:
    job: promtail-sidecar
    test: golang

Upvotes: 1

Related Questions