Basic example of chaos testing using xk6-disruptor extension.
In this example you can find three dummy services:
- Frontend books service which exposes a frontend application showing the list of books available and purchased.
- Books service which exposes an endpoint that list of available books to be purchased.
- Bookstore service which exposes two endpoints to purchase books using their name and to check which books where purchased.
All the data is stored in memory without using any database to make it simple and focus on the disruptor.
โ ๏ธ The ingress deployed will use the host's 80 and 443 ports
- go: golang binary to at least install xk6 cli - https://go.dev/
- docker: used to create images and to run kind - https://www.docker.com/
- kind: used to create a local kubernetes cluster - https://kind.sigs.k8s.io/
- kubectl: cli used to interact with the kubernetes cluster - https://kubernetes.io/docs/reference/kubectl/
- xk6: custom k6 builder to create k6 binaries with custom extensions - https://github.com/grafana/xk6
- xk6-disruptor: extension to apply faults into Kubernetes clusters - https://grafana.com/docs/k6/latest/testing-guides/injecting-faults-with-xk6-disruptor/
- First we create a kind cluster, for that we use kind-cluster.yml configuration file to expose ports on the host machine:
kind create cluster --config kind-cluster.yml
- Next, we deploy an nginx ingress prepared for kind
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
- Wait for the ingress to be ready
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
- Deploy ingress configuration
kubectl apply -f ingress.yml
- Build the three images
docker build -t books-frontend:1.0.0 books-frontend
docker build -t bookstore:1.0.0 bookstore
docker build -t books:1.0.0 books
- Deploy the images inside kind cluster
kind load docker-image books-frontend:1.0.0
kind load docker-image bookstore:1.0.0
kind load docker-image books:1.0.0
- Deploy books-frontend, books and bookstore deployments into kind cluster
kubectl apply -f books-frontend/deployment.yml
kubectl apply -f books/deployment.yml
kubectl apply -f bookstore/deployment.yml
- Install xk6 cli
go install go.k6.io/xk6/cmd/xk6@latest
- Build k6 binary with xk6-disruptor
xk6 build --output k6-disruptor --with github.com/grafana/xk6-disruptor
- Without disruptors
./k6-disruptor run --env SKIP_FAULTS=1 disrup-test.js
- With disruptors
./k6-disruptor run disrup-test.js
The disruptor applied on the example test will inject http faults on the books-service causing it to have 500ms of latency and an error rate of 0.1.
If you want you can delete the kind cluster with the command:
kind delete cluster
And remove any image left:
docker image rm books:1.0.0
docker image rm bookstore:1.0.0
docker image rm books-frontend:1.0.0