TestProject Forum
Powered by leading experts in the test automation community

Firefox headless not found by agent in Kubernetes

Hi,

thanks for adding Docker support to testproject.io!

In our Server we use Kubernetes, so I tried to translate the given example docker-compose.yaml containing the testproject-agent, chrome-headless and firefox-headless to a Kubernetes yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    io.kompose.service: testproject-data-volume
  name: testproject-data-volume
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 400Mi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    io.kompose.service: testproject-browser-data-volume
  name: testproject-browser-data-volume
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1000Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: testproject-agent
  name: testproject-agent
spec:
  selector:
    matchLabels:
      io.kompose.service: testproject-agent
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        io.kompose.service: testproject-agent
    spec:
      containers:
        - env:
            - name: CHROME
              value: "testproject-chrome-service:4444"
            - name: FIREFOX
              value: "testproject-firefox-service:4444"
            - name: TP_API_KEY
              value: xxxx
          image: testproject/agent:latest
          name: testproject-agent
          resources: {}
          volumeMounts:
            - mountPath: /var/testproject/agent
              name: testproject-data-volume
      restartPolicy: Always
      volumes:
        - name: testproject-data-volume
          persistentVolumeClaim:
            claimName: testproject-data-volume
      initContainers:
        - name: init-chrome-pod
          image: busybox
          args:
            - /bin/sh
            - -c
            - >
              set -x;
              while [ $(curl -sw '%{http_code}' "http://testproject-chrome-service:4444/wd/hub" -o /dev/null) -ne 302]; do
                sleep 2;
              done
        - name: init-firefox-pod
          image: busybox
          args:
            - /bin/sh
            - -c
            - >
              set -x;
              while [ $(curl -sw '%{http_code}' "http://testproject-firefox-service:4444/wd/hub" -o /dev/null) -ne 302]; do
                sleep 2;
              done
---
kind: Service
apiVersion: v1
metadata:
  name: testproject-chrome-service
spec:
  ports:
    - port: 4444
      targetPort: 4444
      protocol: TCP
  selector:
    io.kompose.service: testproject-chrome

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: testproject-chrome
  name: testproject-chrome
spec:
  selector:
    matchLabels:
      io.kompose.service: testproject-chrome
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        io.kompose.service: testproject-chrome
    spec:
      containers:
        - image: selenium/standalone-chrome
          name: headless-chrome
          resources: {}
          volumeMounts:
            - mountPath: /dev/shm
              name: chrome-claim0
      restartPolicy: Always
      volumes:
        - name: chrome-claim0
          persistentVolumeClaim:
            claimName: testproject-browser-data-volume
---
kind: Service
apiVersion: v1
metadata:
  name: testproject-firefox-service
spec:
  ports:
    - port: 4444
      targetPort: 4444
      protocol: TCP
  selector:
    io.kompose.service: testproject-firefox
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    io.kompose.service: testproject-firefox
  name: testproject-firefox
spec:
  selector:
    matchLabels:
      io.kompose.service: testproject-firefox
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        io.kompose.service: testproject-firefox
    spec:
      containers:
        - image: selenium/standalone-firefox
          name: headless-firefox
          resources: {}
          volumeMounts:
            - mountPath: /dev/shm
              name: firefox-claim0
      restartPolicy: Always
      volumes:
        - name: firefox-claim0
          persistentVolumeClaim:
            claimName: testproject-browser-data-volume

The problem is the firefox-headless browser is not found by the agent. In the logs there is given

2020-05-11 08:38:07.988 [INFO ] i.t.a.m.a.b                              Checking installed browsers...
2020-05-11 08:38:07.992 [INFO ] i.t.a.m.a.b                              Getting external browser version via http://testproject-chrome-service:4444/wd/hub
2020-05-11 08:38:08.526 [INFO ] i.t.a.m.a.b                              External CHROME version nis 81.0.4044.92
2020-05-11 08:38:08.585 [INFO ] i.t.a.m.a.b                              Getting external browser version via http://testproject-firefox-service:4444/wd/hub
2020-05-11 08:38:09.100 [ERROR] i.t.a.m.a.b                              Failed to get external FIREFOX version via: http://testproject-firefox-service:4444/wd/hub
2020-05-11 08:38:09.107 [INFO ] i.t.a.m.a.b                              Finished detecting installed browsers.

If I connect to the shell in testproject-agent and call

curl -v http://testproject-firefox-service:4444/wd/hub

the result is

*   Trying 10.96.133.112:4444...
* TCP_NODELAY set
* Connected to testproject-firefox-service (10.96.133.112) port 4444 (#0)
> GET /wd/hub HTTP/1.1
> Host: testproject-firefox-service:4444
> User-Agent: curl/7.67.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 302 Found
< Date: Mon, 11 May 2020 08:37:10 GMT
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Cache-Control: no-cache
< Location: http://testproject-firefox-service:4444/wd/hub/static/resource/hub.html
< Content-Length: 0
< Server: Jetty(9.4.z-SNAPSHOT)
<
* Connection #0 to host testproject-firefox-service left intact

Obviously there seems to be no network problem, Firefox can be reached.

Does anyone have an idea what I’m doing wrong?

Hello.
Can you please try to run all 3 containers as a part of the same deployment?
Also if that does not work, can you try and run the entire setup without firefox and see if he is detected.
Regards, Ran.

Hi Ran,

thanks for your reply. The given Kubernetes yaml is one file, everything contained in it is started as once. Is that the same deployment for you?

In the testproject.io -> Agents page the agent is shown with Chrome only. Nothing is detected after the start of the testproject-agent.

Regards,
Christoph

Hi @christoph.guse
Having everything in one file is different than running all the containers in the same pod
As you can see here https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/ you can see how to make all the containers run in the same pod.

Also please try to run without chrome and see if it detects firefox.

Best Regards, Ran.