eBPF Chaos Engineering on Kubernetes: Quick Fix Cheat Sheet
Quick Summary (TL;DR)
- eBPF injects faults below the app (tc for packets, kprobes/tracepoints for syscalls & I/O) — no code changes.
- Deploy one privileged DaemonSet agent per node; drive it with a small
ChaosExperimentCRD.- Always scope by namespace + label selector + hard pod cap, set a TTL, and add a watchdog.
- Copy-paste recipes below cover latency, loss, syscall failure, and disk I/O errors.
- Wire Prometheus/Grafana annotations so dashboards show the exact fault window.
Why eBPF for Fault Injection (30-Second Primer)
eBPF lets you run sandboxed programs at kernel hooks without a kernel module. For chaos engineering that means faults are injected below your application and above the network, so they behave like real infrastructure failures — not mock exceptions in your code.
| Hook | Use it for | Typical fault |
|---|---|---|
tc (clsact) | Network egress/ingress | Latency, loss, corruption |
kprobe/kretprobe | Syscall entry/exit | Force -EIO, -EACCES, -ETIMEDOUT |
tracepoint | Stable kernel events | Observe + gate faults |
| cgroup hooks | Per-container scoping | Blast-radius control |
Why not just tc netem? You can use it for network faults, but eBPF gives you syscall-level and I/O-level faults plus per-cgroup targeting in one programmable plane.
Prerequisites Checklist
- Linux 5.8+ (5.10/5.15 LTS recommended) —
uname -r - BTF present —
ls /sys/kernel/btf/vmlinux -
CONFIG_BPF,CONFIG_BPF_SYSCALL,CONFIG_NET_CLS_BPFenabled -
bpftoolandclang/llvmon build hosts - Privileged DaemonSet (
CAP_BPF,CAP_NET_ADMIN,CAP_SYS_ADMINor hostPID) - Kernel headers or CO-RE (BTF) for portable programs
- A dedicated
chaos-systemnamespace and RBAC
Minimal Platform Architecture
flowchart TD
A[ChaosExperiment CRD] --> B[Chaos Controller]
B --> C[Validate scope + TTL + watchdog]
C --> D[Agent DaemonSet<br/>privileged, per node]
D --> E{eBPF hook?}
E -->|Network| F[tc clsact + BPF prog]
E -->|Syscall| G[kprobe/kretprobe]
E -->|Disk I/O| H[kprobe on vfs/block]
F --> I[Target pods]
G --> I
H --> I
B --> J[Watchdog: SLO + error rate]
J -->|breach| K[Delete progs + qdiscs]
B --> L[Prometheus / Grafana annotations]
Fault Injection Recipes (Copy-Paste)
Network Latency
Add 200ms ± 50ms jitter to egress on a target pod’s veth:
# Inside the agent pod on the target node
PID=$(crictl inspectp <pod-id> | jq -r .info.pid)
VETH=$(ip -o link | awk -v p=$PID '$0 ~ "if"p"-"{print $2}' | tr -d :)
tc qdisc add dev $VETH root handle 1: prio
tc qdisc add dev $VETH parent 1:3 handle 30: netem delay 200ms 50ms distribution normal
Packet Loss
tc qdisc add dev $VETH root handle 1: prio
tc qdisc add dev $VETH parent 1:3 handle 30: netem loss 10%
# verify
tc -s qdisc show dev $VETH
Syscall Failure
Force openat to return -EACCES for a specific cgroup (all its processes):
// openat_deny.bpf.c (sketch)
SEC("kretprobe/do_sys_openat2")
int deny_openat(struct pt_regs *ctx) {
u32 cg = bpf_get_current_cgroup_id();
if (!target_cgroup(cg)) return 0;
// override return value
bpf_override_return(ctx, -EACCES);
return 0;
}
Load with bpftool prog load and attach to the kretprobe. Always gate on cgroup ID so you don’t break the node.
Disk I/O Errors
Return -EIO from vfs_read/vfs_write for a target PID:
SEC("kretprobe/vfs_write")
int fail_write(struct pt_regs *ctx) {
u32 pid = bpf_get_current_pid_tgid() >> 32;
if (!is_target_pid(pid)) return 0;
bpf_override_return(ctx, -EIO);
return 0;
}
⚠️ Never attach to
vfs_*without a PID or cgroup filter — you will corrupt the kubelet and node logs.
Blast Radius Control Cheat Sheet
| Control | Where | Example |
|---|---|---|
| Namespace | CRD field | namespace: payments-staging |
| Label selector | CRD field | app=payments-api |
| Pod cap | Controller | maxPods: 1 or maxPercent: 10 |
| Duration | CRD field | duration: 5m |
| TTL (hard stop) | Controller | ttl: 10m |
| Dry run | CRD field | dryRun: true |
| Allowlist hooks | Agent | deny vfs_* on pid 1 |
apiVersion: chaos.example.io/v1
kind: ChaosExperiment
metadata:
name: payments-latency
namespace: chaos-system
spec:
target:
namespace: payments-staging
selector: { app: payments-api }
maxPods: 1
action: network-latency
params: { delay: "200ms", jitter: "50ms" }
duration: 5m
ttl: 10m
dryRun: false
Observability Integration Snippets
Grafana annotation on experiment start/stop (from controller):
curl -X POST $GRAFANA/api/annotations \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"text":"chaos: payments-latency START","tags":["chaos","payments"]}'
Prometheus watchdog rule — auto-stop if errors spike:
- alert: ChaosWatchdog
expr: rate(http_requests_total{code=~"5.."}[1m]) > 0.05
for: 1m
labels: { severity: chaos-abort }
annotations: { summary: "Abort active chaos experiment" }
Hubble / Tetragon flow filters on the target namespace expose kernel-level drops during the run.
Experiment Design Quick Template
hypothesis: "payments-api tolerates 200ms p99 latency without 5xx"
steady_state: "p99 < 400ms, error rate < 0.1%"
fault: "network-latency 200ms ± 50ms, 1 pod, 5m"
abort_if: "p99 > 1s OR error rate > 1% OR restarts > 0"
observability: "Grafana panel + annotation, Prometheus alert"
rollback: "TTL 10m + watchdog auto-delete"
Common Failures and Fast Fixes
| Symptom | Likely cause | Fix |
|---|---|---|
Operation not permitted loading prog | Missing CAP_BPF | Add caps to DaemonSet |
tc qdisc fails on veth | Wrong interface name | Look up via crictl inspectp PID |
| Syscall fault hits whole node | No cgroup/PID filter | Gate on bpf_get_current_cgroup_id() |
| Experiment never stops | No TTL | Enforce ttl + watchdog in controller |
| App sees no latency | Fault on wrong direction | Use clsact ingress + egress |
BTF not found | Old kernel | Upgrade to 5.10+ or ship vmlinux.h |
Teardown and Safety Checklist
-
tc qdisc del dev $VETH rooton every targeted veth -
bpftool prog show→ confirm no chaos programs remain - Delete
ChaosExperimentCR (controller garbage-collects) - Verify pod restarts and error rates returned to baseline
- Remove Grafana annotations or mark experiment closed
- Log experiment result to your reliability backlog
FAQ
Do I need to modify my application code?
No. eBPF programs attach to kernel hooks (tc, kprobes, tracepoints) and affect syscalls and packets below the application layer. Containers run unchanged; you only need privileged DaemonSet pods or a pre-installed agent on each node.
What is the minimum kernel version?
Linux 5.8+ for BTF and CO-RE; 5.10/5.15 LTS for stable tc BPF, kprobe, and cgroup hooks. Check uname -r and confirm /sys/kernel/btf/vmlinux.
How do I limit an experiment to one service?
Scope by namespace, label selector, and pod count in the CRD, then enforce a hard cap in the controller (max 1 pod or 10% of replicas). Run in a dedicated namespace and use dryRun: true first.
Can eBPF inject disk I/O errors safely?
Yes, but scope tightly. Attach to kprobes on block/filesystem functions for a specific cgroup or PID, return -EIO, and set a short duration with auto-revert. Never target the node root filesystem or kubelet.
How do I auto-stop a runaway experiment?
Add a watchdog watching error rate, latency SLOs, and pod restarts. On breach, the controller deletes eBPF programs and tc qdiscs immediately. Pair with a ttl so nothing runs indefinitely.