How to set up Kubernetes monitoring with Prometheus
· Category: Kubernetes
How to set up Kubernetes monitoring with Prometheus
Introduction
Prometheus is a time-series database that scrapes metrics from Kubernetes workloads. Combined with Grafana, it provides powerful observability into cluster health, resource usage, and application performance.
Installation
Use the Prometheus Helm chart or the Prometheus Operator for CRD-based configuration:
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/kube-prometheus-stack
ServiceMonitor
The Prometheus Operator uses ServiceMonitor CRDs to discover scrape targets:
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: myapp
spec:
selector:
matchLabels:
app: myapp
endpoints:
- port: metrics
Key Metrics
Focus on CPU, memory, disk I/O, request latency, and error rates. Set up alerts for pod crash loops and resource exhaustion.
If you are packaging the monitored application, how to create a Kubernetes Helm chart from scratch streamlines deployment. For the underlying nodes, understanding how to use Docker multi-stage builds for smaller images reduces resource pressure.