3

I have created kubernetes cluster on digitalocean. and I have deployed k6 as a job on kubernetes cluster.

apiVersion: batch/v1
kind: Job
metadata:
  name: benchmark
spec:
  template:
    spec:
      containers:
      - name: benchmark
        image: loadimpact/k6:0.29.0
        command: ["k6", "run", "--vus", "2", "--duration", "5m", "--out", "json=./test.json", "/etc/k6-config/script.js"]
        volumeMounts:
        - name: config-volume
          mountPath: /etc/k6-config
      restartPolicy: Never
      volumes:
      - name: config-volume
        configMap:
          name: k6-config

this is how my k6-job.yaml file look like. After deploying it in kubernetes cluster I have checked the pods logs. it is showing permission denied error. level=error msg="open ./test.json: permission denied" how to solve this issue?

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
  • 3
    Please [edit your question](https://stackoverflow.com/posts/65678315/edit) and fix the formatting – mdaniel Jan 12 '21 at 05:29
  • Code blocks can be formatted with ``` before and after code – Matt Jan 12 '21 at 06:57
  • @Devi I have done the formatting for you. Can you check the permissions of the `./test.json"` file? Also, are you using RBAC in your cluster? It's hard to say much with the info you provided so far. – Wytrzymały Wiktor Jan 12 '21 at 09:22
  • thank you for formatting @Wytrzymały Wiktor. I just thought that k6 will automatically create test.json file with the k6 output on my local – Devi varalakshmi Tangilla Mar 10 '21 at 10:29

1 Answers1

7

The k6 Docker image runs as an unprivileged user, but unfortunately the default work directory is set to /, so it has no permission to write there.

To work around this consider changing the JSON output path to /home/k6/out.json, i.e.:

command: ["k6", "run", "--vus", "2", "--duration", "5m", "--out", "json=/home/k6/test.json", "/etc/k6-config/script.js"]

I'm one of the maintainers on the team, so will propose a change to the Dockerfile to set the WORKDIR to /home/k6 to make the default behavior a bit more intuitive.

imiric
  • 8,315
  • 4
  • 35
  • 39