%%
date:: [[2022-11-16]], [[2022-11-18]], [[2023-04-25]]
%%
# [[Using k6 Operator for distributed load testing]]
[repo](https://github.com/grafana/k6-operator)
The [[k6 (tool)|k6]] [[Kubernetes Operator|Operator]] allows the creation of a k6 [[Kubernetes Custom Resources|custom resource]] within a [[Kubernetes]] cluster. The advantages of the k6 Operator are:
- It allows k6 load tests to be executed and managed in the same way that Kubernetes resources are.
- It is a way to allow for distributed load testing, without the use of [[k6 Cloud]].
<iframe width="560" height="315" src="https://www.youtube.com/embed/ZAq87eZ1w2U?start=1768&end=2278" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
## How to use k6 Operator
`git clone https://github.com/grafana/k6-operator && cd k6-operator`
`make deploy`
Write the k6 script, and save it as `test.js`.
```bash
kubectl create configmap poketest --from-file test.js
configmap/poketest created
```
### Create custom resource
```yaml
apiVersion: k6.io/v1alpha1
kind: K6
metadata:
name: k6-poketest
spec:
parallelism: 10
script:
configMap:
name: poketest
file: test.js
```
### Deploy custom resource
```bash
kubectl apply -f k6-custom-resource.yml
k6.k6.io/k6-poketest created
```
### Confirm that the tests have started
```bash
kubectl get k6
kubectl get jobs
kubectl get pods
```
## Limitations
- Thresholds
- it's difficult to choose geographical zones
- no threshold calculation or stop when threshold is reached
- no results aggregation natively, but you can do it with Grafana (for example)
- k8s only
## Videos on the k6 Operator
### With the creator, [[Simme Aronsson]]
<iframe width="560" height="315" src="https://www.youtube.com/embed/KPyI8rM3LvE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
*k6 Office Hours #21: How to run distributed load tests with k6 operator*
### With contributor [[Hans Knecht]]
<iframe width="560" height="315" src="https://www.youtube.com/embed/IJ0uQgn7gI8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
*k6 Office Hours #34: k6 load testing on Kubernetes using the k6 operator*
### With [[Paul Balogh]], Developer Advocate
<iframe width="560" height="315" src="https://www.youtube.com/embed/OqeVrDnRFiU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
*Paul presenting at a CNCF Webinar: Running distributed load tests with the Grafana k6 operator*
<iframe width="560" height="315" src="https://www.youtube.com/embed/5d5zxsGz8L4" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
*k6 Office Hours #72: Distributed load testing using Kubernetes with k6*
## References
Aronsson, S. (2021). _Running distributed k6 tests on Kubernetes._ Retrieved from https://k6.io/blog/running-distributed-tests-on-k8s/