a Locust on k8s example for scalable load tests.
- Install Docker.
- Install kubectl.
- Install Minikube to generate a local cluster.
- Install the latest Skaffold for easy and repeatable Kubernetes development.
make cluster
skaffold dev # `ctrl + c` to terminate
make api
curl localhost/random-number # check the server is running
Go to http://localhost:8089, and set the host address and the number of v-users.
k8s will auto-scale pods to make concurrent requests if needed.
$ kubectl get hpa --watch
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
locust-worker-hpa Deployment/locust-worker <unknown>/50% 1 10 1 21s
locust-worker-hpa Deployment/locust-worker 73%/50% 1 10 1 45s
locust-worker-hpa Deployment/locust-worker 73%/50% 1 10 2 60s
locust-worker-hpa Deployment/locust-worker 91%/50% 1 10 2 75s
locust-worker-hpa Deployment/locust-worker 81%/50% 1 10 2 90s
locust-worker-hpa Deployment/locust-worker 78%/50% 1 10 2 105s
locust-worker-hpa Deployment/locust-worker 85%/50% 1 10 4 2m
locust-worker-hpa Deployment/locust-worker 63%/50% 1 10 4 2m15s
locust-worker-hpa Deployment/locust-worker 38%/50% 1 10 4 2m30s
make finalize
Modify k8s/configmap.yaml. skaffold
will instantly apply the changes.
apiVersion: v1
kind: ConfigMap
metadata:
name: locust-configmap
data:
locustfile.py: |
from locust import FastHttpUser, between, task
class QuickstartUser(FastHttpUser):
wait_time = between(1, 3)
@task
def get_random_number(self):
self.client.get("/random-number")
Modify server/main.py.