-
Notifications
You must be signed in to change notification settings - Fork 264
Add k6-operator docs to Set up #1559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
9eddaaf
chore: add basic structure for k6-operator docs
heitortsergent 4ea406d
chore: hide reference for now
heitortsergent 2f1015b
k6-operator: add main sections from the repo Readme.md
yorugac 0731380
Add a short introduction to the index page
heitortsergent 835339f
Update install-k6-operator.md
heitortsergent 96b0ecf
Update upgrade-k6-operator.md
heitortsergent 0bd07ec
Update troubleshooting.md
heitortsergent 024875d
Update executing-k6-scripts-with-testrun-crd.md
heitortsergent fc15830
Update extensions.md
heitortsergent af61bb4
Update extensions.md
heitortsergent 0bd92fb
Update common-options.md
heitortsergent 66bd188
Update scheduling-tests.md
heitortsergent 5c71c70
k6-operator: fix typos
yorugac 8a7e311
k6-operator: add content for troubleshooting.md
yorugac 9d046ed
chore: replaces instances of k6-operator with k6 Operator
heitortsergent b8b8104
chore: add uninstall instructions
heitortsergent 1f999ad
chore: hide Upgrade k6 Operator page
heitortsergent c77a629
chore: add Use the k6 operator with Grafana Cloud k6 page
heitortsergent 1d27807
chore: review troubleshooting doc
heitortsergent bc80292
chore: update Namespaced deployment heading to Watch namespace
heitortsergent c079328
Merge branch 'main' into chore/add-plz-docs
heitortsergent 3f08b76
Apply suggestions from code review
heitortsergent ac060ef
Move docs to next and v0.52.x folders
heitortsergent 6360694
Remove docs from v0.50.x folder
heitortsergent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
k6-operator: add main sections from the repo Readme.md
- Loading branch information
commit 2f1015bca9a22fb4db556c1a5b0d0719425dd83b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
docs/sources/v0.50.x/set-up/set-up-distributed-k6/usage/common-options.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| weight: 300 | ||
| title: Common options | ||
| --- | ||
|
|
||
| <!-- TODO: consider removeing this once full reference is generated --> | ||
|
|
||
| # Common options | ||
|
|
||
| The only options that must be defined as part of `TestRun` CRD spec are `script` and `parallelism`. But there are many others; here are some of the most common. | ||
|
|
||
| ## Parallelism | ||
|
|
||
| `parallelism` defines how many instances of k6 runneres you want to create. Each instance will be assigned an equal execution segment. For instance, if your test script is configured to run 200 VUs and `parallelism` is set to 4, the k6-operator will | ||
| create four k6 jobs, each running 50 VUs to achieve the desired VU count. | ||
|
|
||
| ## Separate | ||
|
|
||
| `separate: true` indicates that the jobs created need to be distributed across different nodes. This is useful if you're running a | ||
| test with a really high VU count and want to make sure the resources of each node won't become a bottleneck. | ||
|
|
||
| ## Service account | ||
|
|
||
| If you want to use a custom Service Account you'll need to pass it into both the starter and runner object: | ||
|
|
||
| ```yaml | ||
| apiVersion: k6.io/v1alpha1 | ||
| kind: TestRun | ||
| metadata: | ||
| name: <test-name> | ||
| spec: | ||
| script: | ||
| configMap: | ||
| name: "<configmap>" | ||
| runner: | ||
| serviceAccountName: <service-account> | ||
| starter: | ||
| serviceAccountName: <service-account> | ||
| ``` | ||
|
|
||
| ## Runner | ||
|
|
||
| Defines options for the test runner pods. The non-exhaustive list includes: | ||
|
|
||
| * passing resource limits and requests | ||
| * passing in labels and annotations | ||
| * passing in affinity and anti-affinity | ||
| * passing in a custom image | ||
|
|
||
| ## Starter | ||
|
|
||
| Defines options for the starter pod. The non-exhaustive list includes: | ||
|
|
||
| * passing in custom image | ||
| * passing in labels and annotations | ||
|
|
||
|
|
||
| {{< section depth=2 >}} | ||
10 changes: 0 additions & 10 deletions
10
.../v0.50.x/set-up/set-up-distributed-k6/usage/configure-scripts-in-testrun-crd.md
This file was deleted.
Oops, something went wrong.
221 changes: 221 additions & 0 deletions
221
...0.x/set-up/set-up-distributed-k6/usage/executing-k6-scripts-with-testrun-crd.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| --- | ||
| weight: 100 | ||
| title: Executing k6 scripts with TestRun CRD | ||
| --- | ||
|
|
||
| # Executing k6 scripts with TestRun CRD | ||
|
|
||
| ## Defining test scripts | ||
|
|
||
| There are several ways to configure scripts in `TestRun` CRD. | ||
| #The operator utilises `ConfigMap`s and `LocalFile` to serve test scripts to the jobs. To upload your own test script, run the following command to configure through `ConfigMap`: | ||
|
|
||
| ### ConfigMap | ||
|
|
||
| The main way to configure script is to create a ConfigMap with the script contents: | ||
|
|
||
| ```bash | ||
| kubectl create configmap my-test --from-file /path/to/my/test.js | ||
| ``` | ||
|
|
||
| Then specify it in `TestRun`: | ||
|
|
||
| ```bash | ||
| script: | ||
| configMap: | ||
| name: my-test | ||
| file: test.js | ||
| ``` | ||
|
|
||
| {{% admonition type="note" %}} | ||
|
|
||
| There is a character limit of 1048576 bytes to a single configmap. If you need to have a larger test file, you'll need to use a volumeClaim or a localFile instead | ||
|
|
||
| {{% /admonition %}} | ||
|
|
||
| ### VolumeClaim | ||
|
|
||
| If you have a PVC with the name `stress-test-volumeClaim` containing your script and any other supporting file(s), you can pass it to the test like this: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| script: | ||
| volumeClaim: | ||
| name: "stress-test-volumeClaim" | ||
| # test.js should exist inside /test/ folder. | ||
| # All the js files and directories test.js is importing | ||
| # should be inside the same directory as well. | ||
| file: "test.js" | ||
| ``` | ||
|
|
||
| The pods will expect to find script files in `/test/` folder. If `volumeClaim` fails, it's the first place to check: the latest initializer pod does not generate any logs and when it can't find the file, it will terminate with error. So missing file may not be that obvious and it makes sense to check it is present manually. See [GH issue](https://github.com/k6-operator/issues/143) for potential improvements. | ||
|
|
||
| #### Sample directory structure | ||
|
|
||
| ``` | ||
| ├── test | ||
| │ ├── requests | ||
| │ │ ├── stress-test.js | ||
| │ ├── test.js | ||
| ``` | ||
|
|
||
| In the above example, `test.js` imports a function from `stress-test.js` and these files would look like this: | ||
|
|
||
| ```js | ||
| // test.js | ||
| import stressTest from "./requests/stress-test.js"; | ||
|
|
||
| export const options = { | ||
| vus: 50, | ||
| duration: '10s' | ||
| }; | ||
|
|
||
| export default function () { | ||
| stressTest(); | ||
| } | ||
| ``` | ||
|
|
||
| ```js | ||
| // stress-test.js | ||
| import { sleep, check } from 'k6'; | ||
| import http from 'k6/http'; | ||
|
|
||
|
|
||
| export default () => { | ||
| const res = http.get('https://test-api.k6.io'); | ||
| check(res, { | ||
| 'status is 200': () => res.status === 200, | ||
| }); | ||
| sleep(1); | ||
| }; | ||
| ``` | ||
|
|
||
| ### LocalFile | ||
|
|
||
| If the script is present in the filesystem of custom runner image, it can be accessed with `localFile` option: | ||
|
|
||
| ```yaml | ||
| spec: | ||
| parallelism: 4 | ||
| script: | ||
| localFile: /test/test.js | ||
| runner: | ||
| image: <custom-image> | ||
| ``` | ||
|
|
||
| {{% admonition type="note" %}} | ||
|
|
||
| If there is any limitation on usage of `volumeClaim` in your cluster you can use the `localFile` option, but usage of `volumeClaim` is recommneded. | ||
|
|
||
| {{% /admonition %}} | ||
|
|
||
|
|
||
| ### Multi-file tests | ||
|
|
||
| In case your k6 script is split between more than one JS file, you can simply create a ConfigMap with several data entries like this: | ||
|
|
||
| ```bash | ||
| kubectl create configmap scenarios-test --from-file test.js --from-file utils.js | ||
| ``` | ||
|
|
||
| If there are too many files to specify manually, kubectl with folder might be an option as well: | ||
| ```bash | ||
| kubectl create configmap scenarios-test --from-file=./test | ||
| ``` | ||
|
|
||
| Alternatively, you can create an archive with k6: | ||
| ```bash | ||
| k6 archive test.js [args] | ||
| ``` | ||
|
|
||
| The above command will create an `archive.tar` in your current folder, unless `-O` option is used to change the name of the output archive. Then it is possible to put that archive into configmap similarly to JS script: | ||
| ```bash | ||
| kubectl create configmap scenarios-test --from-file=archive.tar | ||
| ``` | ||
|
|
||
| In case of using an archive it must correctly set in your yaml for `TestRun` deployment: | ||
|
|
||
| ```yaml | ||
| # ... | ||
| spec: | ||
| script: | ||
| configMap: | ||
| name: "crocodile-stress-test" | ||
| file: "archive.tar" # <-- change here | ||
| ``` | ||
|
|
||
| In other words, `file` option must be the correct entrypoint for `k6 run` command. | ||
|
|
||
|
|
||
| ## Executing tests | ||
|
|
||
| Tests are executed by applying the custom resource `TestRun` to a cluster where the k6-operator is running. Additional optional properties of `TestRun` CRD allow you to control some key aspects of a distributed execution. For example: | ||
|
|
||
| ```yaml | ||
| # k6-resource.yml | ||
|
|
||
| apiVersion: k6.io/v1alpha1 | ||
| kind: TestRun | ||
| metadata: | ||
| name: k6-sample | ||
| spec: | ||
| parallelism: 4 | ||
| script: | ||
| configMap: | ||
| name: k6-test | ||
| file: test.js | ||
| separate: false | ||
| runner: | ||
| image: <custom-image> | ||
| metadata: | ||
| labels: | ||
| cool-label: foo | ||
| annotations: | ||
| cool-annotation: bar | ||
| securityContext: | ||
| runAsUser: 1000 | ||
| runAsGroup: 1000 | ||
| runAsNonRoot: true | ||
| resources: | ||
| limits: | ||
| cpu: 200m | ||
| memory: 1000Mi | ||
| requests: | ||
| cpu: 100m | ||
| memory: 500Mi | ||
| starter: | ||
| image: <custom-image> | ||
| metadata: | ||
| labels: | ||
| cool-label: foo | ||
| annotations: | ||
| cool-annotation: bar | ||
| securityContext: | ||
| runAsUser: 2000 | ||
| runAsGroup: 2000 | ||
| runAsNonRoot: true | ||
| ``` | ||
|
|
||
| `TestRun` CR is created with this command: | ||
|
|
||
| ```bash | ||
| kubectl apply -f /path/to/your/k6-resource.yml | ||
| ``` | ||
|
|
||
| ## Cleaning up resources | ||
|
|
||
| After completing a test run, you need to clean up the test jobs created. Manually this can be done by running the following command: | ||
|
|
||
| ```bash | ||
| kubectl delete -f /path/to/your/k6-resource.yml | ||
| ``` | ||
|
|
||
| Alternatively, automatic deletion of all resources can be configured with `cleanup` option: | ||
| ```yaml | ||
| spec: | ||
| cleanup: "post" | ||
| ``` | ||
|
|
||
| With `cleanup` option set, k6-operator will remove `TestRun` CRD and all created resources once the test run is finished. | ||
|
|
||
| {{< section depth=2 >}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.