Litmus

From paulpas/agent-skill-router · View interactive version

Litmus is an AI agent skill from the GitHub repository paulpas/agent-skill-router. "Litmus in Chaos Engineering - cloud native architecture, patterns, pits" and best practices

How to use this skill

Skill file

Litmus in Cloud-Native Engineering

Purpose and Use Cases

What Problem Does It Solve?

When to Use

Key Use Cases

Architecture Design Patterns

Core Components

Litmus Chaos Operator
litmus
├── chaos-operator (main orchestrator)
├── chaos-exporter (metrics collection)
├── chaos-dashboard (UI and API)
├── experiment-images (chaos experiments)
└── workflow-images (chaos workflows)
Chaos Experiment Structure
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosExperiment
metadata:
  name: pod-delete
spec:
  definition:
    execution:
      - name: chaos
        image: litmuschaos/go-runner:latest
        command:
          - /bin/bash
          - -c
          - |
            # Chaos experiment logic
            kubectl delete pod ${CHAOSENGINE} -n ${TARGET_NAMESPACE}
        env:
          - name: TARGET_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: CHAOSENGINE
            value: ${CHAOSENGINE}
Chaos Engine
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: nginx-chaos
  namespace: default
spec:
  appinfo:
    appns: default
    applabel: "app=nginx"
    appkind: deployment
  jobCleanUpPolicy: delete
  engineState: active
  chaosServiceAccount: litmus
  experiments:
    - name: pod-delete
      spec:
        components:
          env:
            - name: TOTAL_CHAOS_DURATION
              value: "30"
            - name: CHAOS_INTERVAL
              value: "10"
            - name: Pod_Delete
              value: "true"

Component Interactions

Chaos Engine
    ↓ (creates job)
Kubernetes Job
    ↓ (runs experiment)
Chaos Experiment Container
    ↓ (executes chaos)
Target Application
    ↓ (monitors results)
Chaos Exporter
    ↓ (collects metrics)
Prometheus

Data Flow Patterns

Experiment Execution Flow
1. ChaosEngine resource created
2. Chaos operator detects new engine
3. Creates Kubernetes Job for experiment
4. Job runs chaos experiment container
5. Experiment applies chaos to target
6. Results collected and reported
7. Job completed, results exported
Self-Healing Test Flow
1. Chaos experiment triggers failure
2. Kubernetes self-healing detects failure
3. Kubernetes recreates failed resources
4. Chaos experiment monitors recovery
5. Success/failure reported
6. Results stored for analysis

Design Principles

Idempotency
Declarative Configuration
Minimal Instrumentation

Integration Approaches

Integration with Other CNCF Projects

Prometheus Integration
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: litmus-exporter
  namespace: litmus
spec:
  selector:
    matchLabels:
      name: litmus-exporter
  namespaceSelector:
    matchNames:
      - litmus
  endpoints:
    - port: metrics
      path: /metrics
      interval: 30s
Grafana Integration
{
  "annotations": {
    "list": [{
      "name": "Chaos Experiments",
      "datasource": "Prometheus",
      "enable": true,
      "expr": "chaos_experiment_total"
    }]
  },
  "panels": [
    {
      "title": "Experiment Success Rate",
      "targets": [{
        "expr": "chaos_experiment_success_ratio"
      }]
    }
  ]
}
ArgoCD Integration
apiVersion: apps/v1
kind: ConfigMap
metadata:
  name: litmus-gitops
data:
  chaos-engine.yaml: |
    apiVersion: litmuschaos.io/v1alpha1
    kind: ChaosEngine
    metadata:
      name: gitops-chaos
    spec:
      appinfo: ...
      experiments: []
Tekton Integration
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: chaos-test-pipeline
spec:
  pipelineRef:
    name: chaos-test-pipeline
  tasks:
    - name: chaos-test
      taskRef:
        name: litmus-chaos-test
      params:
        - name: engine
          value: "my-chaos-engine"
Kyverno Integration
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: require-chaos-tests
spec:
  validationFailureAction: Enforce
  rules:
    - name: chaos-tested
      match:
        any:
          - resources:
              kinds:
                - Pod
      validate:
        message: "Production deployments must have chaos test coverage"
        deny: {}

API Patterns

Experiment API
Result API
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosResult
metadata:
  name: nginx-chaos-pod-delete
  namespace: default
spec:
  engine: nginx-chaos
  experiment: pod-delete
  scenario: Chaos
  status:
    verdict: Pass
    failStep: ""
    probeSuccessPercentage: "100"
    lastUpdateTime: "2023-01-01T00:00:00Z"

Configuration Patterns

Chaos Engine Configuration
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: web-app-chaos
spec:
  appinfo:
    appns: default
    applabel: "app=web-app"
    appkind: deployment
  engineState: active
  jobCleanUpPolicy: delete
  chaosServiceAccount: litmus-admin
  experiments:
    - name: pod-delete
      spec:
        components:
          env:
            - name: TARGET_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: TOTAL_CHAOS_DURATION
              value: "60"
            - name: CHAOS_INTERVAL
              value: "15"
            - name: FORCE
              value: "true"
