## BLOG26: Prometheus Metric collection flow --- # π§© **What type of resource is Prometheus Adapter?** ### βοΈ **Prometheus Adapter is a Deployment** Installed via Helm β creates: * **Deployment** (pods running the adapter) * **Service** * **APIService** (`custom.metrics.k8s.io/v1beta1`) * **ConfigMap** (rules) * **ClusterRole / ClusterRoleBinding** * **ServiceAccount** π‘ **Important:** Prometheus Adapter registers itself as a **Kubernetes API extension**: ``` custom.metrics.k8s.io ``` But the core object running it is a **Deployment**. --- # π± **What type of resource is PodMonitor?** ### βοΈ **PodMonitor is a Custom Resource (CRD)** Created by the **Prometheus Operator (kube-prometheus-stack)**. CRD: ``` monitoring.coreos.com/v1 kind: PodMonitor ``` It tells Prometheus: > βScrape **these pods**, at **this path**, on **this port**.β It **does NOT** run anything β itβs **just configuration** that the Prometheus Operator converts into Prometheus scrape configs. --- # π **Now the Whole Metric Exposure Flow β Brief, Beautiful & Complete** Below is the 10-second summary you can use in your slides or training: --- ## **πΉ Step 1 β Application exposes metrics** Your dummy app exposes: ``` /metrics β myapp_queue_length ``` in Prometheus format. --- ## **πΉ Step 2 β PodMonitor tells Prometheus to scrape** `PodMonitor` selects the pods and creates the scrape config. Prometheus Operator loads the config β Prometheus begins scraping. --- ## **πΉ Step 3 β Prometheus stores the metric** Prometheus stores: ``` myapp_queue_length{pod="dummy-queue-app-XYZ"} ``` --- ## **πΉ Step 4 β Prometheus Adapter translates Prometheus metrics β K8s Custom Metrics API** Adapter rule converts: ``` Prometheus query β Kubernetes API metric ``` Example internal query: ``` myapp_queue_length{namespace="queue-demo", pod="..."} ``` Adapter exposes it at: ``` /apis/custom.metrics.k8s.io/v1beta1/namespaces/queue-demo/pods/*/myapp_queue_length ``` Now Kubernetes can βseeβ the metric. --- ## **πΉ Step 5 β HPA fetches metric from Custom Metrics API** HPA runs a loop: ``` GET custom.metrics.k8s.io/v1beta1/.../myapp_queue_length ``` Compares: * current queue length * desired target --- ## **πΉ Step 6 β HPA scales the Deployment** If queue > target: ``` scale up (replicas++) ``` If queue < target: ``` scale down (replicas--) ``` --- # πΊοΈ **Full Metric Flow Diagram (ASCII)** Copy-paste friendly: ``` ββββββββββββββββββββββββ β Dummy App (Pods) β β exposes /metrics β β myapp_queue_length β ββββββββββββ¬ββββββββββββ β βΌ ββββββββββββββββββββββββββ β PodMonitor (CRD) β β βscrape these podsβ β ββββββββββββ¬βββββββββββββ β generated config βΌ ββββββββββββββββββββββββββ β Prometheus Operator β β creates scrape jobs β ββββββββββββ¬βββββββββββββ β βΌ ββββββββββββββββββββββββββ β Prometheus β β stores metric values β ββββββββββββ¬βββββββββββββ β PromQL query βΌ ββββββββββββββββββββββββββββββββββββββ β Prometheus Adapter (Deploy) β β translates PromQL β K8s API metric β ββββββββββββ¬ββββββββββββββββββββββββββ β exposes: β custom.metrics.k8s.io βΌ βββββββββββββββββββββββββββββββββββββββββββββββββββββββ β Kubernetes Custom Metrics API (APIService) β ββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ β HPA queries: β /apis/custom.metrics.k8s.io/β¦/myapp_queue_length βΌ ββββββββββββββββββββββββββββ β HPA (HorizontalPodAutoscaler) β decides scale up/down ββββββββββββ¬βββββββββββββββ βΌ ββββββββββββββββββββββββ β Deployment replicas β ββββββββββββββββββββββββ ``` --- # π **In One Line** **Pod β PodMonitor β Prometheus β Prometheus Adapter β Custom Metrics API β HPA β Scaling** ---
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up