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 namedk6.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):- Default values - Built-in k6 defaults
- Configuration file -
k6.jsonor specified via--config - Script options -
export const options = {}in your script - Environment variables -
K6_*environment variables - 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
Schema Validation
While k6 doesn’t provide an official JSON schema, the configuration structure mirrors thelib.Options Go struct. Invalid options will cause k6 to exit with an error.
Troubleshooting
Config Not Loading
If your config isn’t being applied:- Verify the file exists:
ls -la k6.json - Check JSON syntax:
cat k6.json | jq . - Use explicit path:
k6 run --config ./k6.json script.js - Enable verbose logging:
k6 run --verbose --config k6.json script.js