Running wiremock docker container in K8S with custom port generates "port xxxx is not a recognized option

952 views
Skip to first unread message

Graham Bunce

unread,
Mar 3, 2022, 5:02:33 AM3/3/22
to wiremock-user
As per this ticket (it's been closed as this is not considered a bug)
https://github.com/wiremock/wiremock/issues/1825

In summary:

Running wiremock in K8S to act as our service virtualization platform. Architecture is:

Custom Proxy as single endpoint to calling service. This proxy forwards to individual wiremock instances. each responsible for virtualizing a specific remote service (we cannot have one wiremock responsible for 2 remote services due to #1783).

We run this within a single K8S service/pod - our custom proxy container and 2 wiremock containers. Since it is in a single pod each container needs it's own port - we cannot use 8080 for both wiremock containers as they will conflict.

We run one wiremock container on port 8080 and wish to run the other on port 8081 (or anything else really, doesn't matter).

We pass an Args to the second wiremock (--port 8081). Container fails to start with

Exception in thread "main" joptsimple.UnrecognizedOptionException: port 8081 is not a recognized option at joptsimple.OptionException.unrecognizedOption(OptionException.java:108) at joptsimple.OptionParser.handleLongOptionToken(OptionParser.java:510) at joptsimple.OptionParserState$2.handleArgument(OptionParserState.java:56) at joptsimple.OptionParser.parse(OptionParser.java:396) at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.<init>(CommandLineOptions.java:342) at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:49) at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:133)

Somehow it looks like port is not being picked up correctly by the docker container in K8S though this works fine when running as a plain docker container.

Our K8S YML:

apiVersion: apps/v1 kind: Deployment metadata: namespace: virtual-services name: proxyservice labels: app: proxyservice spec: minReadySeconds: 5 replicas: 1 selector: matchLabels: app: proxyservice template: metadata: labels: app: proxyservice spec: volumes: - name: proxyservice-service1-volume hostPath: path: /run/desktop/mnt/host/c/dev/local-environment/wiremock/data/service1 type: Directory - name: proxyservice-service2-volume hostPath: path: /run/desktop/mnt/host/c/dev/local-environment/wiremock/data/service2 type: Directory containers: - name: proxyservice image: proxyservice:latest imagePullPolicy: Never ports: - containerPort: 80 env: - name: service.virtualization.enabled value: "false" - name: virtualservice1 image: wiremock/wiremock:latest-alpine ports: - containerPort: 8080 volumeMounts: - name: proxyservice-service1-volume mountPath : "/home/wiremock" readOnly: false - name: virtualservice2 image: wiremock/wiremock:latest-alpine ports: - containerPort: 8081 args: ["--port 8081"] volumeMounts: - name: proxyservice-service1-volume2 mountPath : "/home/wiremock" readOnly: false ---

In K8S it's my understanding that the "args" are passed to the ENTRYPOINT in the underlying docker container.

Alternative ARGS (e.g. --verbose) appear to work fine so it seems that "port" specifically has an issue somehow.

How should we tell the K8S docker container to run on a different port if the "--port XXXX" command appears to be invalid? Is there a different way to invoke this behaviour in K8S?

Graham Bunce

unread,
Mar 10, 2022, 10:24:19 AM3/10/22
to wiremock-user
Figured this out..... in K8S the args need to be:

args : ["--port", "8081"] instead of ["--port 8081"]

Reply all
Reply to author
Forward
0 new messages