---
title: "Prometheus & Kubernetes"
description: "Set up Middleware integration with Prometheus & Kubernetes for cluster metrics, logs, and error tracking."
section: "Integrations"
breadcrumb: "Integrations > Metrics & Monitoring > Prometheus & Kubernetes"
canonical: "https://docs.middleware.io/integrations/prometheus-integration-k8s"
---
# Prometheus & Kubernetes

Scrape Prometheus metrics from services running in your Kubernetes cluster with the Middleware Kubernetes Agent, without running a separate Prometheus server, and use them in Middleware dashboards and alerts.

## Add Prometheus Integration from Middleware K8s Agent

If you are already using [Middleware Kubernetes Agent](/get-started/agent/kubernetes/kubernetes-agent) then you can easily enable prometheus scraping from Middleware UI.

### Step 1: Navigate to Prometheus Integration

Go to **Installation > Integration > Prometheus > Kubernetes Agent** as shown in the image

![Prometheus K8s Integration](/images/prom-k8s1.png?width=100&height=400)

### Step 2: Select the Cluster

Click on the "Add Cluster" button, which will open a dropdown of available clusters and select the Cluster where you want to enable Prometheus Scraping

![Prometheus K8s Integration](/images/prom-k8s2.png?width=100&height=150)

### Step 3: Enable Annotation Based Scraping

Check the box next to **Enable Annotation Based Scraping** and then click **Save** to apply the settings.

![Prometheus K8s Integration](/images/prom-k8s3.png?width=100&height=150)

### Step 4: Configuring the Target Services

Now all services that are exposing prometheus metrics will be scraped.

To confirm, check that the target services have these 3 annotations in place.

```
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
```

The `port` and `path` values may be different for different services.

## Prometheus as a Sidecar Container

> **Note:** We are currently updating this feature. If you have any issues configuring this integration, please contact us at support[at]middleware.io

To scrape the prometheus endpoint using a sidecar, you will need to add `sidecar container` in your pod:

```
- name: middleware-prometheus-agent
  image: ghcr.io/middleware-labs/mw-kube-agent:prometheus-integration
  imagePullPolicy: Always
  env:
  - name: MW_TARGET
    value: https://xxxxx.middleware.io:443 # Middleware Target URL
  - name: MW_API_KEY
    value: "your-initial-token" # Middleware API Key
  - name: PROMETHEUS_SCRAPE_CONFIG
    value: job1@0.0.0.0:8889,job2@0.0.0.0:8890
```

### Environment Variables

> **Note:** If you are logged in to the docs both `MW_TARGET` and `MW_API_KEY` will be populated with your details.

**MW_TARGET**: Specifies the target URL for the Middleware service. This URL defines the endpoint where your application should interact with the middleware.

```
Example Value: your-initial-uid
```

**MW_API_KEY**:
Provides the API key required for authenticating with the Middleware service. Ensure the key is kept confidential and only shared with authorized users or services.

```
Example Value: "your-initial-token"
```

**PROMETHEUS_SCRAPE_CONFIG**:
Configures Prometheus scraping targets. This variable should be set in the format 'job@address:port', where 'job' represents the scraping job name, 'address' is the IP address or hostname, and 'port' is the port to scrape metrics from.

```
Example Value: job1@0.0.0.0:8889,job2@0.0.0.0:8890
```

## Visualize Your Prometheus Metrics

You can now access this metrics data under our Dashboard builder

```
https://app.middleware.io/reports
```

1. Create a new report
2. **Add New Widget**
3. Select **prometheus** under the **Data Source** dropdown to see all metrics, as shown in the screenshot below.

These metrics can be visualized using various widget types, such as Timeseries, Bar Chart, Pie Chart, and more.

## Troubleshooting

### Missing Integrations Menu

If you do not see the Integrations Menu in Middlware, that means your account has not been granted `Installation` permissions. Contact your system administrator to add the `Installation` permission to your user role in Settings.

## Next Steps

- [How to Create Alerts](/features/alerts/manage-alerts)
- [Dashboard Basics & Customization](/features/dashboards)
- [Custom Telemetry Ingestion](/get-started/agent/otel)
- [Getting Started With Real User Monitoring (RUM)](/get-started/rum)
- [Data Ingestion APIs](/get-started/ingestion-api/data-ingestion)

Need assistance or want to learn more about Middleware? Get in touch with us via our Contact Us page or join our Slack channel.
