A sample project demonstrating load testing with k6, featuring API tests for a crocodile management system.
├── api/ # API request modules
│ ├── loginUser.js
│ ├── registerUser.js
│ ├── createCrocodile.js
│ ├── getPublicCrocodiles.js
│ ├── getMyCrocodiles.js
│ └── getSingleCrocodile.js
├── helpers/ # Utility modules
│ ├── UserGenerator.js
│ └── WaitUtil.js
├── csv-user-generator/ # CSV data generation
│ └── generate-credentials.js
├── grafana/ # Grafana configuration
│ ├── docker-compose.yml
│ └── provisioning/dashboards/
├── jenkins/ # Jenkins pipeline
│ └── Jenkinsfile
├── test-app/ # Local test API
│ └── test-api.k6.io-0.0.5.zip
├── config.js # Configuration file
└── test.js # Main test file
npm installThe k6 public test API (test-api.k6.io) has been retired. You need to run the test API locally using Docker.
Steps:
-
Download and install Docker Desktop
-
Extract the
test-app/test-api.k6.io-0.0.5.zipfile:
cd test-app
unzip test-api.k6.io-0.0.5.zip- Start the API (may take 5 minutes on first run):
docker compose up -d-
Verify the API is running at
http://localhost:8000/ -
Update
config.jsto usehttp://localhost:8000/instead ofhttps://test-api.k6.io/ -
To stop the API:
docker compose downUpdate config.js with your API endpoint and test parameters.
Choose a profile based on your testing needs:
| Profile | VUs | Duration | Purpose |
|---|---|---|---|
| smoke | 2 | 30s | Quick sanity check |
| normal | 10 | Ramp-up/down | Standard load test |
| spike | 10→50 | Gradual spike | Test traffic spikes |
| stress | 50→100 | High constant | High load testing |
| endurance | 20 | 5 minutes | Soak testing |
k6 run test.jsk6 run -e PROFILE=normal test.jsk6 run --out influxdb=http://localhost:8086/k6 -e PROFILE=normal test.jsThis project supports three different approaches to track and visualize test results:
Best for: Continuous monitoring, historical data, team dashboards
Setup:
- Start InfluxDB and Grafana:
cd grafana
docker-compose up -d-
Access Grafana at
http://localhost:3000 -
Login with default credentials:
- Username:
admin - Password:
admin
- Username:
-
Run tests with InfluxDB output:
k6 run --out influxdb=http://localhost:8086/k6 -e PROFILE=normal test.js- Grafana dashboard is automatically provisioned and available immediately after startup
Pros & Cons:
| Aspect | Local | Jenkins | Kubernetes |
|---|---|---|---|
| Setup | Easy (Docker Compose) | Medium (need shared InfluxDB) | Medium (need persistent storage) |
| Real-time monitoring | Yes | Yes | Yes |
| Historical data | Yes | Yes | Yes (with persistent volumes) |
| Tags & Checks support | Yes | Yes | Yes |
| Resource overhead | Moderate (Docker) | Low (just k6) | Medium (requires infrastructure) |
Best for: Quick local testing, sharing single test results
Setup:
- Run test with web dashboard export:
K6_WEB_DASHBOARD=true K6_WEB_DASHBOARD_EXPORT=k6-report.html k6 run -e PROFILE=normal test.js- Open generated
k6-report.htmlin your browser
Note: This dashboard shows basic metrics but does not include custom tags and checks.
Pros & Cons:
| Aspect | Local | Jenkins | Kubernetes |
|---|---|---|---|
| Setup | Very easy | Very easy | Very easy |
| Setup time | Instant | Instant | Instant |
| File storage | Local file | Jenkins artifacts | Requires manual export |
| Tags & Checks | Not included | Not included | Not included |
| Suitable for | Quick checks | Build artifacts | Less ideal |
| Comparison | Can compare runs | Can compare builds | Difficult |
Command with all options:
K6_WEB_DASHBOARD=true K6_WEB_DASHBOARD_EXPORT=k6-report.html k6 run --out influxdb=http://localhost:8086/k6 -e PROFILE=normal test.jsBest for: Detailed analysis, custom tags & checks, standalone reports
Setup:
- Install k6-reporter:
npm install k6-reporter --save-dev- Run test with JSON output:
k6 run --out json=results.json -e PROFILE=normal test.js- Generate HTML report:
npx k6-reporter results.json- Open generated
summary.htmlin your browser
Pros & Cons:
| Aspect | Local | Jenkins | Kubernetes |
|---|---|---|---|
| Setup | Easy (npm install) | Medium (npm dependency) | Medium (requires npm) |
| Tags & Checks | Yes, all included | Yes, all included | Yes, all included |
| Detailed metrics | Comprehensive | Comprehensive | Comprehensive |
| File size | Medium | Medium | Medium |
| Standalone | Fully standalone | Works as artifact | Must extract from pod |
| Dependencies | Node.js/npm | Node.js/npm | Node.js/npm in image |
| Automation | Manual or scripted | Easy to script | Requires post-processing |
A sample Jenkinsfile is included for distributed load testing across multiple Jenkins slave nodes.
Location: jenkins/Jenkinsfile
- Runs load tests in parallel on up to 5 slave nodes
- Configurable load profile (smoke, normal, spike, stress, endurance)
- Metrics aggregation to single InfluxDB instance
- Parameterized Jenkins job
- Update slave node labels and IPs in Jenkinsfile (
slave-1throughslave-5) - Update InfluxDB URL (currently
http://100.200.100.200:8086/k6) - Create Jenkins job from this repository
- Run with desired profile parameter
Note: This is a template example. Adjust node labels, IPs, and InfluxDB endpoint for your environment.
Edit config.js to customize:
- API endpoint URL
- Test parameters
- User credentials
- Custom options
- k6 - Load testing tool
- Node.js & npm - JavaScript runtime and package manager
- Docker & Docker Compose - For running test API, InfluxDB, and Grafana
- k6-reporter (optional) - For detailed HTML reports
Modular API request functions for easier test organization and reusability.
Utility functions for user generation, waiting, and common test operations.
Script to generate test user credentials for load testing.
Pre-configured Grafana dashboards and InfluxDB setup using Docker Compose.
Template Jenkinsfile for distributed load testing across multiple nodes.
Packaged local version of the k6 test API for offline testing.
MIT