How mlops-devops-04-26/aiops-anomaly-detection-predictive-analysis-labs works
1. What the repo is
- This repository is a local Kubernetes AIOps lab, not a general-purpose app. It demonstrates two monitoring patterns on the same sample service: real-time CPU anomaly detection and predictive analysis.
- The whole system is meant to run on a laptop using a local Kind cluster.
2. Execution boundary
- The architecture splits into two main environments: the local machine and the Kind Kubernetes cluster.
- The local machine runs setup scripts, traffic generators, and port-forwards. The cluster runs the Product Store app plus the monitoring stack.
3. Cluster topology
- The Kind setup uses a dedicated cluster named aiops-lab with 1 control-plane node and 2 worker nodes.
- This matters architecturally because the labs are designed to exercise multi-node Kubernetes scheduling and monitoring behavior, while still staying fully local.
4. Application subsystem
- The sample workload is Product Store, implemented in apps/product-store/server.py.
- It exposes three endpoints: /health, /products, and /load.
- The app is intentionally simple: normal requests are low-cost, while /load burns CPU to simulate an incident.
5. How the app is deployed
- In Lab 1, the app is not built as a container image. Instead, the Python source is stored in a ConfigMap and mounted into the deployment.
- The app runs as two pods in the aiops-lab namespace, behind an internal Kubernetes Service.
- CPU and memory requests are explicitly set, and the CPU request becomes the baseline used by the alert logic.
6. Monitoring stack
- The monitoring layer is installed in the monitoring namespace using the kube-prometheus-stack Helm chart.
- This gives the lab its three core observability components:
- Prometheus for scraping metrics and evaluating rules
- Alertmanager for routing alerts
- Grafana for dashboarding
- The Slack webhook is injected through generated Helm values, keeping secrets out of git.
7. Lab 1 data flow: anomaly detection
- Traffic reaches Product Store, CPU usage rises, and Prometheus scrapes the pod metrics.
- The Lab 1 rule compares actual CPU usage / requested CPU.
- If the ratio stays above 0.75 for 2 minutes, Prometheus marks the alert as firing.
- Alertmanager receives that firing alert and sends the notification to Slack through an incoming webhook.
8. Lab 1 visualization path
- Grafana reads from Prometheus and shows the same CPU behavior on a dashboard.
- The dashboard is part of the repo’s Kubernetes manifests, so it is deployed alongside the app and alert rule.
- This gives a second validation path: the alert is not only sent, it is also visible as a metric trend.
9. Lab 2 data flow: predictive analysis
- Lab 2 keeps the same app and monitoring stack, but adds a second Prometheus rule.
- That rule uses predict_linear on recent CPU ratio samples to forecast whether the workload will exceed the same threshold soon.
- This is a forward-looking warning, not ML: it is Prometheus time-series forecasting over the last 10 minutes, predicting 5 minutes ahead.
10. Alerting boundary
- Alert routing is intentionally separated from alert detection.
- Prometheus decides whether a condition is true, and Alertmanager decides where it goes.
- Slack is the external notification sink; it is not part of the cluster and is configured entirely through the webhook.
11. Traffic generation
- The repo includes shell scripts that generate two traffic patterns:
- normal baseline requests to /health and /products
- CPU-heavy requests to /load
- This traffic is the input that drives the monitoring story; there is no synthetic telemetry generator separate from the app traffic itself.
12. Operational scripts
- Top-level scripts handle cluster lifecycle and validation:
- create/delete the Kind cluster
- check required tools
- verify that the lab deployed correctly
- Lab-specific scripts handle deployment, cleanup, traffic, and port-forwarding.
- Architecturally, these scripts are the control plane for the lab, while Kubernetes is the runtime plane.
13. Access pattern
- The services are internal by default.
- Local access is provided through kubectl port-forward, exposing Grafana and the Product Store API on localhost without changing cluster networking or service type.
14. Repository structure as system boundaries
- clusters/kind/ defines the local cluster substrate.
- apps/product-store/ contains the workload source.
- labs/lab-01-anomaly-detection/ contains the baseline monitoring app manifests, rule, dashboard, scripts, and traffic.
- labs/lab-02-predictive-analysis/ adds the predictive rule on top of the same base environment.
- diagrams/ documents the intended end-to-end flows, especially the alert path to Slack.
15. What to show in an architecture diagram
- The key nodes are: local machine, Kind cluster, aiops-lab namespace, monitoring namespace, Product Store pods, Prometheus, Alertmanager, Grafana, and Slack.
- The main arrows are:
- local scripts → Kind cluster
- traffic → Product Store Service → Product Store pods
- Product Store pods → Prometheus
- Prometheus → Alertmanager → Slack
- Prometheus → Grafana
- Lab 2 adds one extra rule path from Prometheus evaluation to a predictive alert, but reuses the same runtime and monitoring stack.
Main entry points: values-template.yaml Helm values · 02-product-store-deployment.yaml Product pods · 03-product-store-service.yaml Store service · 01-product-store-configmap.yaml App ConfigMap
Components 20
Local machine
Scripts and traffic generators that control the lab from the laptop.
- Lab scripts · Top-level cluster lifecycle and validation scripts.
scripts - Kind config · Defines the local aiops-lab Kind topology.
clusters/kind/aiops-lab-kind-config.yaml - Deploy lab · Installs the baseline anomaly-detection lab.
labs/lab-01-anomaly-detection/scripts/deploy-lab.sh - Traffic gen · Baseline and CPU-burn request generators.
labs/lab-01-anomaly-detection/traffic/normal-traffic.sh - Port-forward · Exposes cluster services on localhost.
labs/lab-01-anomaly-detection/scripts/port-forward.sh
Kind cluster
Local Kubernetes runtime created as aiops-lab.
- Kind cluster · Local multi-node cluster running the lab.
- aiops-lab · Namespace for the sample workload.
labs/lab-01-anomaly-detection/k8s/00-namespace.yaml - monitoring · Namespace for the observability stack.
aiops-lab namespace
Product Store workload and lab-specific manifests.
- Product Store · Simple service with health, product, and load endpoints.
apps/product-store/server.py - App ConfigMap · Mounts the Python source into the workload.
labs/lab-01-anomaly-detection/k8s/01-product-store-configmap.yaml - Product pods · Two-pod Product Store deployment with CPU baseline requests.
labs/lab-01-anomaly-detection/k8s/02-product-store-deployment.yaml - Store service · Internal Service fronting the Product Store pods.
labs/lab-01-anomaly-detection/k8s/03-product-store-service.yaml - CPU alert · Firing alert when CPU usage exceeds request ratio.
labs/lab-01-anomaly-detection/k8s/04-product-store-cpu-alert.yaml - Predictive rule · Lab 2 forecast using predict_linear over recent CPU ratio.
labs/lab-02-predictive-analysis/product-store-predictive-rule.yaml - Grafana dashboard · Dashboard for validating the same CPU behavior visually.
labs/lab-01-anomaly-detection/k8s/05-grafana-dashboard.yaml
monitoring namespace
Prometheus stack and dashboarding components.
- Helm values · Generated values for kube-prometheus-stack and Slack webhook wiring.
labs/lab-01-anomaly-detection/monitoring/values-template.yaml - Prometheus · Scrapes metrics and evaluates recording and alert rules.
- Alertmanager · Routes firing alerts to the configured notification sink.
- Grafana · Reads from Prometheus and visualizes workload behavior.
Other components
- Slack · Incoming webhook target for alert notifications.
Connections 20
- Lab scripts → Kind cluster: create/manage · Creates, deletes, and validates the local cluster.
- Kind config → Kind cluster: configure · Defines the multi-node Kind topology.
- Deploy lab → Kind cluster: deploy · Installs the lab workload and monitoring manifests.
- Traffic gen → Store service: generate requests · Drives normal and CPU-heavy app traffic.
- Port-forward → Store service: expose · Makes the internal service reachable on localhost.
- Kind cluster → aiops-lab: hosts · Runs the application namespace inside the cluster.
- Kind cluster → monitoring: hosts · Runs the monitoring namespace inside the cluster.
- Product Store → App ConfigMap: stored as · Application source is mounted from a ConfigMap in lab 1.
- App ConfigMap → Product pods: mounted into · Supplies the runtime code to the deployment.
- Product pods → Store service: exposed by · Service fronts the two Product Store pods.
- CPU alert → Prometheus: evaluated by · Prometheus evaluates the CPU ratio alert rule.
- Predictive rule → Prometheus: evaluated by · Prometheus evaluates the predictive forecast rule.
- Product pods → Prometheus: scraped by · Prometheus scrapes pod metrics from the workload.
- Prometheus → Alertmanager: fires alerts · Firing alerts are handed off for routing.
- Alertmanager → Slack: notifies · Slack receives alerts via incoming webhook.
- Prometheus → Grafana: queried by · Grafana uses Prometheus as its data source.
- Grafana dashboard → Grafana: loads into · Dashboard manifest is deployed with the lab.
- Helm values → Prometheus: configures · Helm values configure the Prometheus stack.
- Helm values → Alertmanager: configures · Helm values wire notification routing.
- Helm values → Grafana: configures · Helm values enable Grafana in the stack.