> ## Documentation Index
> Fetch the complete documentation index at: https://www.latitude.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Monitoring a Kubernetes cluster on bare metal with Prometheus and Grafana

> Get real-time visibility into your cluster's health and performance

After [deploying your Kubernetes cluster on bare metal](/guides/kubernetes-on-bare-metal), it's important to set up monitoring to track its health and performance.

This guide walks you through installing and configuring [Prometheus](https://prometheus.io/) and [Grafana](https://grafana.com/) to collect metrics, visualize data, and set up alerts for your Kubernetes environment. Let's get started!

## Prerequisites

* A running Kubernetes cluster.
* `kubectl` configured.
* `Helm 3` installed on your local machine.

Verify your cluster is ready:

```shell theme={null}
kubectl cluster-info
```

## Step 1: Add the Prometheus Helm repository

```bash theme={null}
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

helm repo update
```

## Step 2: Install the Prometheus stack

Install everything (Prometheus, Grafana, Alertmanager) with one command:

```bash theme={null}
helm install monitoring prometheus-community/kube-prometheus-stack
```

This uses default settings and creates a full monitoring stack.

## Step 3: Verify installation

<Steps>
  <Step title="Check pods status">
    Check if all pods are running:

    ```bash theme={null}
    kubectl get pods
    ```

    You should see the pods of the monitoring stack running:

    ```bash theme={null}
    > kubectl get pods -n monitoring
    NAME                                                        READY   STATUS    RESTARTS   AGE
    alertmanager-kube-prometheus-stack-alertmanager-0           2/2     Running   0          53s
    kube-prometheus-stack-grafana-76649cf75d-r4x7k              3/3     Running   0          3m6s
    kube-prometheus-stack-kube-state-metrics-77899fc47f-xmkhf   1/1     Running   0          3m6s
    kube-prometheus-stack-operator-6b6c6f966d-hrsjk             1/1     Running   0          3m6s
    kube-prometheus-stack-prometheus-node-exporter-dcwzq        1/1     Running   0          3m6s
    prometheus-kube-prometheus-stack-prometheus-0               2/2     Running   0          3m6s
    ```
  </Step>

  <Step title="Check services">
    Check the services:

    ```bash theme={null}
    kubectl get services -n monitoring
    ```

    This will show the created services for the monitoring stack and their assigned IPs.
  </Step>
</Steps>

## Step 4: Access the Grafana dashboard

By default, Grafana is only accessible from within the cluster. Use port forwarding to view it locally.

<Steps>
  <Step title="Set up port forwarding">
    Run the following command to forward the port:

    ```bash theme={null}
    kubectl port-forward svc/kube-prometheus-stack-grafana -n monitoring 3000:80
    ```
  </Step>

  <Step title="Open Grafana">
    Open [http://localhost:3000](http://localhost:3000/) in your browser.
  </Step>

  <Step title="Login with default credentials">
    Log in with the default credentials:

    * **Username:** admin
    * **Password:** prom-operator

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/guides/k8s-monitoring/grafana-login-localhost.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=469a5300a0d55d5536deb36364096acf" alt="Grafana login screen" width="956" height="1037" data-path="images/guides/k8s-monitoring/grafana-login-localhost.png" />

    If you need to retrieve the password:

    ```bash theme={null}
    kubectl get secret kube-prometheus-stack-grafana -n monitoring -o jsonpath="{.data.admin-password}" | base64 --decode; echo
    ```
  </Step>
</Steps>

## Step 5: Confirm Prometheus as a data source

The `kube-prometheus-stack` automatically sets up Prometheus as a data source in Grafana. To check:

<Steps>
  <Step title="Login to Grafana">
    Login to Grafana.
  </Step>

  <Step title="Go to Data Sources">Go to **Connections > Data Sources**.</Step>

  <Step title="Confirm Prometheus">
    Confirm Prometheus is listed.

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/guides/k8s-monitoring/grafana-data-sources.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=f75b869b52a8440ef898134eb6fd3431" alt="Grafana data sources" width="949" height="390" data-path="images/guides/k8s-monitoring/grafana-data-sources.png" />
  </Step>
</Steps>

## Step 6: Explore dashboards

Grafana includes several pre-built dashboards out of the box. To access them:

<Steps>
  <Step title="Navigate to dashboards">
    Click **Dashboards** in the sidebar.
  </Step>

  <Step title="Browse available dashboards">
    Select **Browse**.
  </Step>
</Steps>

For a high-level overview, start with **Kubernetes / Compute Resources / Cluster**. This dashboard provides insights into:

* Overall cluster CPU, memory, and filesystem usage.
* Pod and container performance.
* System service metrics.

<img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/guides/k8s-monitoring/grafana-dashboard.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=ede1d8b50b3025a3e834c0709d893f2a" alt="Grafana Kubernetes dashboard" width="1890" height="937" data-path="images/guides/k8s-monitoring/grafana-dashboard.png" />

## Step 7: Set up basic alerts

`Alertmanager` is already included as part of the `kube-prometheus-stack`. To manage alerts:

<Steps>
  <Step title="View alerts">
    In Grafana, go to **Alerting > Alert Rules**.
    View existing alerts or create new ones.
  </Step>

  <Step title="Configure contact points">
    To receive alerts:

    Go to **Alerting > Contact points**.
    Click **Create contact point**.
    Set up notifications (email, Slack, etc.).

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/guides/k8s-monitoring/grafana-contact-points.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=935b942903727a7e1f2871e3a1858753" alt="Grafana contact points" width="1201" height="728" data-path="images/guides/k8s-monitoring/grafana-contact-points.png" />
  </Step>
</Steps>

## Done!

You now have a working monitoring setup for your Kubernetes cluster. For advanced dashboards or deeper integration, check out the [Prometheus](https://prometheus.io/docs/) and [Grafana](https://grafana.com/docs/) documentation.
