codeWithYoha logo
Code with Yoha
HomeArticlesAboutContactSupport ☕
Chaos Engineering

Modern Chaos Engineering with Chaos Mesh and LitmusChaos

CodeWithYoha
CodeWithYoha
6 min read
Modern Chaos Engineering with Chaos Mesh and LitmusChaos

Introduction

In modern cloud-native architectures, failures are not an IF but a WHEN. Microservices, dynamic orchestration via Kubernetes, and distributed architectures create systems of immense complexity. Traditional testing methods—focused purely on happy paths and static environments—fall short of guaranteeing uptime in production.

Chaos engineering is the discipline of experimenting on a system to build confidence in the system's capability to withstand turbulent conditions in production. Rather than hoping systems do not fail, chaos engineering proactively injects controlled failures to uncover systemic weaknesses before they impact end-users.

The Evolution of Chaos Engineering on Kubernetes

When Netflix first popularized chaos engineering with tools like Chaos Monkey, systems were monolithic or migrating to early cloud infrastructure. Today, Kubernetes has become the de facto operating system for the cloud, bringing native abstractions like Pods, Services, Deployments, and Custom Resource Definitions (CRDs).

Kubernetes changed the game for chaos engineering. Because Kubernetes is declarative and API-driven, chaos tools can interact directly with the cluster state. Modern tools like Chaos Mesh and LitmusChaos leverage Kubernetes Operators and CRDs, allowing engineers to define chaos experiments as native Kubernetes manifests, bridging the gap between GitOps and resilience testing.

Prerequisites and Environment Setup

Before diving into chaos engineering tools, ensure you have the following prerequisites configured in your environment:

  • A running Kubernetes cluster (v1.22+ recommended)
  • kubectl CLI configured with cluster administrative privileges
  • Helm (v3+) package manager installed
  • Basic understanding of Kubernetes manifests and architecture

To verify your cluster access, run:

bash
kubectl cluster-info

Introduction to Chaos Mesh

Chaos Mesh is an open-source, cloud-native chaos engineering platform designed for Kubernetes. It offers a rich set of chaos injection types—ranging from pod kills and network delays to kernel panics and I/O pressure—all managed through custom Kubernetes resources and a polished web UI dashboard.

Chaos Mesh operates via a central controller manager that communicates with a sidecar-injector or daemonset agents running across nodes. This architecture enables precise control over container runtimes, network interfaces, and Linux kernel subsystems.

Installing and Configuring Chaos Mesh

Installing Chaos Mesh is straightforward using Helm. First, add the Chaos Mesh Helm repository and create a dedicated namespace:

bash
helm repo add chaos-mesh https://charts.chaos-mesh.org
kubectl create namespace chaos-testing

Next, install Chaos Mesh using Helm. For production environments, ensure you secure the dashboard and configure appropriate RBAC policies:

bash
helm install chaos-mesh chaos-mesh/chaos-mesh \
    --namespace chaos-testing \
    --set dashboard.create=true

Verify the installation by checking the status of the pods in the chaos-testing namespace:

bash
kubectl get pods --namespace chaos-testing

Writing and Executing Chaos Mesh Experiments

Chaos Mesh uses Custom Resources to define experiments. Below is an example of a NetworkChaos experiment that introduces a 200ms latency to a specific service deployment:

yaml
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
  name: web-showcase-latency
  namespace: default
spec:
  action: delay
  mode: one
  selector:
    namespaces:
      - default
    labelSelectors:
      app: web-showcase
  delay:
    latency: '200ms'
    correlation: '10'
    jitter: '10ms'
  duration: '5m'
  scheduler:
    cron: '@every 10m'

Apply this manifest to your cluster using kubectl apply -f:

bash
kubectl apply -f network-delay.yaml

Introduction to LitmusChaos

LitmusChaos is another leading cloud-native chaos engineering framework focusing on developer-centric and GitOps-friendly workflows. Litmus relies heavily on ChaosExperiments and ChaosEngines CRDs, organized around the concept of "ChaosHubs"—centralized repositories of pre-built chaos faults.

Litmus excels at application-level chaos, Kubernetes infrastructure chaos, and cloud provider failure injection. Its modular architecture allows SRE teams to build custom probes for validating system health during experiments.

Installing and Configuring LitmusChaos

LitmusChaos can be installed using its dedicated operator chart. Set up Litmus in your cluster with the following commands:

