Skip to main content
Welcome to the second lab in this course. This step-by-step guide shows how to deploy Prometheus and Grafana inside a Kubernetes cluster, inspect Prometheus configuration and metrics, and connect Prometheus as a data source in Grafana. This lesson uses plain Kubernetes manifests so you can inspect the exact configuration files Prometheus and Grafana rely on; in production you would typically use the Prometheus Operator or Helm charts.
In a production environment you would typically deploy Prometheus via the Prometheus Operator or Helm charts. This lesson uses basic manifests so you can see the configuration files Prometheus and Grafana rely on.
Contents
  • Create a dedicated monitoring namespace
  • Inspect Prometheus configuration and create a ConfigMap
  • Deploy Prometheus (Deployment + Service + RBAC)
  • Explore Prometheus targets and key metrics
  • Deploy Grafana and add Prometheus as a data source
  • Visualize Prometheus metrics in Grafana

1) Create a monitoring namespace

Create a separate namespace to keep monitoring resources (Prometheus, Grafana) isolated from application and control-plane objects. Verify existing namespaces:
Example output:
Create the monitoring namespace:
Confirm the namespace exists:
Example output:

2) Inspect Prometheus manifests

List the Prometheus manifest directory to see what files are available:
Example output:
Table: Prometheus files and purpose Open prometheus.yml to inspect global settings (scrape/evaluation intervals) and scrape_configs (jobs and discovery). Example:
Question (lab): What are the job names under scrape_configs? Answer: prometheus and kubernetes-nodes.

Create a ConfigMap from prometheus.yml

Create a ConfigMap named prometheus-config in the monitoring namespace from the file:
Verify the ConfigMap exists:
Example output:
View the ConfigMap contents:
Example output (truncated):

3) Deploy Prometheus

Inspect prometheus-deployment.yaml — it contains:
  • Deployment running the Prometheus container (args point to the config file and storage path)
  • A ConfigMap volume mounted at /etc/prometheus
  • A ClusterIP Service exposing Prometheus internally at port 9090
  • ServiceAccount, ClusterRole, and ClusterRoleBinding for Kubernetes discovery
Important container snippet from prometheus-deployment.yaml:
Apply the Prometheus manifest:
Example apply output:
Watch the Prometheus pod start:
Example pod output:

4) Inspect Prometheus targets and metrics

Open the Prometheus UI (port-forward or NodePort) and go to Status → Targets. This page shows endpoints Prometheus is scraping based on scrape_configs from the loaded ConfigMap. Typical Targets examples:
  • Prometheus scrape target:
Endpoint: http://localhost:9090/metrics Labels: instance="localhost:9090" job="prometheus"
  • Node exporter (kubernetes-nodes) target (example error):
Endpoint: http://192.168.228.25:9100/metrics Labels: instance="controlplane" job="kubernetes-nodes" Error: Get “http://192.168.228.25:9100/metrics”: dial tcp 192.168.228.25:9100: connect: connection refused Prometheus also exposes builtin metrics. The up metric is the simplest health indicator:
  • up = 1 → target scraped successfully
  • up = 0 → target unreachable / scrape failed
Example (Prometheus expression up):
Another useful internal metric is prometheus_http_requests_total (HTTP handler request totals), helpful for inspecting Prometheus’ own behavior: Example series:
These counters accumulate over the lifetime of the Prometheus process.

5) Deploy Grafana

Inspect grafana/grafana-deployment.yaml. The Deployment runs Grafana on port 3000; for this lesson the admin password is set by environment variables (lab/demo purpose only). Key parts of the Grafana manifest:
Apply Grafana:
Verify pods:
Example output:
Grafana login for this lesson:
  • Username: admin
  • Password: admin
For lab/demo purposes the admin password is set via an environment variable and uses the default admin password. Do NOT use default or insecure credentials in production — rotate credentials and use secure secrets management.
You may get a browser warning about insecure default credentials — this is expected in the lab environment.

6) Add Prometheus as a Grafana data source

Open Grafana and navigate to Connections → Data sources → Add data source.
A browser screenshot of Grafana's "Add data source" page showing a list of time-series database options, including Prometheus, Graphite, InfluxDB, and OpenTSDB. The sidebar shows the Connections → Data sources menu.
Choose Prometheus as the data source. Use the in-cluster Service DNS name so Grafana (running in a separate pod) can reliably reach Prometheus:
No authentication is required for this lab. Click Save & Test — Grafana should report that it successfully queried the Prometheus API.
A dark-themed Grafana browser screenshot showing the Prometheus data source settings page with options like custom query parameters and HTTP method set to POST. A green banner reports "Successfully queried the Prometheus API" and there are "Delete" and "Save & Test" buttons at the bottom.
Why use the Service DNS instead of localhost?
  • Grafana and Prometheus run in different pods; localhost within the Grafana pod would point to Grafana itself. Use the Kubernetes Service DNS (prometheus.monitoring.svc.cluster.local:9090) to reach another in-cluster service.

7) Explore Prometheus metrics in Grafana

Open Grafana’s Explore view, select Prometheus as the data source, and run queries such as:
  • up
  • prometheus_http_requests_total
Grafana provides:
  • Richer visualizations and charting options
  • Ability to combine multiple queries
  • Smoother rendering and history navigation
  • Dashboard sharing and alerting integrations
Example: query prometheus_http_requests_total to see series split by labels like code, handler, instance, and job.

Recap

  • Created a dedicated monitoring namespace.
  • Loaded Prometheus configuration into a ConfigMap and deployed Prometheus (Deployment + Service + RBAC).
  • Inspected Prometheus targets and used up and internal metrics such as prometheus_http_requests_total.
  • Deployed Grafana and added Prometheus as a data source using the in-cluster Service DNS.
  • Visualized Prometheus metrics from Grafana’s Explore view.
This concludes the lab.

Watch Video