Connecting To Prometheus
This guide explains how to connect to a Prometheus server and access its web UI using various methods.
In this guide, you'll learn how to connect to a Prometheus server and access its web UI. We'll cover several methods, starting with inspecting the Prometheus service using kubectl.
Listing Cluster Services¶
Begin by listing all services in your Kubernetes cluster to locate the Prometheus service:
kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-operated ClusterIP None <none> 9093/TCP,9094/TCP,9094/UDP 13h
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13h
prometheus-grafana ClusterIP 10.96.83.197 <none> 80/TCP 13h
prometheus-kube-prometheus-alertmanager ClusterIP 10.96.183.143 <none> 9093/TCP,8080/TCP 13h
prometheus-kube-prometheus-operator ClusterIP 10.96.55.122 <none> 443/TCP 13h
prometheus-kube-prometheus-prometheus ClusterIP 10.96.37.225 <none> 9090/TCP,8080/TCP 13h
prometheus-kube-state-metrics ClusterIP 10.96.107.10 <none> 8080/TCP 13h
prometheus-operated ClusterIP None <none> 9090/TCP 13h
prometheus-prometheus-node-exporter ClusterIP 10.96.104.136 <none> 9100/TCP 13h
This output confirms that the Prometheus service is running. Notice that the service is of type ClusterIP, meaning it is accessible only within the cluster.
Inspecting the Prometheus Service Configuration¶
To investigate further, output the service configuration to a YAML file. For instance, execute:
You will notice it is configured as a ClusterIP service.
Info
Since the service uses ClusterIP, it is only accessible from within your Kubernetes cluster.
Enabling External Access¶
To access Prometheus externally, consider the following options:
- Change the service type to NodePort or LoadBalancer.
- Set up an Ingress resource to route traffic from a specific URL or domain to the Prometheus service.
For demo purposes, we'll use port forwarding.
Accessing Prometheus via Port Forwarding¶
First, check the running pods in your cluster:
kubectl get pods
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-kube-prometheus-alertmanager-0 2/2 Running 0 13h
prometheus-grafana-64b4d64c54-2hjj8 3/3 Running 0 13h
prometheus-kube-prometheus-operator-84d5cd6bfd-lpnxb 1/1 Running 0 13h
prometheus-kube-state-metrics-67cf98b59f-6nrv7 1/1 Running 0 13h
prometheus-prometheus-kube-prometheus-prometheus-0 2/2 Running 0 13h
prometheus-prometheus-node-exporter-6b5mn 1/1 Running 0 13h
Once you have identified the correct Prometheus pod (for example, prometheus-prometheus-kube-prometheus-0), forward the pod’s port 9090 to your local machine:
With port forwarding active, open your browser and navigate to http://localhost:9090 to access the Prometheus web UI. This confirms that Prometheus is actively running.
Warning
Port forwarding is ideal for demos and testing. For production environments, switch to NodePort, LoadBalancer, or configure an Ingress for secure and stable external access.