Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/latest/set-up/set-up-distributed-k6/usage/scheduling-tests.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/latest/set-up/set-up-distributed-k6/usage/scheduling-tests/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
Schedule k6 tests
While the k6 Operator doesn’t support scheduling k6 tests directly, you can schedule tests with the CronJob object from Kubernetes directly. The CronJob would run on a schedule and execute the creation and deletion of the TestRun object.
Running these tests requires a little more setup than a standalone test run.
Create a ConfigMap with k6 scripts
Refer to
Run k6 scripts with TestRun CRD for details on how to create a ConfigMap with k6 scripts.
Create a ConfigMap of the YAML file for the TestRun job
When using the make deploy installation method, add a configMapGenerator to the kustomization.yaml:
configMapGenerator:
- name: <test-name>-config
files:
- <test-name>.yamlCreate a ServiceAccount for the CronJob
For the CronJob to be able to create and delete TestRun objects, create a service account:
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: k6-<namespace>
rules:
- apiGroups:
- k6.io
resources:
- testruns
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: k6-<namespace>
roleRef:
kind: Role
name: k6-<namespace>
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: k6-<namespace>
namespace: <namespace>
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: k6-<namespace>Create a CronJob
This is an example of how to define a CronJob in a YAML file:
# snapshotter.yml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: <test-name>-cron
spec:
schedule: '<cron-schedule>'
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
serviceAccount: k6
containers:
- name: kubectl
image: bitnami/kubectl
volumeMounts:
- name: k6-yaml
mountPath: /tmp/
command:
- /bin/bash
args:
- -c
- 'kubectl delete -f /tmp/<test-name>.yaml; kubectl apply -f /tmp/<test-name>.yaml'
restartPolicy: OnFailure
volumes:
- name: k6-yaml
configMap:
name: <test-name>-configWas this page helpful?
Related resources from Grafana Labs

