Skip to content

Simple Guide to Monitoring and Logging on Kubernetes #1

Updated: at 06:59 PM

Below is an updated blog post that shows you how to deploy a simple Kubernetes monitoring and logging stack using Helm. This guide uses both the Prometheus stack (via the prometheus-community/kube-prometheus-stack chart) and the Loki logging stack with Promtail (via the grafana/loki-stack chart). We use the --create-namespace flag with Helm to simplify namespace creation.


Below is an updated blog post that shows you how to deploy a simple Kubernetes monitoring and logging stack using Helm. This guide uses both the Prometheus stack (via the prometheus-community/kube-prometheus-stack chart) and the Loki logging stack with Promtail (via the grafana/loki-stack chart).


”Simple Guide to Monitoring and Logging on Kubernetes #1”

In this post, we’ll show you how to monitor your Kubernetes cluster while also collecting logs. We will use Helm charts to install everything quickly. For monitoring, we use the kube-prometheus-stack. For logging, we use Loki with Promtail.

What You Get

With these tools, you can see both the performance and the log details of your cluster.


Prerequisites

Before you begin, make sure you have:


Step 1: Set Up the Monitoring Stack

We will install the Prometheus stack using Helm.

1.1. Add the Prometheus Community Helm Repository

helm repo add prometheus-community \
  https://prometheus-community.github.io/helm-charts
helm repo update

1.2. Install the kube-prometheus-stack

Use the following command to install the chart in the monitoring namespace. The command also creates the namespace if it doesn’t exist.

helm install my-monitoring prometheus-community/kube-prometheus-stack \
  --namespace monitoring --create-namespace

This command deploys Prometheus, Grafana, Alertmanager, and other components into your cluster.

1.3. Accessing the Grafana Dashboard

You can access Grafana via port forwarding:

kubectl port-forward svc/my-monitoring-grafana 3000:80 -n monitoring

Then, open http://localhost:3000 in your browser.
To find the default Grafana password, run:

kubectl get secret my-monitoring-grafana -n monitoring \
  -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

Log in with the username admin and the printed password.


Step 2: Set Up the Logging Stack (Loki + Promtail)

Next, we’ll install Loki (and Promtail) for logging.

2.1. Add the Loki Helm Repository

Loki and Promtail are provided by Grafana Labs. Add their Helm repo:

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

2.2. Install Loki and Promtail

Run the following command to install the Loki stack (including Promtail) in the logging namespace:

helm install loki grafana/loki-stack \
  --namespace monitoring --create-namespace \
  --set promtail.enabled=true

The option promtail.enabled=true tells the chart to deploy Promtail along with Loki.

2.3. Access Grafana for Loki Logs

If you use the Grafana from the monitoring stack, you can add Loki as a data source in that Grafana instance. Otherwise, if you’d like to use the Grafana provided with the Loki stack, set port forwarding for it as follows:

kubectl port-forward svc/loki-grafana 3000:80 -n monitoring

Then add Loki as a data source by:

  1. Clicking on the gear icon (Configuration) → Data Sources.
  2. Clicking “Add data source” and selecting Loki.
  3. Setting the URL as http://loki:3100 (usually the default for the Loki stack).
  4. Saving and testing the data source.

Now, you can build dashboards to view your logs.


Step 3: Customizing Your Setup

One of the benefits of using Helm is that you can customize settings via values files. For example, for the monitoring stack, create a file named monitoring-values.yaml:

grafana:
  adminUser: "your-admin-user"
  adminPassword: "your-secure-password"

Then update your release:

helm upgrade --install my-monitoring prometheus-community/kube-prometheus-stack \
  --namespace monitoring -f monitoring-values.yaml

Likewise, you can customize Loki and Promtail with your own values when installing or upgrading the Loki stack.


Step 4: Checking Your Installations

After installing both stacks, verify that all components are running as expected.

For the monitoring stack:

kubectl get pods -n monitoring

For the logging stack:

kubectl get pods -n logging

You should see pods for Prometheus, Alertmanager, Grafana (monitoring), Loki, and Promtail (logging).


Conclusion

Using Helm, you now have a combined monitoring and logging setup running in your Kubernetes cluster. The kube-prometheus-stack gives you clear insights into your cluster’s performance, while Loki with Promtail efficiently gathers and stores logs.


Previous Post
How I Passed the LFCS (and What Actually Helped Me)
Next Post
Setting up NFS Storage Class in Kubernetes with a Helm Chart