Kubernetes Monitoring with Prometheus, Grafana, and Loki
Deploy a production observability stack on Kubernetes combining kube-prometheus-stack metrics, Alertmanager routing, and Grafana Loki centralized logging.
Mohan Kumar BN
Senior Platform Engineer & CNCF Certified Kubestronaut
Blueprint Topology
Mermaid Topology Specification (Architecture-as-Code) ▼
flowchart LR
Pods["Kubernetes Pods & Nodes\n(cAdvisor + Node Exporter)"] --> Prom["Prometheus Server\n(Time-Series Metrics)"]
Pods --> Promtail["Promtail DaemonSet\n(Pod Log Tailer)"]
Promtail --> Loki["Grafana Loki\n(Label-Indexed Logs)"]
Prom --> Alert["Alertmanager\n(SLO Notification Routing)"]
Prom & Loki --> Grafana["Grafana Unified UI\n(Metrics + Logs Correlation)"] Unified Observability on Kubernetes
Operating Kubernetes in production without unified metrics and logs leaves SRE teams blind during latency spikes and node saturation events. By pairing kube-prometheus-stack with Grafana Loki, both metrics and container logs share the exact same Kubernetes metadata labels (namespace, pod, container, app).
Deploying the Stack via Helm
1. Add Prometheus Community and Grafana Helm Repositories
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
kubectl create namespace monitoring
2. Install kube-prometheus-stack
helm upgrade --install monitoring prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--set prometheus.prometheusSpec.retention=15d \
--set grafana.adminPassword="StrongPlatformAdminPassword"
3. Install Grafana Loki and Promtail
helm upgrade --install loki grafana/loki-stack \
--namespace monitoring \
--set promtail.enabled=true \
--set loki.persistence.enabled=true \
--set loki.persistence.size=20Gi
Connecting Loki in Grafana & Querying with LogQL
Add http://loki.monitoring.svc.cluster.local:3100 as a Loki Data Source in Grafana and execute targeted LogQL queries to isolate errors across namespaces:
{namespace="production", app="payment-service"} |= "error" != "healthcheck" Related Engineering Blueprints
Install an External Ceph Distributed Storage Cluster Using Ansible
Provision a self-healing, multi-node Ceph distributed storage cluster with Ansible to deliver replicated block (RBD), shared file (CephFS), and object storage for Kubernetes.
Deploy Self-Hosted Enterprise GitLab on Ubuntu with Ansible
Automate the deployment, TLS configuration, and day-2 tuning of a self-hosted GitLab instance on Ubuntu servers using idempotent Ansible playbooks.
How to Setup High-Availability Load Balancing with HAProxy & Keepalived
Configure redundant Active/Passive HAProxy load balancers with Keepalived VRRP floating Virtual IPs (VIP) on Ubuntu 24.04 to eliminate single points of failure.