Skip to main content

Configuration File

k6 supports configuration via a JSON file, allowing you to define test options without cluttering your test scripts.

Overview

By default, k6 looks for a configuration file named k6.json in the current directory. You can specify a different file using the --config flag or K6_CONFIG environment variable.

Configuration Precedence

Configuration is loaded in this order (later overrides earlier):
  1. Default values - Built-in k6 defaults
  2. Configuration file - k6.json or specified via --config
  3. Script options - export const options = {} in your script
  4. Environment variables - K6_* environment variables
  5. CLI flags - Command-line arguments (highest priority)

File Format

The configuration file is JSON with the following structure:

Configuration Options

Execution Options

int
default:"1"
Number of virtual users.
string
Test duration (e.g., 30s, 5m, 1h).
int
Total iteration limit across all VUs.
array
Ramping configuration stages.
object
Advanced scenario configuration.

HTTP Options

int
default:"20"
Maximum parallel batch requests.
int
default:"6"
Maximum parallel batch requests per host.
int
default:"10"
Maximum HTTP redirects to follow.
string
User-Agent string for requests.
boolean
Skip TLS certificate verification.
boolean
Disable HTTP keep-alive.
boolean
Don’t reuse connections between iterations.
boolean
Don’t save HTTP response bodies.

Thresholds

object
Pass/fail criteria for metrics.

Output Configuration

array
Metrics output destinations.
array
Statistics to calculate for trends.
string
Time unit for trend stats: s, ms, us.
array
System tags to include in metrics.

Test Behavior

boolean
Start test in paused state.
boolean
Skip setup() function.
boolean
Skip teardown() function.
boolean
Keep API server alive after test.
boolean
Disable usage statistics.
boolean
Throw warnings as errors.

Network Configuration

array
IP ranges to blacklist.
array
Hostname patterns to block.
object
DNS resolver configuration.

Cloud Configuration

object
Grafana Cloud k6 options.

Complete Example

Here’s a comprehensive configuration file example:

Best Practices

Separate Configs for Environments

Create environment-specific configs:

Use JSON Schema

Validate your config with a JSON schema editor for better error detection.

Version Control

Commit config files to version control:

Document Custom Settings

Add comments in accompanying README:

Avoid Secrets

Never commit secrets to config files. Use environment variables instead.

Schema Validation

While k6 doesn’t provide an official JSON schema, the configuration structure mirrors the lib.Options Go struct. Invalid options will cause k6 to exit with an error.

Troubleshooting

Config Not Loading

If your config isn’t being applied:
  1. Verify the file exists: ls -la k6.json
  2. Check JSON syntax: cat k6.json | jq .
  3. Use explicit path: k6 run --config ./k6.json script.js
  4. Enable verbose logging: k6 run --verbose --config k6.json script.js

Option Priority

Remember CLI flags override config:

Invalid Options

k6 validates options on startup. Check error messages:

See Also