Deploy a Complete Prometheus Monitoring Stack on Kubernetes (Step‑by‑Step)
This guide walks through the architecture of Prometheus, the key Kubernetes monitoring metrics, and step‑by‑step instructions to deploy Prometheus, Grafana, and Alertmanager on a K8s cluster, configure RBAC, set up ConfigMaps, expose services, import dashboards, and test alert notifications via email.
Introduction
Prometheus is an open‑source monitoring system originally built at SoundCloud and now a CNCF project, making it a natural fit for Kubernetes monitoring.
Prometheus Architecture
Prometheus consists of a server, client libraries, a push gateway, exporters, Alertmanager, and a simple web UI.
All data are stored as time‑series identified by a metric name and a set of key‑value labels.
Jobs and Instances
Instances are scrape targets; a job groups instances that share the same scrape configuration.
Kubernetes Monitoring Metrics
Important metrics include node resource utilization, pod counts, and resource‑object status. Implementations use cAdvisor for pod metrics, node‑exporter for node metrics, and kube‑state‑metrics for object status.
Deploy Prometheus on the K8s Cluster
Cluster environment
Four nodes are used: one master (192.168.73.138) and three workers (192.168.73.136, .139, .140).
Clone the project
git clone https://github.com/zhangdongdong7/k8s-prometheus.git
cd k8s-prometheusRBAC authorization
kubectl apply -f prometheus-rbac.yamlConfiguration
A ConfigMap prometheus-config defines prometheus.yml with scrape jobs for the Prometheus server itself, Kubernetes nodes, API servers, cAdvisor, node‑exporter and kube‑state‑metrics.
StatefulSet deployment
kubectl apply -f prometheus-statefulset.yamlService exposure
kubectl apply -f prometheus-service.yamlThe service uses a fixed NodePort (30090) for external access.
Deploy Grafana
StatefulSet
kubectl apply -f grafana.yamlAccess
Grafana is reachable at http://<NodeIP>:30091 with default credentials admin / admin .
Visualizing Prometheus data in Grafana
Import community dashboards (e.g., dashboard 3119 for cluster resources) and adjust the PromQL queries as needed.
Deploy Alertmanager
Configuration
kubectl apply -f alertmanager-configmap.yaml
kubectl apply -f alertmanager-pvc.yaml
kubectl apply -f alertmanager-deployment.yaml
kubectl apply -f alertmanager-service.yamlAlert rules are stored in prometheus-rules.yaml (e.g., InstanceDown, NodeFilesystemUsage, NodeMemoryUsage, NodeCPUUsage). Email notifications are configured via the Alertmanager config.
Testing alerts
Stopping kubelet on a node triggers the InstanceDown alert and sends an email notification.
After completing these steps you obtain a fully functional Prometheus‑Grafana‑Alertmanager monitoring stack for a Kubernetes cluster.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
