Back to Blog

Building SRE-Grade Observability: Deploying Grafana and Prometheus on AKS

Published: Dec 28, 2024 by Joe Hernandez
SREAzureTerraformKubernetesAKSMonitoringGrafanaPrometheusObservability

As an SRE, observability isn't just about collecting metrics. It's about building systems that help you understand user experience, detect problems before users do, and make data-driven decisions about reliability. In this guide, I'll show you how to deploy a production-ready monitoring stack on AKS that goes beyond basic infrastructure monitoring to support true SRE practices.

Prerequisites

Before we begin, ensure you have the following:

  • An existing AKS cluster
  • Terraform installed (version 1.0.0+)
  • Azure CLI configured with appropriate permissions
  • Helm installed (for manual verification if needed)

Project Structure

Organize your Terraform project as follows:

aks-monitoring/
├── main.tf
├── variables.tf
├── outputs.tf
└── terraform.tfvars

Provider Configuration

In main.tf, configure the AzureRM and Helm providers. In production AKS clusters, local admin accounts should be disabled (local_account_disabled = true) in favor of Microsoft Entra ID RBAC. Rather than passing static client certificates that end up in Terraform state, authenticate the Helm provider through kubelogin using Azure CLI or Managed Identity credentials:

terraform {
  required_version = ">= 1.5.0"

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
    helm = {
      source  = "hashicorp/helm"
      version = "~> 2.12"
    }
  }
}

provider "azurerm" {
  features {}
}

data "azurerm_kubernetes_cluster" "aks" {
  name                = var.aks_cluster_name
  resource_group_name = var.resource_group_name
}

provider "helm" {
  kubernetes {
    host                   = data.azurerm_kubernetes_cluster.aks.kube_config[0].host
    cluster_ca_certificate = base64decode(data.azurerm_kubernetes_cluster.aks.kube_config[0].cluster_ca_certificate)

    exec {
      api_version = "client.authentication.k8s.io/v1beta1"
      command     = "kubelogin"
      args = [
        "get-token",
        "--login", "azurecli",
        "--server-id", "6dae42f8-4368-4678-94ff-3960e28e3630" # Azure Kubernetes Service AAD Server
      ]
    }
  }
}

Deploying Prometheus and Grafana via Helm

Instead of managing standalone Prometheus, Alertmanager, and Grafana charts separately, we deploy kube-prometheus-stack so CRDs (ServiceMonitor, PodMonitor, PrometheusRule) and scrape targets are wired together out of the box.

Two production guardrails matter here:

  1. No plaintext secrets in HCL: Admin credentials come from a Kubernetes Secret populated by the Azure Key Vault Secrets Store CSI Driver (or Entra ID OAuth), never hardcoded in Helm values.
  2. No public LoadBalancer exposure: Grafana stays on ClusterIP behind our internal Ingress controller with automated TLS via cert-manager.
resource "helm_release" "kube_prometheus_stack" {
  name             = "kube-prometheus-stack"
  repository       = "https://prometheus-community.github.io/helm-charts"
  chart            = "kube-prometheus-stack"
  version          = "65.1.1"
  namespace        = "monitoring"
  create_namespace = true
  atomic           = true
  timeout          = 600

  values = [
    yamlencode({
      prometheus = {
        prometheusSpec = {
          retention = "15d"
          replicas  = 2
          storageSpec = {
            volumeClaimTemplate = {
              spec = {
                storageClassName = "managed-csi-premium"
                accessModes      = ["ReadWriteOnce"]
                resources = {
                  requests = {
                    storage = "100Gi"
                  }
                }
              }
            }
          }
        }
      }
      grafana = {
        service = {
          type = "ClusterIP"
        }
        admin = {
          existingSecret = var.grafana_admin_secret_name
          userKey        = "admin-user"
          passwordKey    = "admin-password"
        }
        ingress = {
          enabled          = true
          ingressClassName = "nginx-internal"
          annotations = {
            "cert-manager.io/cluster-issuer" = "letsencrypt-prod"
          }
          hosts = [var.grafana_hostname]
          tls = [
            {
              secretName = "grafana-tls"
              hosts      = [var.grafana_hostname]
            }
          ]
        }
      }
    })
  ]
}

Variables Configuration

Define variables with validation rules in variables.tf:

variable "aks_cluster_name" {
  type        = string
  description = "Name of the existing AKS cluster"
}

