Shoomer

  • Docker
    DockerShow More
    Monolith to Microservices: A Docker + K8s Migration Story
    8 Min Read
    Docker Security Best Practices | Scout Trivy Scans
    8 Min Read
    CI/CD with Docker and Kubernetes with Examples YML
    10 Min Read
    Docker Networking Deep Dive | Bridge, Host, Overlay
    9 Min Read
    Docker Volumes and Bind Mounts Explained with Examples
    7 Min Read
  • Kubernetes
    KubernetesShow More
    Zero to Hero Kubernetes Crash Course – Minikube, kubectl, Helm Quickstart
    7 Min Read
    Spring Boot Web Crash Course 2025 – REST APIs, Controllers, Get/Post
    7 Min Read
    K8s Crash Course – Learn Containers to Clusters (Hands-On in 2025)
    7 Min Read
    Spring Data JPA Crash Course 2025 – Repository, Query Methods & Paging
    7 Min Read
    Spring Boot for Web Development – Crash Course with Thymeleaf & MVC
    7 Min Read
  • CICD Pipelines
    CICD PipelinesShow More
    What is GitOps with ArgoCD: Deep Dive into Architecture
    10 Min Read
    CI/CD with Docker and Kubernetes with Examples YML
    10 Min Read
  • Pages
    • About Us
    • Contact Us
    • Cookies Policy
    • Disclaimer
    • Privacy Policy
    • Terms of Use
Notification Show More
Font ResizerAa
Font ResizerAa

Shoomer

  • Learning & Education
  • Docker
  • Technology
  • Donate US
Search
  • Home
  • Categories
    • Learning & Education
    • Technology
    • Docker
  • More Foxiz
    • Donate US
    • Complaint
    • Sitemap
Follow US
Home » Kubernetes Monitoring with Prometheus & Grafana
Kubernetes

Kubernetes Monitoring with Prometheus & Grafana

shoomer
By shoomer
Last updated: June 11, 2025
Share

Monitoring Kubernetes clusters is essential for understanding system performance, debugging issues, and ensuring resource efficiency. Prometheus and Grafana are two powerful tools that together provide robust metrics collection, visualization, and alerting capabilities. This tutorial guides you through setting up Kubernetes monitoring using Prometheus with the kube-prometheus-stack, collecting node and pod metrics, creating custom Grafana dashboards, and configuring alerting rules.

Contents
Table of ContentsWhat is Prometheus & Grafana?PrometheusGrafanaSetting up Prometheus with kube-prometheus-stackStep 1 – Install HelmStep 2 – Add Prometheus Community RepoStep 3 – Install kube-prometheus-stackStep 4 – Verify InstallationMonitoring Node and Pod MetricsNode MetricsExample PromQL to Query Node Usage:Pod MetricsExample PromQL to Query Pod Metrics:Creating Custom Dashboards in GrafanaStep 1 – Add Prometheus as a Data SourceStep 2 – Create a New DashboardStep 3 – Save and ShareConfiguring Alerting RulesStep 1 – Define Alerts in PrometheusStep 2 – Add Notification Channel in GrafanaStep 3 – Link Alerts to NotificationsTesting AlertsFinal Thoughts

Table of Contents

  1. What is Prometheus & Grafana?
  2. Setting up Prometheus with kube-prometheus-stack
  3. Monitoring Node and Pod Metrics
  4. Creating Custom Dashboards in Grafana
  5. Configuring Alerting Rules
  6. Final Thoughts

What is Prometheus & Grafana?

Prometheus and Grafana are widely used tools for monitoring and observability in Kubernetes environments.

Prometheus

A time-series database designed for metrics collection and query. It gathers metrics from Kubernetes nodes, pods, and applications via an HTTP pull mechanism.

Grafana

A visualization tool that integrates with Prometheus to display metrics on customizable dashboards. Grafana makes it easy to create and share insightful graphs and charts.

Key Features:

  • Prometheus: Time-series storage, multi-dimensional data model, powerful query language (PromQL).
  • Grafana: Interactive dashboards, integrations with Prometheus and other data sources, and advanced alerting.

Together, these tools enable real-time observability for your Kubernetes environment.


Setting up Prometheus with kube-prometheus-stack

The kube-prometheus-stack Helm chart bundles Prometheus, Grafana, and related tools for quick and easy setup. Here’s how you can install it:

Step 1 – Install Helm

Ensure Helm is installed on your local system:

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

Step 2 – Add Prometheus Community Repo

Add the Helm repository for kube-prometheus-stack:

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

Step 3 – Install kube-prometheus-stack

Deploy the stack into a dedicated namespace:

kubectl create namespace monitoring  
helm install kube-stack prometheus-community/kube-prometheus-stack -n monitoring

Step 4 – Verify Installation

Ensure all Pods are running in the monitoring namespace:

kubectl get pods -n monitoring

Expected Output:

NAME                                   READY   STATUS    RESTARTS   AGE
kube-stack-grafana-xxxx                1/1     Running   0          2m
kube-stack-kube-state-metrics-xxxx     1/1     Running   0          2m
kube-stack-prometheus-xxxx             2/2     Running   0          2m

