Skip to main content
Distributed testing allows you to run a single k6 test across multiple machines, enabling higher load generation and testing from multiple IP addresses. This guide covers using the k6 Kubernetes operator to orchestrate distributed tests.

When to Use Distributed Tests

Consider distributed testing when:

High Load Requirements

A single optimized node cannot generate the load your test requires

Multiple IP Addresses

Your system under test needs to be accessed from different IP addresses

Geographic Distribution

You need to test from multiple geographic locations simultaneously

Kubernetes Environment

Kubernetes is already your preferred operations environment

Introducing k6-operator

The k6-operator is a Kubernetes operator that automates distributed k6 test execution. It defines a custom TestRun resource that specifies:
  • The k6 test script to execute
  • The number of parallel pods (parallelism)
  • Environment configuration
  • Resource allocation
When you create a TestRun, the operator automatically provisions k6 test jobs across your cluster, splitting the workload using execution segments.

Getting Started

Prerequisites

  • Access to a Kubernetes cluster
  • kubectl installed and configured
  • Appropriate cluster permissions
You can experiment locally using kind or k3d to run Kubernetes in Docker.

Step 1: Install the Operator

Install the k6-operator in your cluster:
Verify the installation:
You should see:

Step 2: Create a Test Script

Create your k6 test script (same as for local testing):
test.js
Always validate your script locally with k6 run test.js before deploying to Kubernetes.

Step 3: Add Test Script to Kubernetes

You can provide test scripts to the operator using either ConfigMaps or PersistentVolumes.

Step 4: Create a TestRun Resource

Define a TestRun custom resource to execute your test:
run-k6-from-configmap.yaml
This configuration:
  • Runs the test across 4 parallel pods
  • Loads script from the my-test ConfigMap
  • Automatically splits the workload using execution segments
The ConfigMap/PersistentVolumeClaim and TestRun must be in the same Kubernetes namespace.

Advanced Configuration

Environment Variables

Pass configuration through environment variables:
Use in your test script:

Command-Line Arguments

Pass k6 options via command-line arguments:

Resource Limits

Control pod resources:

Automatic Cleanup

Automatically remove test resources after completion:
Use cleanup: post when outputting to real-time services like Prometheus, Grafana Cloud k6, or other external outputs.

Running Tests

1

Apply the TestRun

Deploy your test configuration:
2

Monitor execution

Watch test progress:
3

Clean up resources

After the test completes:
Or use cleanup: post in the TestRun spec for automatic cleanup.

Complete Example

Here’s a comprehensive distributed test setup:
distributed-load-test.yaml
Corresponding test script:
test.js

Monitoring Distributed Tests

Using Prometheus

Using Grafana Cloud k6

Troubleshooting

Check pod events and logs:
Common issues:
  • ConfigMap not found in namespace
  • Insufficient cluster resources
  • Image pull errors
View test runner logs:
Check for:
  • Script errors (syntax, logic)
  • Network connectivity issues
  • Resource constraints
Verify execution segments:
Ensure parallelism is set correctly in the TestRun spec.
For distributed tests, use external outputs:
  • Prometheus Remote Write
  • Grafana Cloud k6
  • InfluxDB
  • Other supported outputs
Local console output won’t aggregate across pods.

Best Practices

Test Locally First

Always validate scripts with k6 run before deploying to Kubernetes

Use External Outputs

Configure real-time outputs for aggregated metrics across all pods

Set Resource Limits

Define appropriate CPU and memory limits to prevent cluster overload

Enable Cleanup

Use cleanup: post to automatically remove completed test resources

Monitor During Tests

Watch pod logs and metrics in real-time to catch issues early

Version Test Scripts

Store test scripts in version control and use ConfigMaps for deployment

Example: High-Scale Distributed Test

high-scale-test.yaml
With parallelism: 20 and TEST_VUS: 10000, each pod will run ~500 VUs. Adjust based on your pod resource limits and cluster capacity.

Next Steps