bash
kubectl create namespace litmus
helm repo add litmuschaos https://litmuschaos.github.io/litmus-helm/
helm install litmus litmuschaos/litmus-core --namespace litmus

Once installed, verify the operator deployment:

bash
kubectl get pods --namespace litmus

To run experiments, you will also need to install chaos experiments from the ChaosHub or install specific chart experiments individually.

Executing LitmusChaos Workflows

Litmus uses declarative ChaosWorkflows to orchestrate complex, multi-step failure scenarios. Below is an example of a LitmusChaos manifest that injects a pod delete fault into a target application:

yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  name: pod-delete-workflow
  namespace: litmus
spec:
  entry: custom-chaos
  templates:
  - name: custom-chaos
    steps:
    - - name: run-pod-delete
        template: pod-delete
  - name: pod-delete
    inputs:
      artifacts:
      - name: chaos-params
        raw:
          data: |
            apiVersion: litmuschaos.io/v1alpha1
            kind: ChaosEngine
            metadata:
              name: nginx-chaos
              namespace: default
            spec:
              engineState: 'active'
              appinfo:
                appns: 'default'
                applabel: 'app=nginx'
                appkind: 'deployment'
              chaosServiceAccount: litmus-admin
              experiments:
              - name: pod-delete
                spec:
                  components:
                    env:
                    - name: TOTAL_CHAOS_EXPERIMENT_DURATION
                      value: '30'

Comparing Chaos Mesh and LitmusChaos

Both Chaos Mesh and LitmusChaos are CNCF sandbox/incubating projects designed for Kubernetes, but they cater to slightly different philosophies:

  • Chaos Mesh: Best known for granular, low-level kernel and network fault injection (e.g., IO Chaos, DNS Chaos, Kernel Chaos). It features an exceptionally intuitive Web UI for building and visualizing experiments.
  • LitmusChaos: Best known for declarative experiment workflows, deep integration with Argo Workflows, and rich application-specific chaos charts from ChaosHub. It shines in GitOps pipelines and automated continuous verification.

Best Practices for Production Chaos Engineering

Implementing chaos engineering in production requires discipline and a strict safety protocol. Follow these best practices:

  1. Start Small: Begin in staging environments with non-destructive faults (e.g., pod restarts) before moving to production.
  2. Define Steady State: Establish clear metrics for what "healthy" looks like (e.g., error rate < 0.1%, latency p99 < 300ms).
  3. Always Have a Blast Radius: Restrict experiments to specific namespaces, labels, or nodes.
  4. Automate Rollbacks: Ensure that monitoring hooks can automatically abort experiments if critical thresholds are breached.
  5. Involve Developers: Make chaos testing a collaborative effort between developers and SREs.

Common Pitfalls to Avoid

Avoid these frequent mistakes when starting your chaos engineering journey:

  • Running Production Experiments Blindly: Never run chaos experiments without proper monitoring, alerting, and observability in place.
  • Testing Too Many Variables: Injecting network latency, CPU stress, and pod termination simultaneously makes root-cause analysis impossible.
  • Ignoring Cleanup: Ensure your chaos tools have clean teardown procedures so lingering faults do not corrupt subsequent deployments.
  • Treating It as a One-Time Event: Chaos engineering must be continuous to account for shifting codebases and infrastructure changes.

Conclusion

Chaos engineering is no longer optional for organizations running complex microservices on Kubernetes. Tools like Chaos Mesh and LitmusChaos democratize resilience testing by embedding failure injection directly into the Kubernetes API lifecycle.

By systematically testing how your applications respond to degraded networks, resource starvation, and infrastructure outages, you build robust systems capable of surviving real-world failures gracefully. Begin your journey today in a non-production cluster, define your steady-state hypotheses, and watch your system's resilience soar.

Support CodeWithYoha

Enjoyed this deep dive? Buy me a coffee!

Every article on CodeWithYoha is 100% free, independent, and sponsor-free. If this guide saved you hours of debugging or helped you architect better software, consider supporting future guides with a coffee ($5, $10, or any amount of your choice).

CodewithYoha

Written by

CodewithYoha

Full-Stack Software Engineer with 7+ years of experience in Java, Spring Boot, and cloud architecture across AWS, Azure, and GCP. Writing production-grade engineering patterns for developers who ship real software.