This project is a demonstration of how to execute locust using docker, docker compose and minikube (kubernetes) using both its standalone and master/worker mode. It's heavly inspired in this repository and this.
You need to have the three pieces installed: docker, docker compose and minikube. Then clone this repository and follow the execution scenarios:
$ git clone https://github.com/gustavobgama/locust-k8s.git
$ cd locust-k8s
$ docker run --name standalone --hostname standalone -e ATTACKED_HOST=https://computer-database.gatling.io -p 8089:8089 -d -v $(pwd):/locust gustavobgama/locust
So, access the locust web interface, define the parameters for load test, execute and go along with the results. After the tests you can remove the container:
$ docker rm -f standalone
You can also execute the load tests without the interface passing the command line documented option in LOCUST_OPTS
, for example:
$ docker run --rm --name standalone --hostname standalone -e ATTACKED_HOST=https://computer-database.gatling.io -e "LOCUST_OPTS=--run-time=30s --spawn-rate=20 --users=200 --headless --only-summary" -p 8089:8089 -v $(pwd):/locust gustavobgama/locust
$ docker-compose up -d --scale worker=4
The locust web interface will be available here.
For ultimate scalability and automation you can use the kubernetes to execute locust in master/worker mode, this setup is going to automatically activate or deactivate workers according to the load test scenario.
-
Start the cluster and enable some addons:
$ minikube start $ minikube addons enable ingress $ minikube addons enable metrics-server
-
Configure the cluster and execute test:
$ kubectl apply -f ./k8s $ minikube service master-load-balancer-service (open the locust web interface)
-
After the tests you can remove the created resources:
$ kubectl delete -f ./k8s