Search⌘ K

Setting up Chaos Toolkit in Kubernetes

Explore how to set up Chaos Toolkit inside a Kubernetes cluster by defining experiments with ConfigMaps and assigning necessary permissions using ServiceAccounts. Understand ConfigMap structure for experiment definitions and configure roles to limit permissions within a namespace, enabling controlled chaos engineering experiments.

Defining configuration in Kubernetes using the ConfigMap

Before we start running chaos experiments inside the Kubernetes cluster, we’ll need to set up at least two things:

  1. We’ll need experiment definitions stored somewhere in the cluster. The most common and the most logical way to define a configuration in Kubernetes is to use ConfigMap.
  2. Apart from having experiment definitions readily available, we will also need to create a ServiceAccount that will provide the necessary privileges to processes that will run the experiments.

Inspecting the definition of ConfigMap

Let’s start with the ConfigMap.

Shell
cat k8s/chaos/experiments.yaml

The output, limited to the first experiment, is as follows.

...
apiVersion: v1
kind: ConfigMap
metadata:
  name: chaostoolkit-experiments
data:
  health-http.yaml: |
    version: 1.0.0
    title: What happens if we terminate an instance of the application?
    description: If an instance of the application is terminated, the applications as a whole should still be operational.
    tags:
    - k8s
    - pod
    steady-state-hypothesis:
      title: The app is healthy
      probes:
      - name: app-responds-to-requests
        type: probe
        tolerance: 200
        provider:
          type: http
          timeout: 3
          verify_tls: false
          url: http://go-demo-8.go-demo-8/demo/person
          headers:
            Host: go-demo-8.acme.com
    method:
    - type: action
      name:
...