k6 Tutorial — Modern Load Testing in JavaScript (2026)
Get productive with k6 in an hour: scripting, stages, thresholds, checks, and the Grafana Cloud output that replaces JMeter for teams shipping to Kubernetes.

Last updated 2026-07-20 · 12 min read · By Avinash Kamble, reviewed by Priyanka G.
k6 replaced JMeter as the default load-test tool for cloud-native teams because scripts are JavaScript, results stream to Grafana, and one binary runs anywhere. This tutorial takes you from install to a production CI pipeline with meaningful thresholds.
Key takeaways
- Install k6 and run your first load test in 5 minutes.
- Stages, VUs, and iterations — the model you must understand.
- Thresholds and checks — how to fail a build on p95 latency.
- Output to Grafana Cloud and integrate into GitHub Actions.
1. Install and first test
brew install k6 # macOS
choco install k6 # Windows
sudo apt install k6 # Debian/Ubuntu
# script.js
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://api.example.com/health');
check(res, { 'status is 200': (r) => r.status === 200 });
sleep(1);
}
# run
k6 run script.js2. Stages — ramp-up and hold
export const options = {
stages: [
{ duration: '2m', target: 100 }, // ramp to 100 VUs
{ duration: '5m', target: 100 }, // hold
{ duration: '2m', target: 500 }, // spike
{ duration: '5m', target: 500 }, // hold
{ duration: '2m', target: 0 }, // ramp down
],
};Match stages to a real user pattern. See our performance strategy guide for how to derive stages from prod metrics.
3. Thresholds — fail the build on regressions
export const options = {
thresholds: {
http_req_failed: ['rate<0.01'], // < 1% errors
http_req_duration: ['p(95)<500', 'p(99)<1500'], // p95 < 500ms
checks: ['rate>0.99'], // 99% checks pass
},
};k6 exits non-zero when thresholds fail — perfect for CI gating.
4. Scenarios — realistic mixes
export const options = {
scenarios: {
browse: { executor: 'ramping-vus', stages: [...], exec: 'browse' },
checkout: { executor: 'constant-arrival-rate', rate: 10,
timeUnit: '1s', duration: '5m', preAllocatedVUs: 20, exec: 'checkout' },
},
};
export function browse() { http.get('/products'); }
export function checkout() { http.post('/orders', payload); }5. Output to Grafana Cloud + CI
# Local Grafana + InfluxDB
k6 run --out influxdb=http://localhost:8086/k6 script.js
# Grafana Cloud k6
K6_CLOUD_TOKEN=... k6 cloud script.js
# GitHub Actions
- uses: grafana/k6-action@v0.3.1
with:
filename: script.js
flags: --out cloudSee the official k6 docs and compare with JMeter to choose per project.
Frequently asked questions
1.k6 or JMeter in 2026?
2.Does k6 support browser testing?
3.How many VUs can one k6 instance drive?
4.Is k6 free?
Practice these questions
Run a live QA mock interview tailored to this topic and get per-skill scoring in minutes.
Was this article helpful?
More from k6 Load Testing
Grafana k6 — scripting, thresholds, scenarios.
- Performance Testingk6 Load Testing Tutorial 2026: First Test in 15 Min
- Performance TestingcURL to k6 Load Test — Convert a Real Request into a Performance Suite
Keep building your QA edge
Pillar guides- cURL to Code Converterturn any cURL command into ready-to-run test codeConvert any cURL command to Postman, Playwright, Rest Assured, k6, Cypress, Python, and more — free, in-browser.
- JSON / JSONPath / JMESPath TesterJSON / JSONPath / JMESPath testerDual-engine JSONPath + JMESPath tester with assertion builder and Postman/Playwright/Rest Assured export.
- Postman to Code Converterturn your Postman collection into a real test suiteConvert any Postman collection into a full Playwright, Rest Assured, k6, Cypress, Supertest, Python, or Karate test suite — folders, pm.test assertions, and environments preserved.
- JMeter Tutorial for BeginnersSoftwareTestPilot's JMeter walkthroughInstall JMeter, script your first load test, thresholds, distributed runs and CI wiring.
- QA Skills HubSoftwareTestPilot's QA skills tracksStructured skill tracks — Selenium, Playwright, Cypress, API, JMeter, SQL, Java, Python for testers.
- QA & Testing Glossarysoftware testing glossary500+ software testing terms defined — from ISTQB vocabulary to CI/CD, AI testing, and framework jargon.
Continue reading
Related concepts, tools & standards around Performance Testing
A quick reference of the people, companies, frameworks and technologies most often mentioned alongside Performance Testing in real QA teams — useful when you're mapping a learning path, preparing for interviews, or scoping a new project.
Join the QA Community
Connect with fellow testers, share job leads, and get career advice.
Stop Reinventing the Wheel. Upgrade Your QA Arsenal.
Take your testing skills from beginner to Lead Engineer. Supercharge your daily workflow with our premium digital resources.
- Ready-to-use testing strategy templates
- Advanced API & UI automation guides
- ⏱️ Save 10+ hours a week on test planning



Discussion
Ask a question, share your experience, or correct us. Be kind — real people are reading.