Description
Deploy Prometheus and Grafana for infrastructure monitoring, alerting, and visualization.
Objective
Provide real-time observability of Kubernetes infrastructure with dashboards and alerts.
Solution
Environment Setup
- 1Provision Kubernetes cluster (EKS, GKE, AKS, or Minikube).
- 2Install Helm package manager.
- 3Create monitoring namespace.
- 4
bash
kubectl create namespace monitoring
Deploy Prometheus
- 1Add Helm repo and install Prometheus.
- 2Verify pods are running.
- 3
bash
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts helm repo update helm install prometheus prometheus-community/prometheus -n monitoring kubectl get pods -n monitoring
Deploy Grafana
- 1Install Grafana via Helm.
- 2Retrieve Grafana admin password.
- 3Port-forward Grafana service.
- 4
bash
helm install grafana grafana/grafana -n monitoring kubectl get secret grafana -n monitoring -o jsonpath="{.data.admin-password}" | base64 -d kubectl port-forward svc/grafana 3000:80 -n monitoring
Configure Prometheus + Grafana
- 1Add Prometheus as Grafana data source.
- 2Import Kubernetes dashboards.
- 3Create custom dashboards for CPU, memory, pod health.
Alerting
- 1Configure Prometheus Alertmanager.
- 2Define alert rules for CPU, memory, pod failures.
- 3Route alerts to Slack, email, or PagerDuty.
- 4
yaml
groups: - name: cpu-alerts rules: - alert: HighCPUUsage expr: sum(rate(container_cpu_usage_seconds_total[2m])) > 0.8 for: 2m labels: severity: warning annotations: description: "CPU usage > 80% for 2m"
Validation
- 1Access Grafana UI at http://localhost:3000.
- 2Verify dashboards show cluster metrics.
- 3Trigger test alerts and confirm delivery.
Tool Stack Used
- βKubernetes
- πPrometheus
- πGrafana
- π§Alertmanager
- π§Helm