Now that you have deployed Chaos Mesh in your environment, it's timeto use it for your chaos experiments. This document walks you through the process of running chaos experiments. It also describes the regular operations on chaos experiments.

Step 1: Deploy the target cluster

The first step is always to have the target cluster to test deployed. For illustration purposes, TiDB is used as a sample cluster.

You can follow the instructions in the following two documents to deploy a TiDB cluster:

Step 2: Define the experiment config file

The chaos experiment configuration is defined in a .yaml file. You need to create your own experiment config file, based on the available fields in the sample below:

  1. apiVersion: pingcap.com/v1alpha1
  2. kind: PodChaos
  3. metadata:
  4. name: pod-failure-example
  5. namespace: chaos-testing
  6. spec:
  7. action: pod-failure # the specific chaos action to inject; supported actions: pod-kill/pod-failure
  8. mode: one # the mode to run chaos action; supported modes are one/all/fixed/fixed-percent/random-max-percent
  9. duration: "60s" # duration for the injected chaos experiment
  10. selector: # pods where to inject chaos actions
  11. namespaces:
  12. - tidb-cluster-demo # the namespace of the system under test (SUT) you've deployed
  13. labelSelectors:
  14. "app.kubernetes.io/component": "tikv" # the label of the pod for chaos injection
  15. scheduler: # scheduler rules for the running time of the chaos experiments about pods.
  16. cron: "@every 5m"

Step 3: Apply a chaos experiment

Running the following commands to apply the experiment config defined in the .yaml file:

  1. kubectl apply -f pod-failure-example.yaml
  2. kubectl get podchaos --namespace=chaos-testing

With this step, you now run your chaos experiment successfully. By running a benchmark against the cluster, you can notice the QPS performance affected by the chaos experiment:

tikv-pod-failure

Regular operations on chaos experiments

In this section, you will learn about some follow-up operations on a chaos experiment after it is applied.

Update a chaos experiment

  1. vim pod-failure-example.yaml # modify pod-failure-example.yaml to what you want
  2. kubectl apply -f pod-failure-example.yaml

Delete a chaos experiment

  1. kubectl delete -f pod-failure-example.yaml

Watch your chaos experiments in Dashboard

Chaos Dashboard is currently only available for TiDB clusters. Stay tuned for more supports or join us in making it happen.

Note:

If Chaos Dashboard was not installed in your earlier deployment, you need to install it by upgrading Chaos Mesh:

helm upgrade chaos-mesh helm/chaos-mesh —namespace=chaos-testing —set dashboard.create=true

A typical way to access it is to use kubectl port-forward

  1. kubectl port-forward -n chaos-testing svc/chaos-dashboard 8080:80

Then you can access http://localhost:8080 in browser.