Cloud Native 27 min read

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.

Ops Development Stories
Ops Development Stories
Ops Development Stories
Deploy a Complete Prometheus Monitoring Stack on Kubernetes (Step‑by‑Step)

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

<code>git clone https://github.com/zhangdongdong7/k8s-prometheus.git
cd k8s-prometheus</code>

RBAC authorization

<code>kubectl apply -f prometheus-rbac.yaml</code>

Configuration

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

<code>kubectl apply -f prometheus-statefulset.yaml</code>

Service exposure

<code>kubectl apply -f prometheus-service.yaml</code>

The service uses a fixed NodePort (30090) for external access.

Deploy Grafana

StatefulSet

<code>kubectl apply -f grafana.yaml</code>

Access

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

<code>kubectl apply -f alertmanager-configmap.yaml
kubectl apply -f alertmanager-pvc.yaml
kubectl apply -f alertmanager-deployment.yaml
kubectl apply -f alertmanager-service.yaml</code>

Alert 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.

Prometheus architecture diagram
Prometheus architecture diagram
Prometheus component diagram
Prometheus component diagram
Prometheus web UI
Prometheus web UI
Prometheus architecture
Prometheus architecture
Prometheus deployment diagram
Prometheus deployment diagram
Grafana login page
Grafana login page
Grafana dashboard import
Grafana dashboard import
Grafana dashboard view
Grafana dashboard view
Grafana panel with Prometheus data
Grafana panel with Prometheus data
Grafana node monitoring
Grafana node monitoring
Alertmanager deployment flow
Alertmanager deployment flow
Alertmanager alert list
Alertmanager alert list
Alert email example
Alert email example
MonitoringKubernetesDevOpsPrometheusGrafanaAlertmanager
Ops Development Stories
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.