locust

by joaquinito2051

Helm chartv1.0.0App 0.9.0

A modern load testing framework

About this chart

Locust Helm Chart

This is a templated deployment of Locust for Distributed Load testing using Kubernetes.

Pre Requisites:

  • Requires (and tested with) helm v2.1.2 or above.

Chart details

This chart will do the following:

  • Convert all files in tasks/ folder into a configmap
  • If an existing configmap is specified, it will be used instead of building one from the chart
  • Create a Locust master and Locust worker deployment with the Target host and Tasks file specified.

Installing the chart

To install the chart with the release name locust-nymph in the default namespace:

helm install -n locust-nymph --set master.config.target-host=http://site.example.com <helm-repo>/locust

helm install -n locust-nymph --set master.config.target-host=http://site.example.com stable/locust

ParameterDescriptionDefault
NameLocust master namelocust
image.repositoryLocust container image namegreenbirdit/locust
image.tagLocust Container image tag0.9.0
image.pullSecretsLocust Container image registry secretNone
service.typek8s service type exposing masterNodePort
service.nodePortPort on cluster to expose master0
service.annotationsKV containing custom annotations{}
service.extraLabelsKV containing extra labels{}
master.config.target-hostlocust target hosthttp://site.example.com
worker.config.locust-scriptlocust script to run/locust-tasks/tasks.py
worker.config.configmapNameconfigmap to mount locust scripts fromempty, configmap is created from tasks folder in Chart
worker.replicaCountNumber of workers to run2

Specify parameters using --set key=value[,key=value] argument to helm install

Alternatively a YAML file that specifies the values for the parameters can be provided like this: Specify parameters using --set key=value[,key=value] argument to helm install

$ helm install --name my-release -f values.yaml <helm-repo>/locust

$ helm install --name my-release -f values.yaml stable/locust

Creating configmap with your Locust task files

You're probably developing your own Locust scripts that you want to run in this distributed setup. To get those scripts into this deployment you can fork the chart and put them into the tasks folder. From there they will be converted to a configmap and mounted for use in Locust.

Another solution, if you don't want to fork the Chart, is to put your Locust scripts in a configmap and provide the name as a config parameter in values.yaml. You can read more on the use of configmaps as volumes in pods here.

If you have your Locust task files in a folder named "scripts" you would use something like the following command:

kubectl create configmap locust-worker-configs --from-file path/to/scripts

Interacting with Locust

Get the Locust URL following the Post Installation notes. Using port forwarding you should be able to connect to the web ui on Locust master node.

You can start the swarm from the command line using port forwarding as follows:

for example:

export LOCUST_URL=http://127.0.0.1:8089

Start / Monitor & Stop the Locust swarm via the web panel or with following commands:

Start:

curl -XPOST $LOCUST_URL/swarm -d"locust_count=100&hatch_rate=10"

Monitor:

watch -n 1 "curl -s $LOCUST_URL/stats/requests | jq -r '[.user_count, .total_rps, .state] | @tsv'"

Stop:

curl $LOCUST_URL/stop

Deploy locust with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has locust on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartlocust is pinned at v1.0.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply