Problem with k6-operator and xk6 custom resource

If i use for example this dockerfile :

FROM golang:1.19-alpine as builder
#Install K6 (version can be changed)
ADD /grafana/k6/releases/download/v0.42.0/k6-v0.42.0-linux-amd64.tar.gz k6-v0.42.0-linux-amd64.tar.gz
RUN tar -xzf k6-v0.42.0-linux-amd64.tar.gz
RUN mv k6-v0.42.0-linux-amd64/k6 /usr/bin/k6
RUN rm -rf k6-v0.42.0-linux-amd64.tar.gz k6-v0.42.0-linux-amd64

#Install xk6
RUN go install xk6@latest
RUN xk6 build --output /k6 --with /grafana/xk6-sql@latest
RUN rm -rf /usr/bin/k6
RUN mv /k6 /usr/bin/k6

FROM alpine:latest AS runtime

RUN apk add --no-cache ca-certificates=~20220614 && \
    adduser -D -u 12345 -g 12345 k6

COPY --from=builder /usr/bin/k6 /usr/bin/k6

USER 12345
WORKDIR /home/k6


I create a this custom resource :

kind: K6
  name: k6-sample
  parallelism: 4
      name: stress-test
      file: test.js
    image: private.registry:latest # just an example ( the image is pulled correctly ) 

my test.js file would be :

import http from 'k6/http';
import { check } from 'k6';

export const options = {
  stages: [
    { target: 200, duration: '30s' },
    { target: 0, duration: '30s' },

export default function () {
  const result = http.get('');
  check(result, {
    'http response status code is 200': result.status === 200,

the initializer pod gets this error :

standard_init_linux.go:228: exec user process caused: exec format error

do we have any way of replacing the xk6 binary built with k6 binary and then use it ?
I am successful in triggering the base loadimpact/k6:latest image but somehow, the custom resources with replaced k6 binary doesn’t work

*Note : tested the docker container locally and it works as intended.

*Note 2 : was not allowed to post more than 2 links in the post that’s why the dockerfile is incomplete

Hi @Darius

Welcome to the community forums :wave:

I find the example from @javaducky GitHub - javaducky/demo-k6-operator: Project for demonstrating the use of k6-operator within Kubernetes clusters. can help you. It creates a docker image for k6 with some extensions and it works. Can you check if that example works for you?

If not, kindly come back here and I’ll try to reproduce with your dockerfile.


@Darius, I’d also highly recommend testing your custom k6 image outside of Kubernetes before digging into things too deeply.

For example, try running:
docker run --rm -i [YOUR CUSTOM IMAGE] run - <test.js

I haven’t tried running your Dockerfile, but noticed you’re building the xk6-sql extension requiring CGO to be enabled.

1 Like

hey @javaducky

thanks for the reply, i’ve actually tried to run the docker on my local and it works as intended

docker run -v {path_to_script}/sql/:/files dbaas-sql-test run /files/stress-test.js.

I’m going to try the above mentioned example and get back with the results.

Thanks for the involvement


Solved it.
Thank you for everything.

The problem was this :

  1. Unfortunately I use Apple M1 Pro .
  2. Figured that the kubectl client is on Platform:“darwin/arm64” and the server on : Platform:“linux/amd64” and ofc at first i’ve build the image by default on arm64, thus the error : “standard_init_linux.go:228: exec user process caused: exec format error”
    And in most cases, apparently the error occurs when : trying to run a binary that was compiled for a different operating system or arch
  3. Solution : build the image with --platform linux/amd64.

hope this helps going forward.
I would change the title of the topic as well


Awesome, @Darius, thanks for sharing the solution, I’m sure it will help other community users.