K6
Features described in this document are being deprecated as part of the transition to Test Workflows - Read More.
Testkube's k6 executor provides a convenient way of running k6 tests.
- Default command for this executor:
k6
- Default arguments for this executor command:
<k6Command>
<envVars>
<runPath>
Parameters in <>
are calculated at test execution:
<k6Command>
-cloud
orrun
depending on the test type<envVars>
- list of environment variables<runPath>
- path to the test files
See more at "Redefining the Prebuilt Executor Command and Arguments" on the Creating Test page.
- k6 is a free, developer-centric, and extensible open-source load testing tool that makes performance testing easy and productive for engineering teams.
- With k6, you can test the reliability and performance of your systems and catch performance regressions and problems earlier. K6 will help you to build resilient and performant applications that scale.
Check out our blog post to follow tutorial steps to harness the power of k6 load testing in Kubernetes with Testkube's CLI and API.
Example k6 testโ
In this example we will use the following k6 test: https://github.com/kubeshop/testkube/blob/main/test/k6/executor-tests/k6-smoke-test-without-envs.js
import http from "k6/http";
export default function () {
http.get("https://testkube.kubeshop.io/");
}
Test Sourceโ
K6 tests may vary significantly. The test may be just a single file, but may also consist of multiple files (modules, dependencies, or test data files). That's why all of the available Test Sources may be used with K6:
- Git file
- Git directory
- File
- String
Creating and Running a Testโ
- Dashboard
- CLI
- Custom Resource
If you prefer to use the Dashboard, just go to Tests, and click Add a new test
button. Then you need to fill in the test Name, choose the test Type (k6 script
), and then choose Test Source.
Fileโ
If the source is File, the test file is uploaded directly.
Git Fileโ
If the source is a Git file, you need to fill in repository details - Git repository URI (in this case https://github.com/kubeshop/testkube.git
), branch (main
), and the path to k6 script in your repository (test/k6/executor-tests/k6-smoke-test-without-envs.js
). In this example, the repository is public, but in the case of private ones you would need to additionally fill in Git credentials.
Stringโ
If the source is a String, the test script is added directly.
If you prefer using the CLI, you can create the test with testkube create test
.
You need to set:
--name
(for example,k6-test
)--type
(in this casek6/script
)
Then choose the Test Content type based on Test Source you want to use:
Fileโ
In the case of File test source:
--test-content-type
(file-uri
)--file
(path to your k6 script - in this casetest/k6/executor-tests/k6-smoke-test-without-envs.js
)
testkube create test --name k6-test --type k6/script --test-content-type file-uri --file test/k6/executor-tests/k6-smoke-test-without-envs.js
Test created testkube / k6-test ๐ฅ
Git fileโ
--test-content-type
(git-file
, so specific file will be checked out from the Git repository)--git-uri
- repository URI (in case of this example,https://github.com/kubeshop/testkube.git
)--git-branch
--git-path
- path to the k6 script in the repository (in this casetest/k6/executor-tests/k6-smoke-test-without-envs.js
)
testkube create test --name k6-test --type k6/script --test-content-type git-file --git-uri https://github.com/kubeshop/testkube.git --git-branch main --git-path test/k6/executor-tests/k6-smoke-test-without-envs.js
Test created testkube / k6-test ๐ฅ
Git Directoryโ
--test-content-type
(git-directory
, so the whole directory will be checked out from the Git repository)--git-uri
- repository URI (in case of this example,https://github.com/kubeshop/testkube.git
)--git-branch
--git-path
(path to the directory that should be checked out)--executor-args
(whole directory will be checked out - specific test file must be set as k6 argument - in this exampletest/k6/executor-tests/k6-smoke-test-without-envs.js
)
testkube create test --name k6-test --type k6/script --test-content-type git-dir --git-uri https://github.com/kubeshop/testkube.git --git-branch main --git-path test/k6/executor-tests --executor-args test/k6/executor-tests/k6-smoke-test-without-envs.js
Test created testkube / k6-test ๐ฅ
Using Additional K6 Arguments in Your Testsโ
Additional arguments can be passed to the k6
binary both on test creation (--executor-args
), and during test execution (--args
).
testkube run test -k6-test --args '--vus 100 --no-connection-reuse'
Git Fileโ
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
name: k6-test
namespace: testkube
spec:
type: k6/script
content:
type: git-file
repository:
type: git
uri: https://github.com/kubeshop/testkube.git
branch: main
path: test/k6/executor-tests/k6-smoke-test-without-envs.js
Git Directoryโ
Check out the entire Git directory (in the following example test/k6/executor-tests
), and run a specific test file (test/k6/executor-tests/k6-smoke-test-without-envs.js
):
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
name: k6-test
namespace: testkube
spec:
type: k6/script
content:
type: git-dir
repository:
type: git
uri: https://github.com/kubeshop/testkube.git
branch: main
path: test/k6/executor-tests
executionRequest:
args:
- test/k6/executor-tests/k6-smoke-test-without-envs.js
Stringโ
apiVersion: tests.testkube.io/v3
kind: Test
metadata:
name: k6-test
namespace: testkube
spec:
type: k6/script
content:
type: string
data: "import http from 'k6/http';\n\nexport default function () {\n http.get('https://testkube.kubeshop.io/');\n}"
K6 Test Resultsโ
A k6 test will be successful in Testkube when all checks and thresholds are successful. In the case of an error, the test will have failed
status, even if there is no failure in the summary report in the test logs. For details check this k6 issue.