How to delete k6 jobs in kubernetes automatically?

Hi!

I’m using k6 to run tests on k8s

I want to know If is possible to configure the runner to remove / clean up the jobs automatically (i cant run kubectl delete) like using ttlSecondsAfterFinished

Thanks

Hello, and welcome to the forum! You can include the cleanup: post option in your custom resource.

Here is an example including the option:

apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
  name: run-k6-with-realtime
spec:
  parallelism: 4
  # Removes all resources upon completion
  cleanup: post
  script:
    configMap:
      name: my-test
      file: test.js
  arguments:  -o experimental-prometheus-rw

This example is from the Running distributed tests guide in the documentation site.

2 Likes

Thanks a lot mate! Works as expected!

2 Likes

in my case I had some failed jobs in my k8 cluster due to which pods remained in the namespace ( i had used the same command ) beyond the duration of load test

this was my scenario spread across 8 pods/runners . for smaller loads the pods do get cleaned up after the duration

export const options = {
  scenarios: {
    ramping_arrival_rate: {
      executor: 'ramping-arrival-rate',
      startRate: 100, // Start with 10 iterations/second
      timeUnit: '1s', // RPS will be calculated per second
      preAllocatedVUs: 20000, // Preallocate 50 VUs
      stages: [
        { target: 500, duration: '2m' },   // Ramp up to 500 RPS in 3 minutes
        { target: 1000, duration: '4m' },  // Ramp up to 1000 RPS in the next 2 minutes
        { target: 3000, duration: '3m' },  // Ramp up to 1500 RPS in the next 2 minutes
        { target: 0, duration: '1m' },     // Ramp down to 0 RPS over 2 minutes
      ],
    },
  },
};