Day 16: Getting Started with Prometheus – Monitoring Metrics
Welcome to Day 16 of the Zero to Platform Engineer in 30 Days challenge! 🚀 Today, we’ll explore Prometheus, the go-to tool for monitoring Kubernetes and collecting real-time metrics.
Why Monitoring with Prometheus?
Monitoring is essential to:
- Detect Issues Early: Identify problems before they impact users.
- Optimize Performance: Track CPU, memory, and request latencies.
- Enable Alerting: Automatically notify teams when issues arise.
🎯 What Prometheus Provides:
- Time-series database optimized for Kubernetes metrics.
- Powerful query language (PromQL) for analyzing data.
- Built-in alerting and integrations with Grafana, Alertmanager, and more.
Installing Prometheus in Kubernetes
Step 1: Deploy Prometheus with Helm
- Add the Prometheus Helm repository:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- Deploy Prometheus with Helm:
helm install prometheus prometheus-community/kube-prometheus-stack --namespace monitoring --create-namespace
- Verify that Prometheus is running:
kubectl get pods -n monitoring
Step 2: Accessing Prometheus UI
- Forward Prometheus to your local machine:
kubectl port-forward svc/prometheus-kube-prometheus-prometheus -n monitoring 9090:9090
- Open Prometheus UI in your browser:
👉 http://localhost:9090
Step 3: Querying Metrics with PromQL
Run the following PromQL queries to analyze metrics:
- CPU usage of all nodes:
sum(rate(node_cpu_seconds_total[5m])) by (instance)
- Memory usage of all nodes:
sum(container_memory_usage_bytes) by (pod)
- Requests per second to your application:
rate(http_requests_total[1m])
Activity for Today
- Deploy Prometheus using Helm.
- Run PromQL queries to analyze your cluster’s metrics.
- Configure Alertmanager to notify when CPU usage is high.
What’s Next?
Tomorrow, we’ll visualize Prometheus metrics with Grafana, creating custom dashboards and alerts.
👉 Check it out here: Zero to Platform Engineer Repository
Feel free to clone the repo, experiment with the code, and even contribute if you’d like! 🚀
Follow the Series!
🎉 Don’t miss a single step in your journey to becoming a Platform Engineer! 🎉
This post is just the beginning. Here’s what we’ve covered so far and what’s coming up next:
-
Day 2: Day 2: Containers and Docker - The Building Blocks of Cloud Native
-
Day 3: Containers and Kubernetes - The Building Blocks of Cloud Native
-
Day 4: Deployments and Scaling in Kubernetes - Let’s Get Practical
-
Day 6: ConfigMaps and Secrets – Managing Configurations in Kubernetes
-
Day 13: Introduction to Observability with Prometheus and Grafana
-
Day 14: Securing Kubernetes – Runtime Security and Policy Enforcemeno
👉 Bookmark this blog and check back every day for new posts in the series. 📣 Share your progress on social media with the hashtag #ZeroToPlatformEngineer to connect with other readers!