Filter logs from a container using promtail

Hello,

We are trying to filter logs only from one container from a multicontainer pod.

specifically, we are trying to get logs only from istio-proxy container from all the pods running in a cluster.

is it possible to to filter like that ?

Hello,

yes it is possible.

Check this documentation Pipelines | Grafana Loki documentation.

You can do something simple like this:

...
- match:
      selector: '{logs="container_logs"} !~ ".*istio-proxy.*"'
      action: drop

This will drop all lines that don’t include “istio-proxy”.

1 Like

Yes, it is possible to filter logs from a specific container within a multi-container pod in a Kubernetes cluster. You can achieve this using the kubectl logs command with the -c flag to specify the container name. In your case, to get logs only from the istio-proxy container, you would run:

phpCopy code

kubectl logs -c istio-proxy <pod-name>

This command will display logs only from the istio-proxy container within the specified pod. Keep in mind that the kubectl logs command fetches logs from a single container, so you’ll need to run it for each pod you want to inspect.