RBAC Configuration
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: litmus-role
rules:
  - apiGroups: [""]
    resources: ["pods", "services", "configmaps", "events", "pods/log"]
    verbs: ["get", "list", "delete"]
  - apiGroups: ["apps"]
    resources: ["deployments", "replicasets"]
    verbs: ["get", "list", "delete"]
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["get", "list", "create", "delete"]
  related-skills: null
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: litmus-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: litmus-role
subjects:
  - kind: ServiceAccount
    name: litmus
    namespace: litmus

Extension Mechanisms

Custom Experiment Templates
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosExperiment
metadata:
  name: custom-experiment
spec:
  definition:
    execution:
      - name: chaos
        image: my-registry/custom-chaos:latest
        command:
          - /bin/bash
          - -c
          - ./run-custom-chaos.sh
        env:
          - name: CUSTOM_PARAM
            value: "value"
Workflow Templates
apiVersion: litmuschaos.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: resilience-test
spec:
  sequence:
    - experiment: pod-delete
    - experiment: pod-cpu-hog
    - experiment: pod-memory-hog
  parallel:
    - experiment: pod-network-latency
    - experiment: pod-disk-fill

Common Pitfalls and How to Avoid Them

Configuration Issues

Insufficient RBAC

Problem: Chaos experiments fail due to missing permissions.

Solution:

# Ensure proper RBAC
kubectl create clusterrolebinding litmus-binding \
  --clusterrole=litmus-role \
  --serviceaccount=litmus:default
Target Application Misconfiguration

Problem: Experiments don't target correct resources.

Solutions:

# Verify app labels
kubectl get pods --show-labels

# Correct ChaosEngine configuration
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
spec:
  appinfo:
    appns: default
    applabel: "app=nginx"  # Must match actual labels
    appkind: deployment
Resource Limits Not Set

Problem: Chaos experiments consume too many resources.

Solution:

apiVersion: v1
kind: Pod
spec:
  containers:
    - name: chaos-runner
      resources:
        requests:
          memory: "256Mi"
          cpu: "100m"
        limits:
          memory: "512Mi"
          cpu: "500m"

Performance Issues

Experiment Overhead

Problem: Chaos experiments impact production performance.

Solutions:

Metrics Collection Impact

Problem: Chaos exporter affects application performance.

Solutions:

Operational Challenges

Experiment Failures

Problem: Experiments fail with unclear error messages.

Solutions:

# Check experiment logs
kubectl logs -f pod/litmus-chaos-runner-xxxxx -n litmus

# Check chaos result
kubectl get chaosresult nginx-chaos-pod-delete -o yaml

# Verify chaos operator logs
kubectl logs -n litmus deploy/chaos-operator
Cleanup Issues

Problem: Experiments leave resources behind.

Solutions:

Version Compatibility

Problem: Litmus versions incompatible with Kubernetes.

Solutions:

Security Pitfalls

Privilege Escalation

Problem: Chaos experiments gain excessive permissions.

Solutions:

Secret Exposure

Problem: Chaos configurations expose sensitive data.

Solutions:

Network Policies

Problem: Chaos experiments blocked by network policies.

Solutions:

Coding Practices

Idiomatic Configuration

Standard Experiment YAML
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosExperiment
metadata:
  name: pod-delete
  labels:
    name: pod-delete
    app.kubernetes.io/component: chaos-experiment
spec:
  definition:
    execution:
      - name: chaos
        image: litmuschaos/go-runner:latest
        command:
          - /bin/bash
          - -c
          - |
            # chaos logic here
            echo "Starting pod deletion chaos"
        env:
          - name: TARGET_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        resources:
          requests:
            memory: 128Mi
            cpu: 100m
          limits:
            memory: 256Mi
            cpu: 200m

API Usage Patterns

Running Experiments
# Create chaos engine
kubectl apply -f chaos-engine.yaml

# Monitor experiment
kubectl get chaosresult -w

# Check experiment status
kubectl get chaosengine nginx-chaos

# View experiment logs
kubectl logs -f deploy/chaos-operator -n litmus
Updating Experiments
# Update chaos engine
kubectl patch chaosengine nginx-chaos \
  --type='json' \
  -p='[{"op": "replace", "path": "/spec/experiments/0/spec/components/env/0/value", "value": "90"}]'

# Delete chaos engine
kubectl delete chaosengine nginx-chaos

Observability Best Practices

Metrics Collection
Logging Strategy

Development Workflow

Experiment Development
  1. Create experiment YAML definition
  2. Build chaos image with experiment logic
  3. Test in isolated namespace
  4. Verify cleanup behavior
  5. Document experiment parameters
  6. Version control configuration
CI/CD Integration
# Example GitLab CI
chaos-test:
  stage: test
  script:
    - kubectl apply -f chaos-engine.yaml
    - kubectl wait --for=condition=Complete job/litmus-chaos-runner --timeout=5m
    - kubectl get chaosresult -o yaml
  rules:
    - if: $CI_COMMIT_BRANCH == 'main'

Fundamentals

Essential Concepts

Chaos Experiment Lifecycle
Litmus Architecture

Terminology Glossary

| Term | Definition |

| related-skills: null

| ChaosExperiment | Kubernetes resource defining a chaos scenario |

| ChaosEngine | Main orchestration resource for chaos execution |

| ChaosResult | Result of chaos experiment execution |

| ChaosOperator | Controller managing chaos resources |

| ChaosExporter | Prometheus metrics exporter for chaos |

| ChaosRunner | Container executing chaos experiment |

| EngineState | Active or stop state of chaos engine |

| JobCleanupPolicy | Policy for cleaning up experiment jobs |

| Application Info | Target application configuration |

| Experiment Spec | Individual experiment configuration |

Data Models and Types

ChaosExperiment Schema
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosExperiment
metadata:
  name: string
spec:
  definition:
    execution:
      - name: string
        image: string
        command: []
        env: []
        resources: {}
ChaosEngine Schema
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: string
spec:
  appinfo: {}
  engineState: active|stop
  jobCleanUpPolicy: delete|keep
  chaosServiceAccount: string
  experiments: []

Lifecycle Management

Installation Lifecycle
  1. Prerequisites: Kubernetes cluster, kubectl
  2. Install Litmus: kubectl apply -f litmus-operator.yaml
  3. Create Service Account: RBAC configuration
  4. Deploy Experiments: Apply experiment YAMLs
  5. Verify Installation: Run litmus check
  6. Configure Experiments: Create ChaosEngine resources
Experiment Lifecycle
  1. Definition: Create ChaosExperiment YAML
  2. Execution: Create ChaosEngine referencing experiment
  3. Monitoring: Watch experiment progress
  4. Result: Collect ChaosResult
  5. Cleanup: Remove ChaosEngine

State Management

Experiment State
Application State During Chaos

Scaling and Deployment Patterns

Horizontal Scaling

Multiple Chaos Engines
# Run chaos in multiple namespaces
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: chaos-web-namespace-1
  namespace: namespace-1
spec: ...
  related-skills: null
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: chaos-web-namespace-2
  namespace: namespace-2
spec: ...
Parallel Experiments
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
spec:
  experiments:
    - name: pod-delete
    - name: pod-cpu-hog
    - name: pod-network-latency

High Availability

Chaos Operator HA
# Deploy multiple operator replicas
kubectl scale -n litmus deploy/chaos-operator --replicas=3
Dashboard HA
# Deploy dashboard with replicas
kubectl scale -n litmus deploy/litmus-dashboard --replicas=3

Production Deployments

Multi-Cluster Chaos
# Export chaos results from all clusters
kubectl get chaosresult --all-namespaces -o json > results.json
Scheduled Experiments
apiVersion: batch/v1
kind: CronJob
metadata:
  name: weekly-chaos
spec:
  schedule: "0 0 * * 0"  # Sunday at midnight
  jobTemplate:
    spec:
      template:
        spec:
          # Create chaos engine
          restartPolicy: Never

Upgrade Strategies

Rolling Updates
  1. Test new version in staging
  2. Update chaos operator
  3. Update experiment images
  4. Update chaos engines
  5. Verify functionality
Blue-Green Updates
  1. Deploy new version alongside old
  2. Run parallel experiments
  3. Compare results
  4. Switch traffic to new version
  5. Decommission old version

Resource Management

Resource Sizing
resources:
  requests:
    memory: "128Mi"
    cpu: "100m"
  limits:
    memory: "256Mi"
    cpu: "500m"
Storage Management

Additional Resources

Official Documentation

CNCF References

Tools and Libraries

Tutorials and Guides

Community Resources

Related Standards

OpenTelemetry Integration

Troubleshooting

Common Issues

  1. Deployment Failures
  1. Performance Issues
  1. Configuration Errors
  1. Integration Problems

Getting Help

Examples

Basic Configuration

# Basic configuration example
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{project_name}}-config
  namespace: default
data:
  # Configuration goes here
  config.yaml: |
    # Base configuration
    # Add your settings here

Kubernetes Deployment

# Kubernetes deployment for {{project_name}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{project_name}}
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{project_name}}
  template:
    metadata:
      labels:
        app: {{project_name}}
    spec:
      containers:
      - name: {{project_name}}
        image: {{project_name}}:latest
        ports:
        - containerPort: 8080
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"

Kubernetes Service

# Kubernetes service for {{project_name}}
apiVersion: v1
kind: Service
metadata:
  name: {{project_name}}
  namespace: default
spec:
  selector:
    app: {{project_name}}
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: ClusterIP

Constraints

MUST DO

MUST NOT DO

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.