Cheat SheetsKubernetesObservability

Observability — Cheat Sheet

Kubernetes · 1 topics. Download the PDF or the Instagram carousel and share it.

Cheat Sheet · AiCanCode.org
Observability
Kubernetes1 topicsQuick revision reference
1

Observability — Metrics, Logs & Tracing

Production Kubernetes observability uses Prometheus + Grafana for metrics, Loki or EFK for logs, and Jaeger or Tempo for distributed tracing. Together they form the three pillars of observability.

  • Three pillars of observability: Metrics (Prometheus), Logs (Loki/EFK), Traces (Jaeger/Tempo).
  • kube-prometheus-stack deploys the full metrics stack in one helm install command.
  • ServiceMonitor CRD tells Prometheus which pods to scrape — label matching is required.
  • Loki + Promtail indexes log labels (namespace, pod, app) for fast filtered queries.
  • OpenTelemetry auto-instrumentation requires zero code changes for most frameworks.
  • Golden signals: Latency, Traffic, Errors, Saturation — alert on these four, not on every symptom.
Prometheus + ServiceMonitor setup
# Install kube-prometheus-stack (Prometheus + Grafana + AlertManager)

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

helm install prometheus prometheus-community/kube-prometheus-stack \

  --namespace monitoring --create-namespace



# What it installs:

# - Prometheus Operator  → manages Prometheus instances via CRDs

# - Prometheus           → scrapes metrics

# - Grafana             → dashboards (pre-built K8s dashboards)

# - AlertManager        → routes alerts to Slack/PagerDuty

# - node-exporter        → host-level metrics (CPU, memory, disk, network)

# - kube-state-metrics   → K8s object metrics (pod counts, deployment status)



# Expose your app metrics via /metrics endpoint

# Add ServiceMonitor to tell Prometheus to scrape it:

apiVersion: monitoring.coreos.com/v1

kind: ServiceMonitor

metadata:

  name: my-app-metrics

  labels:

    release: prometheus          # must match Prometheus's serviceMonitorSelector

spec:

  selector:

    matchLabels:

      app: my-app

  endpoints:

    - port: http

      path: /metrics

      interval: 15s              # scrape every 15s



# Example Prometheus alert rule:

apiVersion: monitoring.coreos.com/v1

kind: PrometheusRule

metadata:

  name: my-app-alerts

spec:

  groups:

    - name: my-app

      rules:

        - alert: HighErrorRate

          expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.01

          for: 5m

          annotations:

            summary: "Error rate > 1% for 5 minutes"
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/kubernetes