variable "resource_group_name" {
  type        = string
  description = "Resource group where the AKS cluster is deployed"
}

variable "grafana_hostname" {
  type        = string
  description = "Internal DNS hostname for the Grafana ingress"
}

variable "grafana_admin_secret_name" {
  type        = string
  description = "Name of the Kubernetes Secret (synced via Key Vault CSI) holding Grafana credentials"
  default     = "grafana-admin-kv-secret"
}

Output Configuration

Expose the internal Grafana URL and Helm release status in outputs.tf:

output "grafana_url" {
  description = "Internal HTTPS endpoint for Grafana"
  value       = "https://${var.grafana_hostname}"
}

output "monitoring_release_version" {
  description = "Deployed kube-prometheus-stack chart version"
  value       = helm_release.kube_prometheus_stack.version
}

Deploying the Monitoring Stack

  1. Initialize Terraform:
terraform init
  1. Configure terraform.tfvars:
aks_cluster_name    = "aks-prod-eastus2-01"
resource_group_name = "rg-platform-prod-eastus2"
grafana_hostname    = "grafana.internal.example.com"
  1. Plan and apply the configuration:
terraform plan -out=tfplan
terraform apply tfplan
  1. Verify the StatefulSets and pods in the monitoring namespace:
kubectl get pods,sts,ingress -n monitoring

SRE Best Practices for Your Monitoring Stack

Essential Dashboards for SRE

Create these dashboards to support SRE practices:

Service Level Indicators Dashboard

  • Request success rate (availability SLI)
  • Response time percentiles (latency SLI)
  • Error budget burn rate across 1h, 6h, and 30d windows
  • Time to detection for critical alerts

Golden Signals Dashboard

  • Latency, Traffic, Errors, Saturation
  • Per-service and per-namespace breakdown
  • Historical trends for capacity planning and right-sizing

Incident Response Dashboard

  • Current system status across all services
  • Recent deployments and Helm/Argo CD revisions
  • Upstream Azure dependency status
  • Direct runbook links in alert annotations

Multi-Window Error Budget Burn Rate Alerting

Static threshold alerts wake engineers up for transient spikes that resolve on their own. Instead, configure multi-window, multi-burn-rate alerts that only page when both a short window (5m) and a longer window (1h) exceed a 14.4x error budget burn rate (which consumes 2% of a 30-day 99.9% error budget in one hour):

# Multi-window 14.4x burn rate alert for a 99.9% availability SLO (0.001 error budget)
- alert: HighErrorBudgetBurnCritical
  expr: |
    (
      sum(rate(http_requests_total{status=~"5.."}[1h])) by (service)
      /
      sum(rate(http_requests_total[1h])) by (service)
      > (14.4 * 0.001)
    )
    and
    (
      sum(rate(http_requests_total{status=~"5.."}[5m])) by (service)
      /
      sum(rate(http_requests_total[5m])) by (service)
      > (14.4 * 0.001)
    )
  for: 2m
  labels:
    severity: critical
  annotations:
    summary: "Critical 14.4x error budget burn on {{ $labels.service }}"
    runbook_url: "https://wiki.internal/runbooks/{{ $labels.service }}-high-burn"

- alert: HighP95LatencyWarning
  expr: |
    histogram_quantile(
      0.95,
      sum(rate(http_request_duration_seconds_bucket[5m])) by (le, service)
    ) > 0.25
  for: 5m
  labels:
    severity: warning

Retention and Storage Strategy

For production SRE monitoring:

  • Short-term (15 days): High-resolution data for incident response
  • Medium-term (90 days): Aggregated data for trend analysis
  • Long-term (1+ year): Summary metrics for capacity planning

Operational Excellence

Monitoring the Monitoring

Your observability stack needs observability too:

  • Monitor Prometheus scrape success rates
  • Alert on Grafana dashboard load times
  • Track alert manager notification success
  • Monitor storage usage and retention

Disaster Recovery

Ensure your monitoring survives outages:

  • Deploy Prometheus in HA mode with multiple replicas
  • Use persistent volumes with backup strategies
  • Document recovery procedures
  • Test restore processes regularly

Conclusion

This monitoring stack provides the foundation for SRE practices like SLI/SLO management, error budget tracking, and data-driven incident response. Remember: the goal isn't just to collect metrics, but to gain insights that improve system reliability and user experience.

The real value comes from using this data to make informed decisions about where to invest engineering effort, when to slow down deployments, and how to continuously improve system reliability.

Share this post