Scaling your Automation using Selenium with Kubernetes(Minikube) and Docker on macOS BigSur

krishna chetan
5 min readMay 23, 2021

After so much time wasted on setting up a working environment with Kubernetes and selenium on a macOS BigSur using Minikube, decided to write this blog to make it easier for whoever wants to set it up next.

Step 1: Install Homebrew.

Homebrew installs the stuff you need that Apple (or your Linux system) didn’t.

Homebrew installs packages to their own directory and then symlinks their files into /usr/local.

Type following command in terminal to install Homebrew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)

Step 2: Download and docker GUI from docker website

https://docs.docker.com/docker-for-mac/install/

Step 3: Install minikube to setup a local kubernetes using brew

brew install minikube

Step 4: Install kubernetes-cli to control kubernetes deployments from terminal using brew

brew install kubernetes-cli

Step 5: Set minkube to use virtualbox as VM

Step 5.1: Install virtual box from

https://www.virtualbox.org/wiki/Downloads

Step 5.2: Make virtualbox the default driver

minikube config set vm-driver virtualbox

Step 6: Setup the required Proxy

If an HTTP proxy is required to access the internet, you may need to pass the proxy connection information to both minikube and Docker using environment variables

Step 6.1: Open .bash_profile on mac terminal

nano .bash_profile

Step 6.2: Update the following as required(Note: Do not use HTTP_PROXY, HTTPS_PROXY if not required)

export HTTP_PROXY=http://<proxy hostname:port>
export HTTPS_PROXY=https://<proxy hostname:port>
export NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.99.0/24,192.168.39.0/24

Note: As I did not require HTTP_PROXY, HTTPS_PROXY to run locally, have set only NO_PROXY

Step 6.3: Refresh .bash_profile on mac terminal

source .bash_profile

More information on Proxy :

  • HTTP_PROXY - The URL to your HTTP proxy
  • HTTPS_PROXY - The URL to your HTTPS proxy
  • NO_PROXY - A comma-separated list of hosts which should not go through the proxy.

The NO_PROXY variable here is important: Without setting it, minikube may not be able to access resources within the VM. minikube uses two IP ranges, which should not go through the proxy:

  • 192.168.99.0/24: Used by the minikube VM. Configurable for some hypervisors via --host-only-cidr
  • 192.168.39.0/24: Used by the minikube kvm2 driver.
  • 192.168.49.0/24: Used by the minikube docker driver’s first cluster.
  • 10.96.0.0/12: Used by service cluster IP’s. Configurable via --service-cluster-ip-range

One important note: If NO_PROXY is required by non-Kubernetes applications, such as Firefox or Chrome, you may want to specifically add the minikube IP to the comma-separated list, as they may not understand IP ranges.

Step 7: Start minikube

minikube start --vm-driver=virtualbox --insecure-registry="gcr.io"

Please enter your system password when prompted for giving sudo permissions.

Step 8: Deploy Selenium Grid Hub

We will be using Selenium Grid Hub to make our Selenium install scalable via a master/worker model. The Selenium Hub is the master, and the Selenium Nodes are the workers. We only need one hub, but we’re using a replication controller to ensure that the hub is always running.

Step 8.1: Create an folder on mac where you will be storing all configuration files and cd to the folder

mkdir Selenium-kubernetes
cd Selenium-kubernetes

Step 8.1: Create new deployment script file required in the above folder

nano selenium-hub-deployment.yaml

Step 8.2: Use the following configuration for the file and save and close the file by using ctrl+x

By adding Strategy as RollingUpdate we can change the hub’s version and after this, we can apply the changes without re-creation the deployment.

kubectl create -f selenium-hub-deployment.yaml

Step 9: The Selenium Nodes will need to know how to get to the Hub, let’s create a service for the nodes to connect to.

Step 9.1: Create an file with the below name and save it with the below content

nano selenium-hub-service.yaml

Step 9.2: Use the following configuration for the file and save and close the file by using ctrl+x

Note : “selenium-hub-service.yaml” service was created and we connected it with our hub and our nodePort is 30009 which means we can reach the hub with this port.

Step 9.3: Kubernetes Service creation

kubectl create -f selenium-hub-service.yaml

Step 10: Verify Selenium Hub Deployment

Let’s verify our deployment of the service by the below command.

kubectl describe service
Observe that the endpoint is 192.168.49.2 and the node port is 30009, we can use this to connect our hub via http://192.168.49.2:30009/

Step 11: Deploy Firefox and Chrome Nodes:

Now that the Hub is up, we can deploy workers. We will deploy 2 Chrome nodes And 2 Firefox nodes using two separate files and deploy them.

Create two files selenium-node-chrome-deployment.yaml and selenium-node-firefox-deployment.yaml

Step 11.1: Chrome Replication controller

Step 11.2: Firefox Replication controller

Step 11.3: Lets go ahead deploy them

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

Step 12: Lets expose this service to view on mac browser

kubectl expose deployment selenium-hub — type=NodePort

Step 13: To Access the selenium-hub url

minikube service selenium-hub --url

You should be able to view your pods running by typing

kubectl get pods

Step 14: View your Minikube Dashboard using

minikube dashboard

Step 15: We should be able to see our selenium grid with attached browsers as below

minikube service selenium-hub --urld

--

--

krishna chetan

Automation Test Engineer by Profession, Traveller by the Weekend