Infrastructure Monitoring with Prometheus

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

  1. 1Provision Kubernetes cluster (EKS, GKE, AKS, or Minikube).
  2. 2Install Helm package manager.
  3. 3Create monitoring namespace.
  4. 4
    bashkubectl create namespace monitoring

Deploy Prometheus

  1. 1Add Helm repo and install Prometheus.
  2. 2Verify pods are running.
  3. 3
    bashhelm 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

  1. 1Install Grafana via Helm.
  2. 2Retrieve Grafana admin password.
  3. 3Port-forward Grafana service.
  4. 4
    bashhelm 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

  1. 1Add Prometheus as Grafana data source.
  2. 2Import Kubernetes dashboards.
  3. 3Create custom dashboards for CPU, memory, pod health.

Alerting

  1. 1Configure Prometheus Alertmanager.
  2. 2Define alert rules for CPU, memory, pod failures.
  3. 3Route alerts to Slack, email, or PagerDuty.
  4. 4
    yamlgroups:
      - 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

  1. 1Access Grafana UI at http://localhost:3000.
  2. 2Verify dashboards show cluster metrics.
  3. 3Trigger test alerts and confirm delivery.

Tool Stack Used

  • ⎈Kubernetes
  • πŸ“ŠPrometheus
  • πŸ“ŠGrafana
  • πŸ”§Alertmanager
  • πŸ”§Helm