Cluster operationsLesson 15 of 16
Chaos Engineering on Kubernetes
Failures will happen in production whether you plan for them or not. Chaos engineering breaks things on purpose, in a controlled way, so you find the missing retry or PodDisruptionBudget before your users do.
Steady state99.95% · p99 180 ms
Blast radius—
Hypothesis—
Finding—
RequestResponse / reportWatchAppears in a later step
What you will learn
- Steady state and a falsifiable hypothesis
- Blast radius and abort conditions tied to SLO metrics
- What Pod kills, latency and node drains reveal
- Losing a zone and stressing CPU
- Game days and automated, repeated experiments
Experiments and what they usually find
| Experiment | Chaos Mesh | LitmusChaos fault | Typical finding | Fix |
|---|---|---|---|---|
| Kill a Pod | PodChaos pod-kill | pod-delete | Failed in-flight requests, slow startup | Retries with backoff, readiness probes, graceful shutdown |
| Inject latency | NetworkChaos delay | pod-network-latency | Slowness spreads to callers | Timeouts, circuit breakers |
| Packet loss | NetworkChaos loss | pod-network-loss | Long hangs, retry storms | Timeouts, retry budgets |
| Drain a node | (use kubectl drain) | node-drain | All replicas on one node, eviction gaps | PodDisruptionBudget, topology spread |
| Lose a zone | NetworkChaos partition, cloud chaos | cloud faults | Not enough capacity left | Headroom per zone, autoscaler limits |
| Stress CPU | StressChaos cpu | pod-cpu-hog | Throttling, late autoscaling | Requests and limits, HPA tuning |
Try it yourself
# Install Chaos Mesh (containerd runtime) into its own namespace
helm repo add chaos-mesh https://charts.chaos-mesh.org
helm install chaos-mesh chaos-mesh/chaos-mesh -n chaos-mesh --create-namespace \
--set chaosDaemon.runtime=containerd \
--set chaosDaemon.socketPath=/run/containerd/containerd.sock
# Before: check replicas, spread and PDBs
kubectl get pods -n staging -l app=cart -o wide
kubectl get pdb -n staging
# Kill one cart Pod
cat <<'EOF' | kubectl apply -f -
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
name: kill-one-cart
namespace: staging
spec:
action: pod-kill
mode: one
selector:
namespaces: [staging]
labelSelectors:
app: cart
EOF
kubectl get pods -n staging -l app=cart -w # watch the replacement
# Add 500 ms latency to one cart Pod for 2 minutes
cat <<'EOF' | kubectl apply -f -
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
name: cart-delay
namespace: staging
spec:
action: delay
mode: one
selector:
namespaces: [staging]
labelSelectors:
app: cart
delay:
latency: '500ms'
duration: '2m'
EOF
# Stop the experiments early
kubectl delete podchaos kill-one-cart -n staging
kubectl delete networkchaos cart-delay -n staging
Check yourself
Further reading: Principles of Chaos Engineering · Chaos Mesh docs · LitmusChaos · LitmusChaos probes · When a Pod Dies (Self-Healing) · Draining Nodes and Upgrading the Cluster