Prometheus and Grafana are now deployed. You can access Grafana by setting up port forwarding:

kubectl port-forward svc/kube-stack-grafana 3000:80 -n monitoring

Access Grafana at http://localhost:3000 and log in with the default credentials (username admin, password prom-operator).


Monitoring Node and Pod Metrics

Node and pod metrics are essential for tracking resource usage, cluster health, and workload performance.

Node Metrics

Metrics like CPU and memory usage per node are collected by the node-exporter component, part of kube-prometheus-stack.

Example PromQL to Query Node Usage:

  • CPU Usage per Node: node_cpu_seconds_total{mode!="idle"}
  • Memory Usage per Node: node_memory_Active_bytes / node_memory_MemTotal_bytes

Pod Metrics

Pod-specific metrics such as CPU usage and memory consumption are gathered by kube-state-metrics and Prometheus.

Example PromQL to Query Pod Metrics:

  • CPU Usage per Pod: sum(rate(container_cpu_usage_seconds_total{namespace="default"}[2m])) by (pod)
  • Memory Usage per Pod: sum(container_memory_working_set_bytes{namespace="default"}) by (pod)

Visual Reference:
Below is a diagram showing data flow from metrics sources to Prometheus and Grafana:

Node and Pod Metrics Flow

Creating Custom Dashboards in Grafana

Grafana supports creating custom dashboards to visualize metrics tailored to your use case.

Step 1 – Add Prometheus as a Data Source

  1. Log in to Grafana (http://localhost:3000).
  2. Go to Configuration > Data Sources > Add Data Source.
  3. Select Prometheus and configure the URL as http://kube-stack-prometheus.monitoring.svc.cluster.local.

Step 2 – Create a New Dashboard

  1. Navigate to Dashboards > New Dashboard.
  2. Add panels for CPU and memory metrics.

Example Panel Query (CPU Usage by Node):

sum(node_cpu_seconds_total{mode!="idle"}) by (instance)

Step 3 – Save and Share

Save the dashboard for later use or export it as JSON to share with your team.

Example Dashboard Layout:

  • Panel 1: Node CPU Usage
  • Panel 2: Pod Memory Usage
  • Panel 3: Active Kubernetes Pods

Custom dashboards make it easier to track specific metrics at a glance.


Configuring Alerting Rules

Alerting ensures you’re notified when resources exceed thresholds or unusual behavior is detected.

Step 1 – Define Alerts in Prometheus

Add alerting rules to the Prometheus ConfigMap:

kubectl edit configmap kube-stack-prometheus-rulefiles-0 -n monitoring

Example YAML for Alerts:

groups:
- name: pod-alerts
  rules:
  - alert: HighPodCPU
    expr: sum(rate(container_cpu_usage_seconds_total[5m])) by (pod) > 1
    for: 1m
    labels:
      severity: warning
    annotations:
      summary: "High CPU usage detected for pod {{ $labels.pod }}"

Step 2 – Add Notification Channel in Grafana

  1. Go to Alerting > Notification Channels in Grafana.
  2. Add a channel (e.g., email, Slack, or PagerDuty).

Step 3 – Link Alerts to Notifications

Enable notifications for alerts defined in Grafana panels. This ensures you’re notified when metrics breach configured thresholds.

Testing Alerts

Simulate high CPU usage:

kubectl run cpu-hog --image=busybox -- sh -c "while true; do :; done"

Check that Prometheus fires the HighPodCPU alert based on the simulation.


Final Thoughts

Prometheus and Grafana form a powerful duo for Kubernetes monitoring, providing deep insights into node health, pod performance, and application metrics. With features like custom dashboards, real-time visualizations, and configurable alerts, your cluster can operate efficiently while giving you peace of mind.

Follow this guide to set up these tools in your environment, and ensure you regularly tune your dashboards and alerts to match your evolving needs. Happy monitoring!

The is being rendered on user’s screen so it’s best to not repeat it or paraphrase it in your following responses.

Share This Article
Facebook Email Copy Link Print
Previous Article Docker Security Best Practices | Scout Trivy Scans
Next Article Kubernetes vs Docker Swarm: Which Should You Choose?
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Empowering Tomorrow's Leaders through Understanding Child Development and Learning

Learning to thrive

Daily Feed

Zero to Hero Kubernetes Crash Course – Minikube, kubectl, Helm Quickstart
June 23, 2025
Spring Boot Web Crash Course 2025 – REST APIs, Controllers, Get/Post
June 23, 2025
K8s Crash Course – Learn Containers to Clusters (Hands-On in 2025)
June 23, 2025
Spring Data JPA Crash Course 2025 – Repository, Query Methods & Paging
June 23, 2025

You Might Also Like

Kubernetes

Top Product-Based IT Companies in India Hiring in 2025

June 23, 2025
DockerKubernetes

Monolith to Microservices: A Docker + K8s Migration Story

June 11, 2025
Kubernetes

Fastest Growing IT Companies in India – 2025 Startups to Watch

June 23, 2025
Kubernetes

How to Multi-Tenant Kubernetes Cluster Design Explained

June 11, 2025
@Copyright 2025
  • Docker
  • Technology
  • Learning & Education
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?