Hands-on Lab·Kubernetes and Cloud Native Associate
PromQL Query Basics
Query Prometheus from a Pod instead of a port-forward. Four queries: how many targets exist, how many are down, which jobs they belong to, and how busy the cluster really is.
Observability Guide 37 of 46 Beginner
- Kubernetes1.36.4
- Cluster4 nodes
- Runtimecontainerd 2.2.6
- CNICalico v3.32.1
- TimeAbout 20 min
Metric names are stable across these versions; the numbers in the output are from this cluster and yours will differ.
- Chartkube-prometheus-stack 88.5.3
- Prometheus Operatorv0.93.1
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| CKA1001 | 192.168.0.175 | Ubuntu 26.04 LTS | Control Plane Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE01 | 192.168.0.176 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE02 | 192.168.0.177 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
| CKA1001-NODE03 | 192.168.0.178 | Ubuntu 26.04 LTS | Worker Node | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when Prometheus is running and you need to ask it something useful. This matters because the first questions worth asking are about Prometheus itself - which targets it is failing to scrape - and PromQL is how you ask them.
- querying the HTTP API from a Pod inside the cluster rather than through
kubectl port-forward - using
upto count scrape targets and how many of them are failing - grouping those failures by job, because a count of seven is not something anyone can act on
- writing two queries that answer questions about the workload rather than about Prometheus
Before you start
- kube-prometheus-stack running in a
monitoringnamespace. The install guide covers it. - No port-forward needed - every query here runs from a Pod inside the cluster.
-
A Pod to query from
-
How many targets, and how many are broken
-
Group them, because a count is not a diagnosis
-
Two queries that answer real questions