0

I'm running Selenium Grid in Minikube using the official Docker Selenium Helm chart, with KEDA enabled for autoscaling. My goal is to scale Chrome nodes based on session demand, where each node can handle up to 3 parallel sessions. However, when I launch a second identical test job, KEDA spins up a second node instead of assigning the session to one of the available slots on the first node. I'm trying to figure out why this happens.

Kubernetes: Minikube (latest version, single-node cluster). Helm Install Command:

helm install selenium-grid docker-selenium/selenium-grid --values val.yaml --namespace default

val.yaml

seleniumGrid:
  nodeMaxSessions: 3

autoscaling:
  enabled: true
  scalingType: deployment

I launch sessions via Python Selenium script in Kubernetes Jobs. The script creates a single Chrome session and keeps it open for testing.

Python code (in a Docker image, run as K8s Job):

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--headless")

SELENIUM_REMOTE_URL = os.getenv("SELENIUM_REMOTE_URL", "http://selenium-hub.default.svc.cluster.local:4444/wd/hub")

driver = webdriver.Remote(
command_executor=SELENIUM_REMOTE_URL,
options=chrome_options
)

driver.get("https://www.example.com")
time.sleep(60)
driver.quit()

K8s Job:

apiVersion: batch/v1
kind: Job
metadata:
name: selenium-test-job-1  # Or -2 for the second
spec:
template:
spec:
containers:
- name: selenium-test
  image: my-selenium-client:latest
  env:
  - name: SELENIUM_REMOTE_URL
    value: "http://selenium-hub.default.svc.cluster.local:4444/wd/hub"
  restartPolicy: Never
  backoffLimit: 0

I apply the first Job (kubectl apply -f job1.yaml), wait for it to run, then apply the second (kubectl apply -f job2.yaml with a different name).

This is what happening

  • First Job:

    KEDA scales up to 1 Chrome node (selenium-grid-selenium-node-chrome Deployment replicas=1). Hub assigns the session to this node (1/3 slots used).

  • Second Job:

    Instead of assigning to the existing node (which has 2/3 slots free), KEDA immediately scales to 2 replicas. New node starts, and the second session goes there.

I tried increasing the pooling interval for the scaled object from 20 seconds to 60 (I suspected that a new application instance wouldn't have time to connect to an existing node). I tried running jobs with a longer interval, about 2-3 minutes. I changed the scaling type for autoscaling from deployment to jobs.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.