Dynamic scaling selenium grid in kubernetes

  • Grid status : The grid status gives us information about the browser nodes connected to selenium and also if they are running a session
  • Session queue : The session queue gives us information about the queued sessions and their needed capabilities. We need this information to deploy pods later
  • Drain node : The drain API will be used to shut down no longer needed browser nodes
  • Create pod : The manager must deploy pods to kubernetes.

Configure your pods correctly

apiVersion: v1kind: Podmetadata:  name: chrome-node-1spec:volumes:  - name: dshm    emptyDir:      medium: MemoryrestartPolicy: Nevercontainers:  - name: selenium-node-chrome    image: selenium/node-chrome:4   ports:   - containerPort: 5555   volumeMounts:   - mountPath: /dev/shm     name: dshm  env:   - name: SE_EVENT_BUS_HOST     value: "selenium-hub"   - name: SE_EVENT_BUS_SUBSCRIBE_PORT     value: "4443"   - name: SE_EVENT_BUS_PUBLISH_PORT     value: "4442"  resources:    limits:      memory: "550Mi"      cpu: "500m"
{"value": [{"capabilities": [{"acceptInsecureCerts": true,"browserName": "chrome","goog:chromeOptions": {"args": [],"extensions": []}}],"requestId": "38570b15-6cf6-40bf-96f8-df507ec4256d"},...]}
{"value": {"ready": true,"message": "Selenium Grid ready.","nodes": [{"id": "fd1ab0ad-e375-41b7-aec7-f95b866e3a86","uri": "","maxSessions": 1,"osInfo": {"arch": "amd64","name": "Linux","version": "5.4.0-42-generic"},"heartbeatPeriod": 60000,"availability": "UP","version": "4.1.2 (revision 9a5a329c5a)","slots": [{"id": {"hostId": "fd1ab0ad-e375-41b7-aec7-f95b866e3a86","id": "7b09bb45-898b-4a44-bdea-18fa77901df8"},"lastStarted": "2022-02-21T11:44:12.072459Z","session": {"capabilities": {"acceptInsecureCerts": true,"browserName": "chrome","browserVersion": "98.0.4758.102","chrome": {"chromedriverVersion": "98.0.4758.102 (273bf7ac8c909cde36982d27f66f3c70846a3718-refs/branch-heads/4758@{#1151})","userDataDir": "/tmp/.com.google.Chrome.1OTIS2"},"goog:chromeOptions": {"debuggerAddress": "localhost:36989"},"networkConnectionEnabled": false,"pageLoadStrategy": "normal","platformName": "linux","proxy": {},"se:cdp": "ws://","se:cdpVersion": "98.0.4758.102","se:vnc": "ws://","se:vncEnabled": true,"se:vncLocalAddress": "ws://","setWindowRect": true,"strictFileInteractability": false,"timeouts": {"implicit": 0,"pageLoad": 300000,"script": 30000},"unhandledPromptBehavior": "dismiss and notify","webauthn:extension:credBlob": true,"webauthn:extension:largeBlob": true,"webauthn:virtualAuthenticators": true},"sessionId": "afa9e52ff23fcc5499dc7e436bcf925d","start": "2022-02-21T11:44:12.072459Z","stereotype": {"browserName": "chrome","browserVersion": "98.0","platformName": "Linux","se:vncEnabled": true},"uri": ""},"stereotype": {"browserName": "chrome","browserVersion": "98.0","platformName": "Linux","se:vncEnabled": true}}]}]}}
{"value": true,"message": "Node status was successfully set to draining."}
  • K8S_TOKEN : SA Token of your cluster
  • K8S_SERVER_API : URL to your kubernetes cluster api
  • K8S_NAMESPACE : The target namespace for your deployments
  • SELENIUM_HUB : URL (from the ingress) of the selenium hub. If you are running a distributed selenium grid, you need to adjust the code to connect to the corrent api endpoints
  • SELENIUM_MAXNODES : Maximum amount of nodes which should run in your selenium grid. This is optional.
  • SELENIUM_MINNODES : Minimum amount of idle nodes which should be kept. This is optional.
  • LOGMODE : Should the app log in readable text set it to “TEXT”, all other values will let the app log in JSON. This is optional.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store