Skip to content

LitmusChaos Setup

Installing LitmusChaos and Running Chaos Monkey Experiments

LitmusChaos requires dedicated namespaces for running experiments and its own components. Follow these steps to set up the environment:

  1. Create a namespace for chaos experiments:

    kubectl create namespace chaos-testing
    

  2. Set namespace context for subsequent commands:

    kubectl config set-context --current --namespace=chaos-testing
    

  3. Create the 'litmuschaos' service account (prerequisite for RB, install LitmusChaos components):

    kubectl create serviceaccount litmuschaos -n litmus
    
    Note: The litmus namespace is where LitmusChaos controller and related components are installed, while chaos-testing is used for experiment workloads.

  4. Grant permissions (RBAC):
    Ensure the litmuschaos service account has access to the chaos-testing namespace. Apply a role binding with restricted permissions:

    kubectl create rolebinding chaos-runner-binding \
      --namespace=chaos-testing \
      --role=chaos-runner \
      --serviceaccount=litmus:litmuschaos
    
    (Adjust the role and service account based on your cluster configuration. For production, use a more restrictive role than cluster-admin.)

  5. Install LitmusChaos via Helm:
    Add the LitmusChaos Helm repository and deploy:

    helm repo add litmuschaos https://charts.litmuschaos.io
    helm install litmuschaos litmuschaos/litmuschaos --namespace litmus
    
    Alternatively, use Kubernetes manifests from the LitmusChaos GitHub repo for installation.

  6. Run a Chaos Monkey experiment:
    Create a Chaos Monkey experiment manifest (e.g., pod-delete.yaml):

    apiVersion: litmuschaos.io/v1alpha1
    kind: ChaosEngine
    metadata:
      name: pod-delete
      namespace: chaos-testing
    spec:
      engineName: chaos-mono
      appInfo:
        appNS: chaos-testing
        appLabels: {}
        appPods: []
      chaosServiceAccount: litmuschaos
      experiments:
        - name: pod-delete
          spec:
            engineName: chaos-mono
            workloadKind: pod
            workloadSelector:
              matchLabels:
                app: nginx
            chaosNamespace: chaos-testing
            metadata:
              annotations:
                "chaos.io/timeout": "30s"
            spec:
              signal: true
              signalType: pod
              podDelete:
                gracePeriod: 5
                preKill: true
                postKill: true
    
    This example deletes a pod with label app: nginx in the chaos-testing namespace. Adjust labels and parameters based on your workload.

  7. Execute and verify the experiment:
    Apply the manifest and monitor the results:

    kubectl apply -f pod-delete.yaml
    kubectl get pods -n chaos-testing
    
    Check logs and metrics to confirm the chaos effect and recovery.