My problem: I am only using promtail to send logs from my Kubernetes cluster to my Grafana cloud instance. It works, my logs arrive perfectly. My problem is that I don’t want to send logs from the whole cluster, I only want to send those that are conveniently tagged. I also don’t want to tag all objects in the cluster prematurely to indicate they should not be logged, because I don’t find it scalable. My idea is to take, for example, a Deployment, tag it in a convenient way (“logs-enabled,” for example), and then receive only its logs. Below is the configuration I currently have.
I installed Promtail simply using helm: helm repo add grafana https://grafana.github.io/helm-charts, and then helm repo update
So I created this yml file, which works perfectly for sending my logs to my Grafana Cloud:
config:
clients:
- url: my-url
basic_auth:
username: my-user
password: my-pass
positions:
filename: /run/promtail/positions.yaml
pipeline_stages:
- docker: {}
scrape_configs:
- job_name: kubernetes-pods
kubernetes_sd_configs:
- role: pod
relabel_configs:
# ---- FILTERING ----
# Try to only keep pods that have logging=logs-enabled label
# This should drop ALL pods that don't have this exact label
- source_labels: [__meta_kubernetes_pod_label_logging]
regex: ^logs-enabled$
action: keep
# ---- STANDARD LABELS ----
- source_labels: [__meta_kubernetes_namespace]
target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
target_label: pod
- source_labels: [__meta_kubernetes_container_name]
target_label: container
# ---- MAP ALL POD LABELS ----
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
And finally I just execute helm upgrade --install promtail grafana/promtail -f promtail-values.yaml
As you can see, I’m trying to filter by the label “logs-enabled” inside “scrape_configs,” but this isn’t working. Continue sending logs of absolutely everything.
I also tried filtering by namespace, leaving only the “default” namespace, and got no results; absolutely everything continues to be logged:
- source_labels: [__meta_kubernetes_namespace]
action: keep
regex: ^default$
Thanks in advance!