Skip to main content
In this guide, we demonstrate how to view Kubernetes logs and review the default Promtail configurations used in a Loki-Grafana environment. You’ll learn how to query logs in Grafana, inspect the Promtail configuration, and understand how Kubernetes service discovery and relabeling work together to provide an efficient logging solution.
This article covers querying pod logs in Grafana and reviewing Promtail configurations used within a Loki-Grafana setup. Ensure that your Loki stack is running and properly configured to collect logs from your Kubernetes environment.

Querying Pod Logs in Grafana

After navigating to the Explore section in Grafana, run a query to confirm that logs are being collected. When selecting a label (for example, “cd mini”) and executing a query, you’ll see various system labels—such as app, component, file name, instance, job, and namespace—that are automatically assigned to system pods (e.g., etcd server, kube API, kube controller) as well as to Loki, Grafana, and Promtail pods. For example, to view logs for a specific pod (e.g., the etcd pod in the “minikube” namespace), use the following query:
This query returns all logs generated by the etcd pod, along with metadata labels such as node name, scrape job (defined within the Promtail configuration), and the source file path (typically located under /var/log/pods). You can further refine your queries by modifying or adding extra labels. For instance:
This setup illustrates how logs from containers and pods in a Kubernetes environment are collected and transmitted to Grafana via Loki and Promtail.
The image shows a Grafana interface with a query builder for Loki, displaying options for label filters and a graph of log data over time.

Reviewing Promtail Configurations

Next, we examine the Promtail configuration to understand how logs are discovered, processed, and transmitted.

Retrieving the Loki-Grafana Admin Password

First, verify the presence of the Loki-Grafana secret and retrieve the admin password:

Checking Running Pods and Secrets

Ensure that your Loki stack is running by listing the current pods:
Then, inspect the Promtail pod to examine mounts and container configuration. The Promtail container uses several volumes, including a configuration volume mounted from a secret and directories for Docker containers and pod logs. Below is an excerpt from the Promtail pod configuration:
This Promtail container configuration is defined by a Kubernetes secret (named loki-promtail) that supplies the Promtail configuration file.

Inspecting the Volume Configuration

Review the volume configuration, which shows how various directories are mounted within the Promtail pod:

Decoding the Promtail Configuration

To inspect the actual Promtail configuration, retrieve and decode the secret:
Then decode the secret’s content using base64. The decoded configuration outlines both client and scrape settings. For example, a snippet of the configuration is:
This configuration instructs Promtail on where to locate log files (typically under /var/log/pods) and how to assign labels based on the pod’s metadata.

Understanding the Scrape Configuration

The scrape configuration uses Kubernetes service discovery to locate all pods and applies relabeling rules to standardize log labels. An excerpt of the scrape configuration follows:
These relabeling rules ensure that critical metadata is preserved in the logs, making it easier to query and manage log data effectively in Grafana.
Using Kubernetes service discovery combined with relabeling rules enables Promtail to efficiently locate pods and standardize log labels, ensuring a seamless log monitoring experience in Grafana.
By following these steps and reviewing the configurations, you can monitor your Kubernetes environment’s logs with Loki, Promtail, and Grafana effectively.

Additional Resources

Happy logging!

Watch Video