Foreword
Github address https://github.com/rootsongjc/distributed-load-testing-using-kubernetes
The tutorial describes how Kubernetes distributed load balancing tests, including a web application, and Docker image Kubernetes controllers / services. For more information, please see the Distributed Testing the Using the Load Kubernetes .
Note: The test is set up on my own local cluster of kubernetes test does not require the use of Google Cloud Platform.
ready
GCE and other components do not need, you just need to have a kubernetes cluster can be.
If you have not kubernetes cluster, you can refer kubernetes-handbook deploy a.
Deploying Web Applications
sample-webapp
Directory contains a simple web application testing. We will build its image as a docker, run kubernetes in. You can build your own, you can also directly use this I build a good image index.tenxcloud.com/jimmy/k8s-sample-webapp:latest
.
Sample-webapp deployed on kubernetes.
$ cd kubernetes-config
$ kubectl create -f sample-webapp-controller.yaml
$ kubectl create -f kubectl create -f sample-webapp-service.yaml
Locust deployment of the Controller and Service
locust-master
And locust-work
use the same docker mirror, modify cotnroller in the spec.template.spec.containers.env
field of value for your sample-webapp
service name.
- name: TARGET_HOST
value: http://sample-webapp:8000
Creating Controller Docker mirror (optional)
locust-master
And locust-work
all controller use locust-tasks
docker mirror. You can download gcr.io/cloud-solutions-http://olz1di9xf.bkt.clouddn.com/locust-tasks
, you can compile your own. Probably take a few minutes to compile, image size is 820M.
$ docker build -t index.tenxcloud.com/jimmy/locust-tasks:latest .
$ docker push index.tenxcloud.com/jimmy/locust-tasks:latest
Note : I am using a cloud-speed image repository.
Yaml each controller's spec.template.spec.containers.image
field specifies that my image:
image: index.tenxcloud.com/jimmy/locust-tasks:latest
Deployment Locust-Master
$ kubectl create -f locust-master-controller.yaml
$ kubectl create -f locust-master-service.yaml
Deployment Locust-Worker
Now deploy locust-worker-controller
:
$ kubectl create -f locust-worker-controller.yaml
You can very easily to the work expansion, through the command line:
$ kubectl scale --replicas=20 replicationcontrollers locust-worker
Of course, you can also WebUI: Dashboard - Workloads - Replication the Controllers - ServiceName to expansion Scale -.
Configuration Traefik
Reference kubernetes traefik ingress of installation , the ingress.yaml
addition of the following configurations:
- host: traefik.locust.io
http:
paths:
- path: /
backend:
serviceName: locust-master
servicePort: 8089
And then perform kubectl replace -f ingress.yaml
to update traefik.
By Traefik the dashboard you can see the newly added traefik.locust.io
nodes.
Test execution
Open the http://traefik.locust.io
page, click on Edit
the number of requests and the number of users enter fake user sent per second, click Start Swarming
on it to start the test.
Adjusted during the test sample-webapp
pod number (the default setting for a pod), to observe changes in the load of pod.
From the period of observation can be seen in the load is evenly distributed to the three pod.
In locust pages can be observed in real time can also download the test results.