# Why can't connect to Prometheus in K8s created by Rancher Desktop?

**URL:** <https://community.grafana.com/t/why-cant-connect-to-prometheus-in-k8s-created-by-rancher-desktop/122426>\
**Category:** Dashboards\
**Tags:** api\
**Created:** [May 24, 2024, 5:17am UTC](https://community.grafana.com/t/why-cant-connect-to-prometheus-in-k8s-created-by-rancher-desktop/122426 "2024-05-24T05:17:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![seikyo-cho-lvgs](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@seikyo-cho-lvgs](https://community.grafana.com/u/seikyo-cho-lvgs)\
**Post date:** [May 24, 2024, 5:17am UTC](https://community.grafana.com/t/why-cant-connect-to-prometheus-in-k8s-created-by-rancher-desktop/122426/1 "2024-05-24T05:17:51Z")

</div>

I installed Prometheus and Grafana via Helm:

```auto
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/prometheus
helm repo add grafana https://grafana.github.io/helm-charts 
helm repo update
helm install grafana grafana/grafana

```

Forwarding

```auto
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=prometheus,app.kubernetes.io/instance=prometheus" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward $POD_NAME 9090

export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=grafana" -o jsonpath="{.items[0].metadata.name}")
kubectl --namespace default port-forward $POD_NAME 3000

```

Expose services

```auto
kubectl expose service prometheus-server --type=NodePort --target-port=9090 --name=prometheus-server-ext
kubectl expose service grafana --type=NodePort --target-port=3000 --name=grafana-ext

```

When I login to Grafana([http://localhost:3000](http://localhost:3000)) and add data source with Prometheus

 ![1](https://us1.discourse-cdn.com/grafana/original/3X/4/1/41fd29491649031826aa0fb1179645281cf9b6e6.png)

I got this error:

 ![2](https://us1.discourse-cdn.com/grafana/original/3X/6/a/6a19aeee5ff56e97e02068594e1127e647949e02.png)

> Post “[http://localhost:9090/api/v1/query](http://localhost:9090/api/v1/query)”: dial tcp 127.0.0.1:9090: connect: connection refused - There was an error returned querying the Prometheus API.

But I can access **localhost:9090** from browser.

The kubernetes services are:

```auto
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 1d
prometheus-alertmanager-headless ClusterIP None <none> 9093/TCP 1h
prometheus-server ClusterIP 10.43.39.133 <none> 80/TCP 1h
prometheus-prometheus-pushgateway ClusterIP 10.43.199.209 <none> 9091/TCP 1h
prometheus-prometheus-node-exporter ClusterIP 10.43.246.176 <none> 9100/TCP 1h
prometheus-alertmanager ClusterIP 10.43.28.143 <none> 9093/TCP 1h
prometheus-kube-state-metrics ClusterIP 10.43.228.89 <none> 8080/TCP 1h
prometheus-server-ext NodePort 10.43.104.42 <none> 80:30186/TCP 1h
grafana ClusterIP 10.43.208.205 <none> 80/TCP 1h
grafana-ext NodePort 10.43.55.78 <none> 80:32765/TCP 1h

```

How to set `Prometheus server URL` correctly?

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [May 28, 2024, 7:47pm UTC](https://community.grafana.com/t/why-cant-connect-to-prometheus-in-k8s-created-by-rancher-desktop/122426/2 "2024-05-28T19:47:56Z")

</div>

Don’t use localhost - each container has own localhost. Connect to ClusterIP, e.g 10.43.39.133
