Chaos Testing — Chaos Engineering
Overview
Chaos engineering is the discipline of experimenting on a system in order to build confidence in its ability to withstand turbulent conditions in production. Rather than waiting for failures to happen organically, chaos engineering proactively injects controlled faults to expose weaknesses before they cause real outages.
The discipline is grounded in the Principles of Chaos Engineering (principlesofchaos.org), which define a rigorous, experiment-driven approach to resilience validation:
- Build a hypothesis around steady-state behavior — define what "normal" looks like in terms of measurable business and system metrics.
- Vary real-world events — inject failures that reflect things that actually happen (server crashes, network partitions, disk full, dependency latency).
- Run experiments in production — only production truly represents production; start with staging, but graduate to production with safeguards.
- Automate experiments to run continuously — one-off experiments decay in value; automated chaos builds lasting confidence.
- Minimize blast radius — design experiments to limit the scope of impact, and have abort conditions ready.
Reference: Chaos Engineering: System Resiliency in Practice by Casey Rosenthal & Nora Jones (O'Reilly, 2020) is the definitive guide to the discipline, covering theory, organizational adoption, and practical tooling.
Core Concepts
Steady-State Hypothesis
The steady-state hypothesis defines the normal, expected behavior of a system using measurable indicators. Before injecting any fault, you must establish what "healthy" looks like so you can detect whether the system degrades. Common steady-state metrics include request success rate, p99 latency, error rate, throughput, and queue depth. The experiment succeeds if the steady state is maintained despite the injected fault, and fails if the steady state is violated.
Example hypothesis: "When 10% of application pods are terminated, the request success rate remains above 99.5% and p99 latency stays below 500ms."
Blast Radius
Blast radius is the scope of potential impact of a chaos experiment. Effective chaos engineering demands strict control over blast radius — start with the smallest possible scope and expand gradually as confidence grows. Controls include targeting a single host or pod, limiting experiment duration, defining automatic abort conditions (kill switches), running during low-traffic windows initially, and having rollback procedures ready.
Game Days
A game day is a planned event where teams deliberately inject failures into their systems and practice their incident response. Game days combine chaos experiments with organizational readiness: teams observe how monitoring, alerting, runbooks, and human coordination perform under realistic failure conditions. They are typically scheduled, cross-team events with defined scenarios, observers, and post-game retrospectives.
Experiment Design
Designing a chaos experiment follows a structured methodology:
Form a hypothesis — Identify a steady-state metric and predict what will happen when a specific failure is introduced. Example: "If we lose one availability zone, failover completes within 30 seconds and no requests are dropped."
Design the smallest experiment — Start with the most limited scope that can test the hypothesis. Target a single instance, a single failure mode, and a short duration. Prefer reversible faults (latency injection) over destructive ones (data corruption) when starting out.
Measure and observe — Instrument the experiment to capture the steady-state metrics, system behavior, and any side effects. Use existing monitoring dashboards and add experiment-specific telemetry if needed.
Analyze results — Compare observed behavior against the hypothesis. If the steady state held, confidence increases. If it broke, you have discovered a real weakness to fix. Document findings either way.
Expand or remediate — If the experiment passed, gradually increase blast radius (more instances, longer duration, production environment). If it failed, fix the underlying issue and re-run the experiment.
Common Failure Modes
| Category |
Failure Mode |
Example |
| Infrastructure |
Host/VM termination |
Kill a random EC2 instance or Kubernetes pod |
| Infrastructure |
Availability zone loss |
Simulate an entire AZ going offline |
| Infrastructure |
Disk full |
Fill disk to capacity on a target host |
| Network |
Latency injection |
Add 500ms latency to inter-service calls |
| Network |
Packet loss |
Drop 10% of packets between services |
| Network |
DNS failure |
Return NXDOMAIN for a downstream dependency |
| Network |
Partition |
Block traffic between two service groups |
| Application |
CPU stress |
Consume 90% CPU on target hosts |
| Application |
Memory pressure |
Allocate memory until near OOM conditions |
| Application |
Process crash |
Kill the application process (not the host) |
| Application |
Exception injection |
Force specific error codes from a dependency |
| Data |
Clock skew |
Shift system time forward or backward |
| Data |
Data corruption simulation |
Return malformed responses from a dependency |
| Dependencies |
Third-party outage |
Block or timeout calls to external APIs |
| Dependencies |
Database failover |
Trigger a primary-to-replica failover |
| Dependencies |
Cache eviction |
Flush the entire cache (cold cache scenario) |
Cross-Platform Tools
| Tool |
Type |
Target |
Open Source |
| Chaos Monkey |
Random instance termination |
AWS VMs / cloud instances |
Yes (Netflix OSS) |
| Gremlin |
SaaS fault injection platform |
Multi-layer (infra, network, app, data) |
No (commercial SaaS, free tier available) |
| Litmus |
Kubernetes chaos engineering (CNCF) |
Kubernetes + cloud resources + bare metal |
Yes (Apache 2.0) |
| Chaos Mesh |
Kubernetes fault injection |
Kubernetes only |
Yes (Apache 2.0) |
| Toxiproxy |
TCP proxy for simulating network faults |
Any TCP connection (language-agnostic) |
Yes (Shopify, MIT) |
| Pumba |
Container chaos tool |
Docker containers |
Yes (Apache 2.0) |
| AWS Fault Injection Service |
Managed chaos engineering service |
AWS resources (EC2, ECS, EKS, RDS, etc.) |
No (AWS managed service) |
| Azure Chaos Studio |
Managed chaos engineering service |
Azure resources (VMs, AKS, Cosmos DB, etc.) |
No (Azure managed service) |
Toxiproxy
Toxiproxy is a TCP proxy that lets you simulate network conditions between your application and its dependencies. It is lightweight, language-agnostic, and ideal for integration testing environments.
Setup
# Install Toxiproxy server
# macOS
brew install toxiproxy
# Linux (download binary)
wget https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy-server-linux-amd64 -O toxiproxy-server
chmod +x toxiproxy-server
# Start the Toxiproxy server
./toxiproxy-server &
# Create a proxy for your database connection
toxiproxy-cli create postgres_primary \
--listen 127.0.0.1:15432 \
--upstream 127.0.0.1:5432
Usage Example — Simulating Latency
# Add 500ms latency to all traffic through the proxy
toxiproxy-cli toxic add postgres_primary \
--type latency \
--attribute latency=500 \
--attribute jitter=100
# Your application connects to 127.0.0.1:15432 instead of :5432
# and now experiences ~500ms (+/- 100ms) of added latency on every query
# Remove the toxic when done
toxiproxy-cli toxic remove postgres_primary --toxicName latency_downstream
Usage Example — Simulating Connection Loss
# Simulate a complete connection timeout (no data flows)
toxiproxy-cli toxic add postgres_primary \
--type timeout \
--attribute timeout=0
# Simulate the downstream service going away entirely
toxiproxy-cli toggle postgres_primary # disables the proxy
# Re-enable
toxiproxy-cli toggle postgres_primary # toggles it back on
Programmatic Usage (Node.js)
import Toxiproxy from "toxiproxy-node-client";
const toxiproxy = new Toxiproxy("http://localhost:8474");
// Create a proxy
const proxy = await toxiproxy.createProxy({
name: "redis_cache",
listen: "127.0.0.1:16379",
upstream: "127.0.0.1:6379",
});
// Add latency toxic
await proxy.addToxic({
type: "latency",
attributes: { latency: 200, jitter: 50 },
});
// Run your test against 127.0.0.1:16379
// ...
// Clean up
await proxy.remove();
Litmus
Litmus is a CNCF project that provides a complete chaos engineering platform for Kubernetes. It uses a CRD-based approach where chaos experiments are defined as Kubernetes resources.
ChaosEngine Example — Pod Delete Experiment
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: pod-delete-chaos
namespace: default
spec:
appinfo:
appns: "default"
applabel: "app=my-api"
appkind: "deployment"
engineState: "active"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-delete
spec:
components:
env:
# Number of pods to target
- name: TOTAL_CHAOS_DURATION
value: "30"
# Duration between each pod deletion (seconds)
- name: CHAOS_INTERVAL
value: "10"
# Forceful deletion (like kill -9)
- name: FORCE
value: "false"
# Number of pods to delete at a time
- name: PODS_AFFECTED_PERC
value: "50"
probe:
- name: "check-api-health"
type: "httpProbe"
httpProbe/inputs:
url: "http://my-api.default.svc:8080/healthz"
method:
get:
criteria: "=="
responseCode: "200"
mode: "Continuous"
runProperties:
probeTimeout: 5s
interval: 2s
retry: 3
This experiment deletes 50% of pods matching app=my-api every 10 seconds for 30 seconds, while continuously probing the health endpoint to verify the steady-state hypothesis (the API remains responsive).
Chaos Mesh
Chaos Mesh is a Kubernetes-native chaos engineering platform that supports network, pod, stress, I/O, time, and DNS fault injection through CRDs.
NetworkChaos Example — Latency and Packet Loss
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
name: network-delay-payment-service
namespace: chaos-testing
spec:
action: delay
mode: all
selector:
namespaces:
- production
labelSelectors:
app: payment-service
delay:
latency: "200ms"
correlation: "75"
jitter: "50ms"
direction: to
target:
selector:
namespaces:
- production
labelSelectors:
app: order-service
mode: all
duration: "5m"
scheduler:
cron: "@every 24h"
This experiment injects 200ms of latency (with 50ms jitter and 75% correlation) on all traffic from payment-service to order-service for 5 minutes, running daily on a cron schedule.
NetworkChaos Example — Partition
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
name: network-partition-db
namespace: chaos-testing
spec:
action: partition
mode: all
selector:
namespaces:
- production
labelSelectors:
app: api-gateway
direction: to
target:
selector:
namespaces:
- production
labelSelectors:
app: database-proxy
mode: all
duration: "2m"
CI/CD Integration
Chaos experiments should be integrated into your CI/CD pipeline systematically, with increasing scope at each stage:
After integration tests pass — Chaos tests run only when the system is known to be functionally correct. Running chaos against a broken build wastes time.
Start with staging environments — Run automated chaos experiments in staging on every deployment to catch resilience regressions early. Use Litmus, Chaos Mesh, or Toxiproxy experiments that are defined as code alongside your application.
Gate production deployments — Include chaos experiment results as a deployment gate. If the service cannot survive pod termination or latency injection in staging, it should not be promoted to production.
Expand to production with safeguards — Once experiments consistently pass in staging, graduate them to production with strict controls:
- Run during low-traffic windows initially
- Use canary or blue-green deployments to limit blast radius
- Define automatic abort conditions (if error rate exceeds threshold, halt the experiment)
- Have a human-in-the-loop approval for destructive experiments
Schedule recurring experiments — Use cron-based scheduling (Chaos Mesh scheduler, CI cron jobs) to run chaos experiments continuously, not just at deploy time.
CI/CD Pipeline with Chaos Integration
│
├── Build + Static Analysis
│
├── Unit Tests
│
├── Integration Tests (with Toxiproxy for dependency faults)
│
├── Deploy to Staging
│
├── Chaos Tests in Staging ──► Litmus pod-delete, NetworkChaos experiments
│ │
│ └── Abort deployment if steady-state hypothesis violated
│
├── Deploy to Production (canary)
│
└── Chaos Tests in Production ──► Scheduled experiments with kill switches
Game Day Checklist
Define objectives — Select the systems to test and the failure scenarios to simulate. Align on what you want to learn, not what you want to prove.
Establish steady-state metrics — Agree on the measurable indicators of system health (error rate, latency, throughput) and the thresholds that constitute a failure.
Prepare the experiments — Write or configure the chaos experiments, test them in a non-production environment, and verify they can be aborted quickly.
Brief all participants — Ensure all teams involved (SREs, developers, on-call, support) understand the plan, timeline, and their roles. Designate an experiment lead, observers, and a safety controller.
Verify monitoring and alerting — Confirm that dashboards are up, alerting is active, and on-call rotations are staffed. You must be able to see the impact in real time.
Confirm rollback procedures — Validate that you can abort the experiment and restore normal operations within a defined time window. Test the kill switch before starting.
Execute the experiment — Run the chaos injection according to plan. Observers record system behavior, alerting behavior, and team response actions.
Monitor and respond — The team responds to the injected failure as if it were a real incident. This exercises runbooks, communication channels, and escalation procedures.
Abort if necessary — If the blast radius exceeds expectations or real user impact is detected beyond acceptable thresholds, trigger the abort condition immediately.
Conduct a retrospective — After the game day, hold a blameless retrospective. Document what went well, what surprised the team, what broke, and what actions to take. Create tickets for discovered weaknesses.
Track and remediate — File issues for every weakness discovered. Re-run the experiment after fixes are applied to verify improvement.
Best Practices
- Start small and expand gradually — Begin with a single pod or instance in a non-production environment. Increase blast radius only as confidence grows.
- Automate experiments — Manual chaos is a one-time event; automated chaos is continuous confidence. Define experiments as code and run them in CI/CD.
- Test in production, but with safeguards — Production is the only environment that truly represents production. Use kill switches, canary scopes, and low-traffic windows to manage risk.
- Establish steady state before injecting faults — Never run a chaos experiment against a system whose baseline health is unknown or degraded.
- Define abort conditions upfront — Every experiment must have clear criteria for when to stop (error rate threshold, latency ceiling, manual kill switch).
- Make experiments observable — Tag chaos experiments in your monitoring system so you can correlate injected faults with observed impact. Use experiment IDs in logs and dashboards.
- Run game days regularly — Schedule game days quarterly at minimum. They exercise not just systems but also people and processes.
- Involve the whole team — Chaos engineering is not just for SREs. Developers, product managers, and support teams all benefit from understanding failure modes.
- Fix what you find — The value of chaos engineering is in the remediation, not the experiment itself. Every discovered weakness should result in an actionable improvement.
- Document and share learnings — Publish experiment results, both successes and failures, so the broader organization builds institutional knowledge about system resilience.
1---
2name: chaos-testing
3license: MIT
4description: 'Use when designing or implementing chaos engineering experiments to verify system resilience under failure conditions. Covers chaos engineering principles, steady-state hypothesis, blast radius management, game days, and tools like Chaos Monkey, Gremlin, Litmus, Chaos Mesh, Toxiproxy, and cloud-native fault injection services. USE FOR: chaos engineering, fault injection, resilience testing, game days, steady-state hypothesis, blast radius, Chaos Monkey, Gremlin, Litmus, Chaos Mesh, Toxiproxy, AWS Fault Injection Service, Azure Chaos Studio DO NOT USE FOR: load testing without fault injection (use performance-testing), general system monitoring (use logging-monitoring), disaster recovery planning (use architecture skills)'
5metadata:
6 source: https://skillmd.com/skills/aibot88/chaos-testing
7 metadata:
8 displayName: Chaos Testing
9 author: Tyler-R-Kendrick
10 compatibility: claude, copilot, cursor
11 references:
12 - title: Principles of Chaos Engineering
13 url: https://principlesofchaos.org
14 - title: Litmus Chaos Engineering GitHub Repository
15 url: https://github.com/litmuschaos/litmus
16 - title: Chaos Mesh Documentation
17 url: https://chaos-mesh.org/docs/
18---
19
20# Chaos Testing — Chaos Engineering
21
22## Overview
23
24**Chaos engineering** is the discipline of experimenting on a system in order to build confidence in its ability to withstand turbulent conditions in production. Rather than waiting for failures to happen organically, chaos engineering proactively injects controlled faults to expose weaknesses before they cause real outages.
25
26The discipline is grounded in the **Principles of Chaos Engineering** ([principlesofchaos.org](https://principlesofchaos.org)), which define a rigorous, experiment-driven approach to resilience validation:
27
281. **Build a hypothesis around steady-state behavior** — define what "normal" looks like in terms of measurable business and system metrics.
292. **Vary real-world events** — inject failures that reflect things that actually happen (server crashes, network partitions, disk full, dependency latency).
303. **Run experiments in production** — only production truly represents production; start with staging, but graduate to production with safeguards.
314. **Automate experiments to run continuously** — one-off experiments decay in value; automated chaos builds lasting confidence.
325. **Minimize blast radius** — design experiments to limit the scope of impact, and have abort conditions ready.
33
34> **Reference**: *Chaos Engineering: System Resiliency in Practice* by Casey Rosenthal & Nora Jones (O'Reilly, 2020) is the definitive guide to the discipline, covering theory, organizational adoption, and practical tooling.
35
36## Core Concepts
37
38### Steady-State Hypothesis
39
40The steady-state hypothesis defines the normal, expected behavior of a system using measurable indicators. Before injecting any fault, you must establish what "healthy" looks like so you can detect whether the system degrades. Common steady-state metrics include request success rate, p99 latency, error rate, throughput, and queue depth. The experiment succeeds if the steady state is maintained despite the injected fault, and fails if the steady state is violated.
41
42**Example hypothesis**: "When 10% of application pods are terminated, the request success rate remains above 99.5% and p99 latency stays below 500ms."
43
44### Blast Radius
45
46Blast radius is the scope of potential impact of a chaos experiment. Effective chaos engineering demands strict control over blast radius — start with the smallest possible scope and expand gradually as confidence grows. Controls include targeting a single host or pod, limiting experiment duration, defining automatic abort conditions (kill switches), running during low-traffic windows initially, and having rollback procedures ready.
47
48### Game Days
49
50A game day is a planned event where teams deliberately inject failures into their systems and practice their incident response. Game days combine chaos experiments with organizational readiness: teams observe how monitoring, alerting, runbooks, and human coordination perform under realistic failure conditions. They are typically scheduled, cross-team events with defined scenarios, observers, and post-game retrospectives.
51
52## Experiment Design
53
54Designing a chaos experiment follows a structured methodology:
55
561. **Form a hypothesis** — Identify a steady-state metric and predict what will happen when a specific failure is introduced. Example: "If we lose one availability zone, failover completes within 30 seconds and no requests are dropped."
57
582. **Design the smallest experiment** — Start with the most limited scope that can test the hypothesis. Target a single instance, a single failure mode, and a short duration. Prefer reversible faults (latency injection) over destructive ones (data corruption) when starting out.
59
603. **Measure and observe** — Instrument the experiment to capture the steady-state metrics, system behavior, and any side effects. Use existing monitoring dashboards and add experiment-specific telemetry if needed.
61
624. **Analyze results** — Compare observed behavior against the hypothesis. If the steady state held, confidence increases. If it broke, you have discovered a real weakness to fix. Document findings either way.
63
645. **Expand or remediate** — If the experiment passed, gradually increase blast radius (more instances, longer duration, production environment). If it failed, fix the underlying issue and re-run the experiment.
65
66## Common Failure Modes
67
68| Category | Failure Mode | Example |
69|----------|-------------|---------|
70| **Infrastructure** | Host/VM termination | Kill a random EC2 instance or Kubernetes pod |
71| **Infrastructure** | Availability zone loss | Simulate an entire AZ going offline |
72| **Infrastructure** | Disk full | Fill disk to capacity on a target host |
73| **Network** | Latency injection | Add 500ms latency to inter-service calls |
74| **Network** | Packet loss | Drop 10% of packets between services |
75| **Network** | DNS failure | Return NXDOMAIN for a downstream dependency |
76| **Network** | Partition | Block traffic between two service groups |
77| **Application** | CPU stress | Consume 90% CPU on target hosts |
78| **Application** | Memory pressure | Allocate memory until near OOM conditions |
79| **Application** | Process crash | Kill the application process (not the host) |
80| **Application** | Exception injection | Force specific error codes from a dependency |
81| **Data** | Clock skew | Shift system time forward or backward |
82| **Data** | Data corruption simulation | Return malformed responses from a dependency |
83| **Dependencies** | Third-party outage | Block or timeout calls to external APIs |
84| **Dependencies** | Database failover | Trigger a primary-to-replica failover |
85| **Dependencies** | Cache eviction | Flush the entire cache (cold cache scenario) |
86
87## Cross-Platform Tools
88
89| Tool | Type | Target | Open Source |
90|------|------|--------|-------------|
91| **Chaos Monkey** | Random instance termination | AWS VMs / cloud instances | Yes (Netflix OSS) |
92| **Gremlin** | SaaS fault injection platform | Multi-layer (infra, network, app, data) | No (commercial SaaS, free tier available) |
93| **Litmus** | Kubernetes chaos engineering (CNCF) | Kubernetes + cloud resources + bare metal | Yes (Apache 2.0) |
94| **Chaos Mesh** | Kubernetes fault injection | Kubernetes only | Yes (Apache 2.0) |
95| **Toxiproxy** | TCP proxy for simulating network faults | Any TCP connection (language-agnostic) | Yes (Shopify, MIT) |
96| **Pumba** | Container chaos tool | Docker containers | Yes (Apache 2.0) |
97| **AWS Fault Injection Service** | Managed chaos engineering service | AWS resources (EC2, ECS, EKS, RDS, etc.) | No (AWS managed service) |
98| **Azure Chaos Studio** | Managed chaos engineering service | Azure resources (VMs, AKS, Cosmos DB, etc.) | No (Azure managed service) |
99
100## Toxiproxy
101
102[Toxiproxy](https://github.com/Shopify/toxiproxy) is a TCP proxy that lets you simulate network conditions between your application and its dependencies. It is lightweight, language-agnostic, and ideal for integration testing environments.
103
104### Setup
105
106```bash
107# Install Toxiproxy server
108# macOS
109brew install toxiproxy
110
111# Linux (download binary)
112wget https://github.com/Shopify/toxiproxy/releases/download/v2.9.0/toxiproxy-server-linux-amd64 -O toxiproxy-server
113chmod +x toxiproxy-server
114
115# Start the Toxiproxy server
116./toxiproxy-server &
117
118# Create a proxy for your database connection
119toxiproxy-cli create postgres_primary \
120 --listen 127.0.0.1:15432 \
121 --upstream 127.0.0.1:5432
122```
123
124### Usage Example — Simulating Latency
125
126```bash
127# Add 500ms latency to all traffic through the proxy
128toxiproxy-cli toxic add postgres_primary \
129 --type latency \
130 --attribute latency=500 \
131 --attribute jitter=100
132
133# Your application connects to 127.0.0.1:15432 instead of :5432
134# and now experiences ~500ms (+/- 100ms) of added latency on every query
135
136# Remove the toxic when done
137toxiproxy-cli toxic remove postgres_primary --toxicName latency_downstream
138```
139
140### Usage Example — Simulating Connection Loss
141
142```bash
143# Simulate a complete connection timeout (no data flows)
144toxiproxy-cli toxic add postgres_primary \
145 --type timeout \
146 --attribute timeout=0
147
148# Simulate the downstream service going away entirely
149toxiproxy-cli toggle postgres_primary # disables the proxy
150
151# Re-enable
152toxiproxy-cli toggle postgres_primary # toggles it back on
153```
154
155### Programmatic Usage (Node.js)
156
157```javascript
158import Toxiproxy from "toxiproxy-node-client";
159
160const toxiproxy = new Toxiproxy("http://localhost:8474");
161
162// Create a proxy
163const proxy = await toxiproxy.createProxy({
164 name: "redis_cache",
165 listen: "127.0.0.1:16379",
166 upstream: "127.0.0.1:6379",
167});
168
169// Add latency toxic
170await proxy.addToxic({
171 type: "latency",
172 attributes: { latency: 200, jitter: 50 },
173});
174
175// Run your test against 127.0.0.1:16379
176// ...
177
178// Clean up
179await proxy.remove();
180```
181
182## Litmus
183
184[Litmus](https://litmuschaos.io/) is a CNCF project that provides a complete chaos engineering platform for Kubernetes. It uses a CRD-based approach where chaos experiments are defined as Kubernetes resources.
185
186### ChaosEngine Example — Pod Delete Experiment
187
188```yaml
189apiVersion: litmuschaos.io/v1alpha1
190kind: ChaosEngine
191metadata:
192 name: pod-delete-chaos
193 namespace: default
194spec:
195 appinfo:
196 appns: "default"
197 applabel: "app=my-api"
198 appkind: "deployment"
199 engineState: "active"
200 chaosServiceAccount: litmus-admin
201 experiments:
202 - name: pod-delete
203 spec:
204 components:
205 env:
206 # Number of pods to target
207 - name: TOTAL_CHAOS_DURATION
208 value: "30"
209 # Duration between each pod deletion (seconds)
210 - name: CHAOS_INTERVAL
211 value: "10"
212 # Forceful deletion (like kill -9)
213 - name: FORCE
214 value: "false"
215 # Number of pods to delete at a time
216 - name: PODS_AFFECTED_PERC
217 value: "50"
218 probe:
219 - name: "check-api-health"
220 type: "httpProbe"
221 httpProbe/inputs:
222 url: "http://my-api.default.svc:8080/healthz"
223 method:
224 get:
225 criteria: "=="
226 responseCode: "200"
227 mode: "Continuous"
228 runProperties:
229 probeTimeout: 5s
230 interval: 2s
231 retry: 3
232```
233
234This experiment deletes 50% of pods matching `app=my-api` every 10 seconds for 30 seconds, while continuously probing the health endpoint to verify the steady-state hypothesis (the API remains responsive).
235
236## Chaos Mesh
237
238[Chaos Mesh](https://chaos-mesh.org/) is a Kubernetes-native chaos engineering platform that supports network, pod, stress, I/O, time, and DNS fault injection through CRDs.
239
240### NetworkChaos Example — Latency and Packet Loss
241
242```yaml
243apiVersion: chaos-mesh.org/v1alpha1
244kind: NetworkChaos
245metadata:
246 name: network-delay-payment-service
247 namespace: chaos-testing
248spec:
249 action: delay
250 mode: all
251 selector:
252 namespaces:
253 - production
254 labelSelectors:
255 app: payment-service
256 delay:
257 latency: "200ms"
258 correlation: "75"
259 jitter: "50ms"
260 direction: to
261 target:
262 selector:
263 namespaces:
264 - production
265 labelSelectors:
266 app: order-service
267 mode: all
268 duration: "5m"
269 scheduler:
270 cron: "@every 24h"
271```
272
273This experiment injects 200ms of latency (with 50ms jitter and 75% correlation) on all traffic from `payment-service` to `order-service` for 5 minutes, running daily on a cron schedule.
274
275### NetworkChaos Example — Partition
276
277```yaml
278apiVersion: chaos-mesh.org/v1alpha1
279kind: NetworkChaos
280metadata:
281 name: network-partition-db
282 namespace: chaos-testing
283spec:
284 action: partition
285 mode: all
286 selector:
287 namespaces:
288 - production
289 labelSelectors:
290 app: api-gateway
291 direction: to
292 target:
293 selector:
294 namespaces:
295 - production
296 labelSelectors:
297 app: database-proxy
298 mode: all
299 duration: "2m"
300```
301
302## CI/CD Integration
303
304Chaos experiments should be integrated into your CI/CD pipeline systematically, with increasing scope at each stage:
305
3061. **After integration tests pass** — Chaos tests run only when the system is known to be functionally correct. Running chaos against a broken build wastes time.
307
3082. **Start with staging environments** — Run automated chaos experiments in staging on every deployment to catch resilience regressions early. Use Litmus, Chaos Mesh, or Toxiproxy experiments that are defined as code alongside your application.
309
3103. **Gate production deployments** — Include chaos experiment results as a deployment gate. If the service cannot survive pod termination or latency injection in staging, it should not be promoted to production.
311
3124. **Expand to production with safeguards** — Once experiments consistently pass in staging, graduate them to production with strict controls:
313 - Run during low-traffic windows initially
314 - Use canary or blue-green deployments to limit blast radius
315 - Define automatic abort conditions (if error rate exceeds threshold, halt the experiment)
316 - Have a human-in-the-loop approval for destructive experiments
317
3185. **Schedule recurring experiments** — Use cron-based scheduling (Chaos Mesh scheduler, CI cron jobs) to run chaos experiments continuously, not just at deploy time.
319
320```
321CI/CD Pipeline with Chaos Integration
322 │
323 ├── Build + Static Analysis
324 │
325 ├── Unit Tests
326 │
327 ├── Integration Tests (with Toxiproxy for dependency faults)
328 │
329 ├── Deploy to Staging
330 │
331 ├── Chaos Tests in Staging ──► Litmus pod-delete, NetworkChaos experiments
332 │ │
333 │ └── Abort deployment if steady-state hypothesis violated
334 │
335 ├── Deploy to Production (canary)
336 │
337 └── Chaos Tests in Production ──► Scheduled experiments with kill switches
338```
339
340## Game Day Checklist
341
3421. **Define objectives** — Select the systems to test and the failure scenarios to simulate. Align on what you want to learn, not what you want to prove.
343
3442. **Establish steady-state metrics** — Agree on the measurable indicators of system health (error rate, latency, throughput) and the thresholds that constitute a failure.
345
3463. **Prepare the experiments** — Write or configure the chaos experiments, test them in a non-production environment, and verify they can be aborted quickly.
347
3484. **Brief all participants** — Ensure all teams involved (SREs, developers, on-call, support) understand the plan, timeline, and their roles. Designate an experiment lead, observers, and a safety controller.
349
3505. **Verify monitoring and alerting** — Confirm that dashboards are up, alerting is active, and on-call rotations are staffed. You must be able to see the impact in real time.
351
3526. **Confirm rollback procedures** — Validate that you can abort the experiment and restore normal operations within a defined time window. Test the kill switch before starting.
353
3547. **Execute the experiment** — Run the chaos injection according to plan. Observers record system behavior, alerting behavior, and team response actions.
355
3568. **Monitor and respond** — The team responds to the injected failure as if it were a real incident. This exercises runbooks, communication channels, and escalation procedures.
357
3589. **Abort if necessary** — If the blast radius exceeds expectations or real user impact is detected beyond acceptable thresholds, trigger the abort condition immediately.
359
36010. **Conduct a retrospective** — After the game day, hold a blameless retrospective. Document what went well, what surprised the team, what broke, and what actions to take. Create tickets for discovered weaknesses.
361
36211. **Track and remediate** — File issues for every weakness discovered. Re-run the experiment after fixes are applied to verify improvement.
363
364## Best Practices
365
366- **Start small and expand gradually** — Begin with a single pod or instance in a non-production environment. Increase blast radius only as confidence grows.
367- **Automate experiments** — Manual chaos is a one-time event; automated chaos is continuous confidence. Define experiments as code and run them in CI/CD.
368- **Test in production, but with safeguards** — Production is the only environment that truly represents production. Use kill switches, canary scopes, and low-traffic windows to manage risk.
369- **Establish steady state before injecting faults** — Never run a chaos experiment against a system whose baseline health is unknown or degraded.
370- **Define abort conditions upfront** — Every experiment must have clear criteria for when to stop (error rate threshold, latency ceiling, manual kill switch).
371- **Make experiments observable** — Tag chaos experiments in your monitoring system so you can correlate injected faults with observed impact. Use experiment IDs in logs and dashboards.
372- **Run game days regularly** — Schedule game days quarterly at minimum. They exercise not just systems but also people and processes.
373- **Involve the whole team** — Chaos engineering is not just for SREs. Developers, product managers, and support teams all benefit from understanding failure modes.
374- **Fix what you find** — The value of chaos engineering is in the remediation, not the experiment itself. Every discovered weakness should result in an actionable improvement.
375- **Document and share learnings** — Publish experiment results, both successes and failures, so the broader organization builds institutional knowledge about system resilience.