Chaos Mesh & LitmusChaos
On Kubernetes, chaos experiments are usually written as custom resources and run by an operator in the cluster. The two CNCF projects for this are Chaos Mesh (started at PingCAP) and LitmusChaos (started at ChaosNative, now Harness). Both kill pods, inject network faults, stress CPU and memory and run multi-step workflows; they differ in packaging and in how they check the steady state. Cloud providers offer managed equivalents (AWS Fault Injection Service, Azure Chaos Studio) for faults below Kubernetes, such as stopping instances or failing an availability zone.
Everything in this lesson needs a cluster with the operator installed, so the manifests and sessions are samples. Check each project's documentation for the version you install: the CRD fields evolve between releases.
Chaos Mesh
Install with its Helm chart into a chaos-mesh namespace (see the project's installation guide for the chart
repository and the container runtime settings for your cluster). Each fault type is its own kind in the API group
chaos-mesh.org/v1alpha1.
Kill one random checkout pod:
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata:
name: checkout-pod-kill
namespace: shop
spec:
action: pod-kill
mode: one # one random pod among those selected
selector:
namespaces: [shop]
labelSelectors:
app: checkoutAdd 300 ms of latency (±50 ms) to traffic from checkout pods to the payments service for 5 minutes:
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
name: checkout-to-payments-delay
namespace: shop
spec:
action: delay
mode: all
selector:
namespaces: [shop]
labelSelectors:
app: checkout
direction: to
target:
mode: all
selector:
namespaces: [shop]
labelSelectors:
app: payments
delay:
latency: "300ms"
jitter: "50ms"
correlation: "25"
duration: "5m"Run the pod kill every weekday at 10:00 in staging, as a regression test for readiness probes and retries:
apiVersion: chaos-mesh.org/v1alpha1
kind: Schedule
metadata:
name: weekday-pod-kill
namespace: shop-staging
spec:
schedule: "0 10 * * 1-5"
type: PodChaos
historyLimit: 5
concurrencyPolicy: Forbid
podChaos:
action: pod-kill
mode: one
selector:
namespaces: [shop-staging]
labelSelectors:
app: checkout# sample session: needs a cluster with Chaos Mesh installed
$ kubectl apply -f checkout-to-payments-delay.yaml
networkchaos.chaos-mesh.org/checkout-to-payments-delay created
$ kubectl delete networkchaos checkout-to-payments-delay -n shop # the abort button
networkchaos.chaos-mesh.org "checkout-to-payments-delay" deletedDeleting the resource stops the fault: that's the manual abort. Chaos Mesh also has a dashboard and a Workflow
kind that chains faults and checks (including HTTP requests) into one experiment.
LitmusChaos
Litmus packages faults as experiments (from its ChaosHub, such as pod-delete, pod-network-latency,
pod-cpu-hog) and runs them through a ChaosEngine resource. Its distinguishing feature is probes:
steady-state checks that run before, during or after the fault and decide whether the experiment passed. Litmus 3
also has a control plane (ChaosCenter) with a UI, scheduling and resilience scores.
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: checkout-pod-delete
namespace: shop
spec:
engineState: active
appinfo:
appns: shop
applabel: app=checkout
appkind: deployment
chaosServiceAccount: litmus-admin
experiments:
- name: pod-delete
spec:
components:
env:
- name: TOTAL_CHAOS_DURATION
value: "60" # seconds
- name: CHAOS_INTERVAL
value: "15" # delete a pod every 15 s
- name: FORCE
value: "false"
probe:
- name: checkout-health
type: httpProbe
mode: Continuous # checked throughout the experiment
httpProbe/inputs:
url: http://checkout.shop.svc.cluster.local:8080/healthz
method:
get:
criteria: ==
responseCode: "200"
runProperties:
probeTimeout: 2s
interval: 2s
retry: 1# sample session: needs a cluster with Litmus installed
$ kubectl apply -f checkout-pod-delete.yaml
chaosengine.litmuschaos.io/checkout-pod-delete created
$ kubectl get chaosresult checkout-pod-delete-pod-delete -n shop \
-o jsonpath='{.status.experimentStatus.verdict}{"\n"}'
PassA Fail verdict means a probe failed: the steady-state hypothesis was disproved. Litmus also offers
promProbe, which evaluates a PromQL query, a natural fit for SLO-based hypotheses (for example, the 5-minute
burn rate from SLO Recording Rules stays below 14.4).
Chaos Mesh or Litmus?
| Chaos Mesh | LitmusChaos | |
|---|---|---|
| model | one CRD per fault type, plus Schedule and Workflow |
ChaosEngine runs experiments from a hub; ChaosResult holds the verdict |
| steady-state checks | in workflows (HTTP tasks), or external | built-in probes: HTTP, command, Kubernetes, Prometheus |
| UI | dashboard | ChaosCenter (multi-cluster, scheduling, reports) |
| good for | quick, precise fault injection; scheduled regression chaos | experiments with pass/fail verdicts in pipelines |
Simpler tools cover narrower needs: kubectl delete pod by hand for a first game day, Toxiproxy for network faults
in integration tests, and tc netem on a test VM.
Guardrails as code
Chaos manifests deserve the same review as any change to production. A CI check can reject dangerous ones before
they are applied. The session writes two Chaos Mesh manifests and a small yq script that flags faults that
target all pods, have no duration, or select by namespace only:
mkdir -p chaos && cd chaos
cat > pod-kill.yaml <<'YML'
apiVersion: chaos-mesh.org/v1alpha1
kind: PodChaos
metadata: {name: checkout-pod-kill, namespace: shop}
spec:
action: pod-kill
mode: one
selector: {namespaces: [shop], labelSelectors: {app: checkout}}
YML
cat > net-loss.yaml <<'YML'
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata: {name: shop-loss, namespace: shop}
spec:
action: loss
mode: all
selector: {namespaces: [shop]}
loss: {loss: "30"}
YML
status=0
for f in *.yaml; do
kind=$(yq '.kind' "$f")
mode=$(yq '.spec.mode' "$f")
[ "$mode" = "all" ] && { echo "$f: mode 'all' hits every selected pod"; status=1; }
[ "$(yq '.spec.selector.labelSelectors // "none"' "$f")" = "none" ] && { echo "$f: no labelSelectors, the whole namespace is in scope"; status=1; }
if [ "$kind" != "PodChaos" ] && [ "$(yq '.spec.duration // "none"' "$f")" = "none" ]; then
echo "$f: no duration, the fault stays until someone deletes it"; status=1
fi
done
[ $status -eq 0 ] && echo "all chaos manifests within guardrails"
echo "exit $status"net-loss.yaml: mode 'all' hits every selected pod
net-loss.yaml: no labelSelectors, the whole namespace is in scope
net-loss.yaml: no duration, the fault stays until someone deletes it
exit 1
pod-kill.yaml passes: a pod kill is instantaneous, so it needs no duration. net-loss.yaml would drop 30% of
packets for every pod in the namespace, with no end: exactly the experiment that turns into an incident.
Test yourself
How do you abort a running Chaos Mesh NetworkChaos experiment by hand?
- Restart the cluster
- Delete the NetworkChaos resource
- Scale the operator to zero
- Wait for it to finish
What is a Litmus probe for?
- Installing experiments
- Checking the steady state before, during or after the fault to decide the verdict
- Deleting pods
- Scheduling experiments
Why did the guardrail check reject net-loss.yaml?
- Wrong API version
- It targets every pod in the namespace (mode all, no label selector) with no duration
- Network faults are forbidden
- It has a typo