SELENIUM GRID RUNNING ON IBM CLOUD KUBERNETES SERVICE (IKS)

Juan José Pérez B
7 min readOct 8, 2020

This tutorial was built in collaboration with Luis Alberto Mira and here are the steps to install the Selenium Grid over an IKS (IBM Cloud Kubernetes Service).

What is Selenium Grid?

Selenium is a framework for testing web applications that provide tools in order to run functional tests. Selenium Grid is a component of the suite that works as a smart proxy server that specializes in the execution of multiple parallel tests across different browsers, operating systems, and machines. It is achieved by routing the commands of remote browser instances where a server acts as a hub or proxy orchestrate requirements and nodes.

The two major components of selenium are Hub and Node, the first one hub accepts the request from a WebDriver client, and execute them remotely on many nodes in parallel.

And the node act as a remote device that receives the request and executes it using WebDriver.

What we are going to need?

You may need some knowledge on manipulating files with VIM, Nano, notepad, or another text editor depending if you are going to use your workstation or IBM CLI

In case of use, your workstation needs some preinstalled tools like:

kubectl: Kubernetes Command Line Tool

Helm (Optional): Package management for Kubernetes

Git: (Optional): To download the repository and get the examples

And here we explain how to install and configure

  • IBM Cloud Kubernetes Cluster and ibmcloud Command Line Tool
  • Installation of Istio 1.7
  • Installation of Selenium Grid hub and nodes
  • Kubernetes Ingress to expose the endpoint

NOTE: You might need to use an account Pay-As-You-Go, since selenium grid uses an endpoint that needs to be accessible, that is the reason we are going to use IBM Cloud Load balancer routed by the Kubernetes Ingress with ISTIO as a service mesh. Have in mind you could get USD$200 of credits by the first month.

Create a Kubernetes Cluster

After to create your account, you need log in to this page https://cloud.ibm.com/login and put your credentials first

IBM Cloud Log in Portal

When you log in, you click in the top left menu and select the option Kubernetes > clusters

Now you can see the next screen and you can select the option create cluster

Select a plan, you can choose the standard option or select the name for your cluster, the number of nodes, the region, choose the flavor of the instances (are) of the and click in “create” to build the cluster

Finally, after 20 minutes approximately the cluster is ready to use.

Install IBM Cloud Command Line Tool or Use IBM CLI Embedded

You could use the IBM CLI in order to interact with all the IKS components, there you have already installed the components needed in this article.

Or you could use your own workstation, follow the steps on this page to install the latest IBM Cloud CLI based on your OS:

In this case, we are going to install with:

curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
IBM CLI Installation

Accessing your cluster

  1. Log in to your IBM Cloud account. using the following command, after that you would be asked by the password.
ibmcloud login -a cloud.ibm.com -r us-south -u <account>
ibmcloud command line tool to login with the account

2. Set the Kubernetes context to your “~/.kube/config” file, with the following command

ibmcloud ks cluster config --cluster <cluster-name>
add the cluster to the kube-config file

3. Verify that you can connect to your cluster.

kubectl config current-context
kubectl get pods -n kube-system

Now, you are ready to execute kubectl commands to manage your cluster workloads in IBM Cloud

Install Istio using IBM Cloud addons

In order to expose the selenium-grid application to the world, we are going to install Istio as a service mesh, that will allow us to create a LoadBalance Service and expose it with an IP Address or DNS.

ibmcloud ks cluster addon enable istio -cluster <cluster_name>
istio addon installation

After the installation, you can list the addons

ibmcloud ks cluster addon ls -cluster <cluster_name>
addons list

After a few seconds, the pods start to appear

kubectl get pods -n istio-system
pods on istio-system namespace

Install Selenium Grid Hub and Nodes

There are many ways to deploy the Selenium grid Hub and Nodes, the standard way, using raw files like deployments, services, ingress, and Virtual services, or using Helm, a tool that creates all the artifacts needed by selenium by easily.

We are going to deploy in a large way, in order to know the used Kubernetes components. in this article are the snippet of the code, but you could clone them from the repo using :

git clone https://github.com/juanjopb/k8s-selenium-grid

First, create we create a Namespace to group all the components in a different of the default Namespace.

kubectl create namespace selenium

We need to apply an Istio injection in order to add an Istio sidecar on any new pods that are created in that namespace.

kubectl label namespace selenium istio-injection=enabled

The following is the deployment file and the service to spin up the hub component working as a controller of the nodes. (If you cloned the repository you could find the artifacts on the folder “k8s-selenium-grid/selenium-grid-files”)

deployment.yaml of the Hub component
service.yaml of the Hub component

Copy the snippet codes above and save on your workstation, each one in files as “deployment.yaml” and “service.yaml” then executes the following lines, taking care of the namespace

kubectl apply -f deployment.yaml -n seleniumkubectl apply -f service.yaml -n selenium
deployment and service created

Check the pods running on the selenium namespace

kubectl get pods -n selenium
kubectl get service -n selenium
pod and services running

Create an Ingress and VirtualService

Now, we have to expose the selenium console to be accessible via the internet. We achieve this using Istio components ingress and a virtual server

ingress.yaml
virtualservice.yaml component to connect with the service.

Copy the snippet codes above and save on your workstation, each one in files as “ingress.yaml” and “virtualservice.yaml” then executes the following lines, run inside the namespace selenium.

kubectl apply -f ingress.yaml -n seleniumkubectl apply -f virtualservice.yaml -n selenium
ingress and virtualservice applied.

After applied the ingress and virtual service components we can run the following command in order to know the IP Address generated by Istio using an ALB of IBM Cloud.

kubectl get service --all-namespaces

Notice the column External-IP has public addresses, but one belongs to the Istio-ingress gateway, and this in conjunction with the gateway and virtual service created, exposes the service to the internet.

Selenium URL open by the port 80

Install Selenium Nodes

The nodes are the final executors of the test, the Hub makes control, and calls the nodes to run the tests.

deployment-node.yaml
service-node.yaml

Save the files and run taking care of the namespace

kubectl apply -f deployment-node.yaml -n seleniumkubectl apply -f service-node.yaml -n selenium
kubectl get pods -n selenium

Running the command to check the pods running on the namespace

And check the console you can view the node deployed

Next Article Testing with Selenium Grid on K8s

--

--