Lab 38 - Production incident analysis
Lab 38 - Production incident analysis
InfodiscoverGoal: three tickets from users. Find the root cause with metrics, events and logs, mitigate, and write a short postmortem. Chapter: Monitoring with Prometheus and Grafana
Requires the monitoring stack from Lab 37.
Set the scene
cd ~
cat > incidents.yaml <<'YAML'
apiVersion: v1
kind: Namespace
metadata: { name: prod }
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: checkout, namespace: prod }
spec:
replicas: 2
selector: { matchLabels: { app: checkout } }
template:
metadata: { labels: { app: checkout } }
spec:
containers:
- name: checkout
image: registry.k8s.io/hpa-example
resources:
requests: { cpu: "50m" }
limits: { cpu: "50m" }
---
apiVersion: v1
kind: Service
metadata: { name: checkout, namespace: prod }
spec:
selector: { app: checkout }
ports: [{ port: 80 }]
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: reports, namespace: prod }
spec:
replicas: 1
selector: { matchLabels: { app: reports } }
template:
metadata: { labels: { app: reports } }
spec:
containers:
- name: reports
image: busybox:1.36
command: ["sh", "-c", "x=; while true; do x=\"$x$(head -c 1000000 /dev/zero | tr '\\0' a)\"; sleep 2; done"]
resources:
limits: { memory: "64Mi" }
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: catalog, namespace: prod }
spec:
replicas: 2
selector: { matchLabels: { app: catalog, track: stable } }
template:
metadata: { labels: { app: catalog, track: stable } }
spec:
containers: [{ name: web, image: "nginx:1.27" }]
---
apiVersion: apps/v1
kind: Deployment
metadata: { name: catalog-test, namespace: prod }
spec:
replicas: 1
selector: { matchLabels: { app: catalog, track: test } }
template:
metadata: { labels: { app: catalog, track: test } }
spec:
containers:
- name: web
image: nginx:1.27
command: ["sh", "-c", "rm /usr/share/nginx/html/index.html; nginx -g 'daemon off;'"]
---
apiVersion: v1
kind: Service
metadata: { name: catalog, namespace: prod }
spec:
selector: { app: catalog }
ports: [{ port: 80 }]
---
apiVersion: v1
kind: Pod
metadata: { name: traffic, namespace: prod }
spec:
containers:
- name: traffic
image: busybox:1.36
command: ["sh", "-c", "while true; do wget -qO- http://checkout >/dev/null; wget -qO- http://catalog >/dev/null 2>&1; done"]
YAML
kubectl apply -f incidents.yaml
Wait 5 minutes for the metrics to build up. Do not read the manifest - work from the symptoms.
The tickets
INC-101 - “Checkout is very slow since this morning.” - Sales
INC-102 - “The reports service keeps crashing, we lose half our reports.” - Finance
INC-103 - “About every third catalog page shows an error.” - Web team
For each ticket:
- Find the cause - Grafana, PromQL,
kubectl events,describe,logs. - Mitigate - restore service.
- Postmortem - fill in the template below.
Incident: INC-xxx
Impact: who noticed what, since when
Detection: which metric / event shows it (the query!)
Root cause:
Mitigation: what you changed
Prevention: alert, policy, test that would have caught it earlier
Hints
Solution
Clean up
kubectl delete ns prod