K6-operator job failing because K6_BROWSER_ENABLED not set

Title says it all; can I set K6_BROWSER_ENABLED somewhere in the CRD spec so that the job spec has it?

Hi @adam-xero

Welcome to the community forum :wave:

I think you can use the usual Kubernetes way to Define Environment Variables for a Container. Adding the configuration to the runner, similar to https://github.com/javaducky/demo-k6-operator/blob/main/resources/k6-output-grafana-cloud.yaml:

spec: 
.....
  runner:
    env:
        - name: K6_BROWSER_ENABLED
          value: true

I haven’t tested this, as I do not have a Kubernetes cluster available at this time. It works with Docker similarly. With the script in headless mode:

import { chromium } from 'k6/experimental/browser';

export default async function () {
    const browser = chromium.launch({
        headless: true,
        timeout: '60s',
    });
    const page = browser.newPage();

    try {
        await page.goto('https://test.k6.io/');
        page.screenshot({ path: 'screenshot.png' });
    } finally {
        page.close();
        browser.close();
    }
}

I successfully run docker run --rm -e K6_BROWSER_ENABLED=true -i grafana/k6 run - <script.js.

Similarly in Kubernetes, we should add the environment variable K6_BROWSER_ENABLED. Let me know if it does not work in Kubernetes, and I’ll dig further.

Cheers!

Heya @eyeveebe thanks for your response! This link https://github.com/javaducky/demo-k6-operator/blob/main/resources/k6-output-grafana-cloud.yaml: is unfortunately missing. We were following this guide Running distributed k6 tests on Kubernetes and so far not sure where we can configure or update the runner spec

Oh actually looks like I can just add it to the CRD https://github.com/javaducky/demo-k6-operator/blob/k6-v0.41.0/resources/k6-output-grafana-cloud.yaml

If anyone has stumbled into this, tldr you can set it in the K6 custom resource e.g.

apiVersion: k6.io/v1alpha1
kind: K6
metadata:
  name: crocodile-stress-test
spec:
  parallelism: 4
  runner:
    env:
      - name: K6_BROWSER_ENABLED
        value: "true"
  script:
    configMap:
      name: crocodile-stress-test
      file: test.js

1 Like

hi sorry to somewhat hijack this thread but it looks like you are trying to run k6 browser test on k6-operator? when i tried, it seems like chrome is not installed on the image i get this error:

time="2023-07-05T23:22:10Z" level=error msg="Uncaught (in promise) GoError: launching browser: exec: no command\n\tat github.com/grafana/xk6-browser/browser.mapBrowserType.func2 (native)\n\tat file:///test/fes_overview.js:14:36(46)\n" executor=per-vu-iterations scenario=default

how did you get around that? thanks!