Skip to content

Instantly share code, notes, and snippets.

@elsonrodriguez
Last active October 17, 2023 14:21
Show Gist options
  • Save elsonrodriguez/261e746cf369a60a5e2d to your computer and use it in GitHub Desktop.
Save elsonrodriguez/261e746cf369a60a5e2d to your computer and use it in GitHub Desktop.
Selenium on Kubernetes!

This is a quick and dirty guide on how to deploy Selenium on Kubernetes.

It is required that you have Kubernetes cluster up and running. If you don't have one, GKE is pretty nifty: https://cloud.google.com/container-engine/

Deploy the Seleniumb Hub:

kubectl create -f selenium-hub-rc.yaml
kubectl create -f selenium-hub-svc.yaml

Deploy some Firefox and Chrome pods:

kubectl create -f selenium-node-chrome-rc.yaml
kubectl create -f selenium-node-firefox-rc.yaml

Grab the Service ip or nodeport:

kubectl describe service selenium-hub

Then it should be on serviceip:4444 or kube-host:nodeport/

If you need more Firefox or Chrome nodes, your hardware is the limit:

kubectl scale rc selenium-node-firefox --replicas=10
kubectl scale rc selenium-node-chrome --replicas=10

To check on one of the browser nodes via VNC, you may have to proxy depending on your kube setup:

kubectl port-forward -p <POD_NAME> 9000:5900

Then connect to localhost:9000 with your VNC client.

TODO: Figure out healthcheck for the nodes.

Adapted from: https://github.com/SeleniumHQ/docker-selenium

apiVersion: v1
kind: ReplicationController
metadata:
name: selenium-hub
labels:
name: selenium-hub
spec:
replicas: 1
selector:
name: selenium-hub
template:
metadata:
labels:
name: selenium-hub
spec:
containers:
- name: selenium-hub
image: selenium/hub:2.47.1
ports:
- containerPort: 4444
resources:
limits:
memory: "1000Mi"
cpu: "1"
livenessProbe:
httpGet:
path: /grid/console
port: 4444
initialDelaySeconds: 30
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /grid/console
port: 4444
initialDelaySeconds: 30
timeoutSeconds: 5
apiVersion: v1
kind: Service
metadata:
name: selenium-hub
labels:
name: selenium-hub
spec:
ports:
- port: 4444
targetPort: 4444
name: port0
selector:
name: selenium-hub
type: NodePort
sessionAffinity: None
apiVersion: v1
kind: ReplicationController
metadata:
name: selenium-node-chrome
labels:
name: selenium-node-chrome
spec:
replicas: 3
selector:
name: selenium-node-chrome
template:
metadata:
labels:
name: selenium-node-chrome
spec:
containers:
- name: selenium-node-chrome
image: selenium/node-chrome-debug:2.47.1
ports:
- containerPort: 5900
env:
- name: HUB_PORT_4444_TCP_ADDR
value: "selenium-hub"
- name: HUB_PORT_4444_TCP_PORT
value: "4444"
resources:
limits:
memory: "1000Mi"
cpu: "1"
apiVersion: v1
kind: ReplicationController
metadata:
name: selenium-node-firefox
labels:
name: selenium-node-firefox
spec:
replicas: 3
selector:
name: selenium-node-firefox
template:
metadata:
labels:
name: selenium-node-firefox
spec:
containers:
- name: selenium-node-firefox
image: selenium/node-firefox-debug:2.47.1
ports:
- containerPort: 5900
env:
- name: HUB_PORT_4444_TCP_ADDR
value: "selenium-hub"
- name: HUB_PORT_4444_TCP_PORT
value: "4444"
resources:
limits:
memory: "1000Mi"
cpu: "1"
@elsonrodriguez
Copy link
Author

@hisrarul The best way to share files in Kubernetes is with an object store such as S3 or GCS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment