├── README.md ├── target.yaml ├── tsung-config.yaml ├── tsung-master.yaml └── tsung-slave.yaml /README.md: -------------------------------------------------------------------------------- 1 | # Running Tsung in Kubernetes 2 | 3 | This project demonstrate one possible way to run Tsung in Kubernetes using `StatefulSet`. 4 | 5 | ## About Tsung 6 | 7 | [Tsung] is an open-source multi-protocol distributed load testing tool written in [Erlang]. 8 | With proper setup, Tsung could generate millions of virtual users accessing target endpoints. 9 | 10 | Typically we run Tsung in baremetal machines or virtual machines. In order to launch Tsung 11 | in Kubernetes, we have to figure out a way to assign hostnames to Tsung pods because Tsung 12 | master have to connect to slaves using their hostnames. 13 | 14 | ## About StatefulSet 15 | 16 | [StatefulSet] is a beta feature added to Kubernetes in 1.5. It is a controller used to 17 | provide unique identity to its Pods. Together with a headless service, we could assign dns 18 | name to each pods in the StatefulSet. 19 | 20 | ## Demo 21 | 22 | Here is a quick demo showing the process to launch a load test using Tsung in Kubernetes. 23 | You could modify `tsung-config.yaml` to test your own systems. 24 | 25 | ### Create Namespace 26 | 27 | ```console 28 | $ kubectl create namespace tsung 29 | ``` 30 | 31 | ### Launch test target 32 | 33 | We use nginx as a demo target 34 | 35 | ```console 36 | $ kubectl create -f target.yaml --namespace tsung 37 | ``` 38 | 39 | ### Set Tsung config 40 | 41 | We will inject Tsung config to master pod using `ConfigMap`. Modify the settings if you like. 42 | 43 | ```console 44 | $ kubeclt create -f tsung-config.yaml --namespace tsung 45 | ``` 46 | 47 | ### Launch Tsung slave 48 | 49 | ```console 50 | $ kubectl create -f tsung-slave.yaml --namespace tsung 51 | ``` 52 | 53 | ### Launch Tsung master 54 | 55 | Tsung master will begin the test as soon as the Pod boots up. When the test ended, 56 | the master process will keep running so that user could access the test report using 57 | Tsung web interface. 58 | 59 | ```console 60 | $ kubectl create -f tsung-slave.yaml --namespace tsung 61 | ``` 62 | 63 | ### Access Tsung web interface 64 | 65 | ```console 66 | $ kubectl port-forward tsung-master-0 -n tsung 8091:8091 67 | ``` 68 | 69 | Then we could access the web interface at `http://localhost:8091` 70 | 71 | ### Cleanup 72 | 73 | ```console 74 | $ kubectl delete namespace tsung 75 | ``` 76 | 77 | [Tsung]: http://tsung.erlang-projects.org/ 78 | [Erlang]: https://www.erlang.org/ 79 | [StatefulSet]: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/ 80 | -------------------------------------------------------------------------------- /target.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | labels: 6 | app: target 7 | name: target 8 | spec: 9 | ports: 10 | - port: 80 11 | protocol: TCP 12 | targetPort: 80 13 | selector: 14 | app: target 15 | type: ClusterIP 16 | --- 17 | apiVersion: extensions/v1beta1 18 | kind: Deployment 19 | metadata: 20 | labels: 21 | app: target 22 | name: nginx 23 | spec: 24 | replicas: 1 25 | selector: 26 | matchLabels: 27 | app: target 28 | template: 29 | metadata: 30 | labels: 31 | app: target 32 | spec: 33 | containers: 34 | - name: nginx 35 | image: nginx 36 | -------------------------------------------------------------------------------- /tsung-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | data: 3 | config.xml: | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | kind: ConfigMap 27 | metadata: 28 | name: tsung-config 29 | -------------------------------------------------------------------------------- /tsung-master.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | labels: 6 | run: tsung-master 7 | name: tsung-master 8 | spec: 9 | clusterIP: None 10 | selector: 11 | run: tsung-master 12 | ports: 13 | - port: 8091 14 | sessionAffinity: None 15 | type: ClusterIP 16 | --- 17 | apiVersion: apps/v1beta1 18 | kind: StatefulSet 19 | metadata: 20 | name: tsung-master 21 | spec: 22 | serviceName: "tsung-master" 23 | replicas: 1 24 | template: 25 | metadata: 26 | labels: 27 | run: tsung-master 28 | spec: 29 | containers: 30 | - name: tsung 31 | image: ddragosd/tsung-docker:1.6.0 32 | env: 33 | - name: ERL_SSH_PORT 34 | value: "22" 35 | args: 36 | - -k 37 | - -f 38 | - /tsung/config.xml 39 | - -F 40 | - start 41 | volumeMounts: 42 | - mountPath: /tsung 43 | name: config-volume 44 | volumes: 45 | - configMap: 46 | name: tsung-config 47 | name: config-volume 48 | -------------------------------------------------------------------------------- /tsung-slave.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v1 3 | kind: Service 4 | metadata: 5 | labels: 6 | run: tsung-slave 7 | name: tsung-slave 8 | spec: 9 | clusterIP: None 10 | selector: 11 | run: tsung-slave 12 | ports: 13 | - port: 22 14 | type: ClusterIP 15 | --- 16 | apiVersion: apps/v1beta1 17 | kind: StatefulSet 18 | metadata: 19 | name: tsung-slave 20 | spec: 21 | serviceName: "tsung-slave" 22 | replicas: 1 23 | template: 24 | metadata: 25 | labels: 26 | run: tsung-slave 27 | spec: 28 | containers: 29 | - name: tsung 30 | image: ddragosd/tsung-docker:1.6.0 31 | env: 32 | - name: SLAVE 33 | value: "true" 34 | --------------------------------------------------------------------------------