Locust.io on Kubernetes

Moses Liao GZ
Level Up Coding
Published in
4 min readJan 20, 2021

--

I used to have a repository that contains python code that run locust.io on EC2 based on fabric. What it does is it installs locust.io on the EC2 instance and then pushes the locustfile.py to the instance and runs it. The problem is EC2 can be a pain to use and there isn’t any load balancing and scaling.

Hence I look around and found some GitHub repository that I can use locust on Kubernetes. The problem is you have to use his image and usually isn’t the latest version of locust. Hence I decided to come up with my version of locust.io that is more user friendly in my opinion, a Kubernetes deployment that uses the latest image from their official docker repository and you can easily change the locustfile.pyas and when you need.

This is the repository I created that will serve the purpose of deploying.

Cluster Deployment

All the source files used below are stored in the root directory. Let’s set up the cluster. (I assume that kubernetes is up and running and kubectl is able to connect to the cluster.)

$ git clone git@github.com:mosesliao/kubernetes-locust.git
$ cd kubernetes-locust
$ kubectl create -f nodeport.yaml -f scripts-cm.yaml -f master-deployment.yaml -f service.yaml -f slave-deployment.yaml

kubectl command connects to my AWS EKS cluster and create the components mentioned above. If ran for the first time, it may take a while to complete (if there is no locust docker image on the cluster, it needs to be downloaded first).

Let’s go through each and every component

nodeport.yml: This file creates the service to have the external port to be connected to the EKS cluster

scripts-cm.yml: This file creates the locustfile.pythat you need to run locust.io on the docker instances. It will be mounted as a volume for both master and slave nodes

master-deployment.yaml: This file creates the master node of the locust.io

slave-deployment.yaml: This file creates the slave node and connects to the master node. The difference is the args given.

service.yaml: This file ties all the nodes together, ensure that they are communicated through the correct ports.

--

--