Skip to main content
Testkube 2.6.0 is out! A new AI Agent Framework that integrates with external MCP Servers for agentic troubleshooting, remediation, etc. Read More

Distributed K6 Example

info

This Workflows functionality is not available when running the Testkube Agent in Standalone Mode - Read More

Testkube has built-in support for parallelising any testing tool - check out the Parallelization documentation for details and examples.

The below example shows how to distribute a K6 test across a configurable number of nodes

  • Takes optional run configuration parameters (config)
    • vus to declare Virtual Users to distribute
    • duration to declare Load Test time
    • workers to declare number of K6 instances to create
  • Load the K6 script from Git repository (content)
  • Run distributed K6 tests (steps[0].parallel)
    • It's using built-in distribute/evenly Test Workflow Template, that sets pod.topologySpreadConstraints to distribute pods evenly across nodes (steps[0].parallel.use)
    • It's creating as many K6 workers as has been declared in workers config (steps[0].parallel.count)
    • It copies the test case from Git repository into workers (steps[0].parallel.transfer)
    • It reserves 1/8 CPU and 128MB for each worker (steps[0].parallel.container.resources)
    • It ensures that all workers will start load tests at the same time, when all are ready (steps[0].parallel.paused)
    • It runs K6 executable against that test case (steps[0].parallel.run.shell)
      • It passes number of Virtual Users and test duration via K6 parameters
      • It uses K6 --execution-segment argument to select the fraction of tests to run
    • It retrives the generated HTML reports as artifacts
Distributed K6 Workflow
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: distributed-k6
namespace: testkube
labels:
docs: example
spec:
config:
duration:
type: string
default: 5s
vus:
type: integer
default: 10
workers:
type: integer
default: 3
content:
git:
uri: https://github.com/kubeshop/testkube
paths:
- test/k6/k6-smoke-test.js
steps:
- name: Run test
parallel:
count: config.workers
transfer:
- from: /data/repo
use:
- name: distribute/evenly
container:
workingDir: /data/repo/test/k6
env:
- name: K6_SYSTEM_ENV
value: K6_SYSTEM_ENV_value
- name: K6_WEB_DASHBOARD
value: "true"
- name: K6_WEB_DASHBOARD_EXPORT
value: /data/k6-test-report.html
resources:
requests:
cpu: 128m
memory: 128Mi
paused: true
run:
image: grafana/k6:0.49.0
shell: |
k6 run k6-smoke-test.js \
-e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value \
--vus {{ config.vus }} \
--duration {{ shellquote(config.duration) }} \
--execution-segment {{ index }}/{{ count }}:{{ index + 1 }}/{{ count }}
artifacts:
workingDir: /data
paths:
- '*.html'

The k6 log output from one of the workers:

Distributed K6 Log Output