Loki
Tutorial to scrap the pod’s traces with a Promtail sidecar agent and send the logs to Grafana Loki.
The following documentation presents how to scrap log from a Spring Boot Microservice. You may need to adapt it to your needs.
Requirements
- A Grafana instance (see Grafana Helm chart)
- A deployed service (Kubernetes Deployment)
kubectl
andhelm
installed and configured to your Kubernetes clusters- (optional) a cluster dedicated to your cross namespaces tools (example:
mycorp-monitoring
). It could be the same as your Grafana instance.
Loki
Install Loki by using its Helm chart.
Configure
Configure your Loki instance values.yaml
:
Installation
Applies your configuration:
(optional) Expose
Deploy the routes to access publicly your Loki instance:
- routes.yaml
Grafana
DataSource
Configure Loki datasource on http://loki:3100 (if your Grafana is in the same namespace). You may also want to use your public routes to configure the datasource of an external Grafana instance.
Dashboard
Here is a link to a Loki Dashboard you can import in your Grafana instance. You can also import a dashboard from the Grafana Marketplace.
Promtail
We are using the Kubernetes pods multi-containers capability (the sidecar is part of the service mesh) to share your application’s traces with the Promtail agent.
Configuration
Agent configuration shared with the agent containers.
In this example we are using the
/app/log/*.log
path and file pattern for the service’s logs files.
The following configuration defines how to process, parse and extract labels of the default Spring Boot Logback output
It’s possible to parameterize the configuration by using environment variables, example in the below configuration:
${SERVICE_NAME:service}
- promtail-boot.config.yaml:
⚠️ Pay attention to the __path__
value where the agent will look for traces to scrap.
- deploy the configuration in the namespace where will be located the sidecar agents:
Agent Sidecar
The most important part is to share the log files location between the Deployment
’s containers. To do so, we are using an emptyDir
volume.
- configure your application to produce log files. Example in your Spring Boot microservice
application.yaml
:
If you need more configuration options, you can use a logback.xml
file
- add the sidecar Promtail agent to your
Deployment
:
Adapt the security context, the log path, the service name and other Promtail environment variables.
Repeat this configuration to all the service to observe.
Explore the logs
Once your observed services are up and running (you should see 2/2 pods on a single replicated service) and after few seconds (depending on the amount of logs produced and the scrapping delay), go to your Grafana instance and “Explore” the Loki “Log Browser” or your dedicated dashboards.
You should be able to set alerts to observe and to be notified on crossed services critical logs levels.