In this blog, I will talk about the generation of custom/new chaos experiment with the help of Litmus SDK. Before jumping in, let's do a quick recap on Litmus. Litmus is a framework for practicing Chaos Engineering in cloud-native environments. Litmus provides a chaos-operator, a large set of chaos experiments in its hub, detailed documentation, quick Demo, and a friendly community.
The Litmus SDK provides a simple way to bootstrap your experiment and helps create the aforementioned artifacts in the appropriate directory (i.e., as per the chaos-category) based on an attributes file provided as input by the chart-developer. The scaffolded files consist of placeholders which can then be filled as desired.
It generates the custom chaos experiments with some default Pre & Post Chaos Checks (AUT & Auxiliary Applications status checks). It can use the existing chaoslib (present inside /chaoslib
directory), if available else It will create a new chaoslib inside the same directory.
Each Chaos Experiment is divided into six main sections:
## for litmus-go
$ git clone https://github.com/litmuschaos/litmus-go.git
$ cd litmus-go/contribute/developer-guide
## for litmus-ansible
$ git clone https://github.com/litmuschaos/litmus-ansible.git
$ cd litmus-ansible/contribute/developer_guide
As an example, let us consider an experiment to kill one of the replicas of an Nginx deployment. The attributes.yaml can be constructed like this:
$ cat attributes.yaml
---
name: "pod-delete"
version: "0.1.0"
category: "sample-category"
repository: "https://github.com/litmuschaos/litmus-go/tree/master/sample-category/pod-delete"
community: "https://kubernetes.slack.com/messages/CNXNB0ZTN"
description: "kills nginx pods in a random manner"
keywords:
- "pods"
- "kubernetes"
- "sample-category"
- "nginx"
scope: "Namespaced"
auxiliaryappcheck: false
permissions:
- apigroups:
- ""
- "batch"
- "litmuschaos.io"
resources:
- "jobs"
- "pods"
- "chaosengines"
- "chaosexperiments"
- "chaosresults"
verbs:
- "create"
- "list"
- "get"
- "update"
- "patch"
- "delete"
maturity: "alpha"
maintainers:
- name: "ksatchit"
email: "ksatchit@mayadata.io"
provider:
name: "Mayadata"
minkubernetesversion: "1.12.0"
references:
- name: Documentation
url: "https://docs.litmuschaos.io/docs/getstarted/"
## litmus-go
$ go run generate_experiment.go -attributes=attributes.yaml -generateType=experiment
## litmus-ansible
$ python3 generate_chart.py --attributes_file=attributes.yaml --generate_type=experiment
--generate_type
(litmus-ansible) or -generateType
(litmus-go) attribute, select the appropriate type of manifests to be generated, where,$ cd /experiments
$ ls -ltr
total 8
drwxr-xr-x 3 shubham shubham 4096 May 15 12:02 generic/
drwxr-xr-x 3 shubham shubham 4096 May 15 13:26 sample-category/
$ ls -ltr sample-category/
total 12
-rw-r--r-- 1 shubham shubham 41 May 15 13:26 sample-category.package.yaml
-rw-r--r-- 1 shubham shubham 734 May 15 13:26 sample-category.chartserviceversion.yaml
drwxr-xr-x 2 shubham shubham 4096 May 15 13:26 pod-delete/
$ ls -ltr sample-category/pod-delete
total 28
-rw-r--r-- 1 shubham shubham 791 May 15 13:26 rbac.yaml
-rw-r--r-- 1 shubham shubham 734 May 15 13:26 pod-delete.chartserviceversion.yaml
-rw-r--r-- 1 shubham shubham 792 May 15 13:26 experiment.yaml
-rw-r--r-- 1 shubham shubham 1777 May 15 13:26 pod-delete-k8s-job.yml
## this file will be created in case of litmus-go
-rw-r--r-- 1 shubham shubham 4533 May 15 13:26 pod-delete.go
## this file will be created in case of litmus-ansible
-rw-r--r-- 1 shubham shubham 4533 May 15 13:26 pod-delete-ansible-logic.yml
-rw-r--r-- 1 shubham shubham 813 May 15 13:26 engine.yaml
Litmus SDK will help developers & SREs to create their custom chaos experiment on demand. It will generate the templates, pre/post chaos checks, chaoslib (which can be modified according to use-case).
Are you an SRE or a Kubernetes enthusiast? Does Chaos Engineering excite you? Join Our Community #litmus channel in Kubernetes Slack
Contribute to LitmusChaos and share your feedback on Github
If you like LitmusChaos, become one of the many stargazers here