Basic K6 Example
Below is a simple workflow for executing an inline K6 test. You can paste this directly into the YAML of an existing or new test, just make
sure to update the name
and namespace
for your environment if needed.
- The
spec.content
property defines a simple k6 script which gets written to/data/example.js
- the
spec.steps
property defines a single step that runs the test and uploads the created report.
Basic K6 Workflow
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: k6-sample
namespace: testkube
labels:
docs: example
spec:
content:
files:
- path: /data/example.js
content: |-
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
http.get('https://test.k6.io');
sleep(1);
};
steps:
- name: Run Tests
workingDir: /data
run:
image: grafana/k6:0.49.0
env:
- name: K6_WEB_DASHBOARD
value: "true"
- name: K6_WEB_DASHBOARD_EXPORT
value: k6-test-report.html
args:
- run
- example.js
artifacts:
paths:
- k6-test-report.html
After execution, you can see the output from the test executions under the executions panel tabs:
- Log Output
- Artifacts
- HTLM Report
The log output from k6:
The uploaded report is available in the Artifacts tab:
Clicking the HTLM report opens it in your browser:
Basic K6 from Template
Below is an example workflow for executing the K6 test using an official Testkube Template.
Basic K6 Workflow from Template
apiVersion: testworkflows.testkube.io/v1
kind: TestWorkflow
metadata:
name: k6-sample-from-template
namespace: testkube
labels:
docs: example
spec:
container:
workingDir: /data/repo/test/k6/executor-tests
env:
- name: K6_SYSTEM_ENV
value: K6_SYSTEM_ENV_value
steps:
- name: Run from template
workingDir: /data/repo/test/k6/executor-tests
content:
git:
uri: https://github.com/kubeshop/testkube
revision: main
paths:
- test/k6/executor-tests/k6-smoke-test.js
template:
name: official/k6/v1
config:
version: 0.49.0
run: "k6 run k6-smoke-test.js -e K6_ENV_FROM_PARAM=K6_ENV_FROM_PARAM_value"