Wednesday 23 February 2022

How to Deploy Selenium grid on Google Cloud Platform using Kubernetes and Helm

                                          



                                        It is a open secret that Selenium Grid maintenance is a nightmare in an era where you see a frequent upgrades to browsers and corresponding drivers. No sooner the usage of automation framework / selenium grid increases, scalability and maintenance becomes a challenge. To address such issues, we do have solutions based on dockers, docker swarm etc. Having said that, there are some caveats in scaling, managing container health etc.

Below solution would try to address most of them. Major chunks of the solution include Selenium, Zalenium, Docker, Kubernetes and Google Cloud Platform.

This article would outline the process of deploying Selenium grid(Zalenium) on Google cloud platform using Kubernetes and Helm.

What do we achieve with this setup..?

  • Scalability: GCP/GKE can scale the nodes and pods as per the given configuration.
  • Visibility: Zalenium provides a feature to view the live executions on the containers.
  • Availability: GKE kubernetes cluster makes selenium grid available all the time.
  • Maintenance: Low maintenance as the containers are destroyed after each execution.

Pre-requisites:

  • An active Google Cloud Platform account
  • Enable Kubernetes engine by setting up a Billing Account.

Lets Get Started!

  • Create a project "MyAutomationGrid" (or any name of your choice) in GCP.
  • Create a cluster, Compute --> Kubernetes Engine --> Clusters --> Create
    Select GKE Standard --> Configure

Name: zalenium
        Location: Regional
--> asia-east1-a
        Control plane version
--> static version

  • Use default-pool or Create node from "Add Node Pool"

 Number of nodes: 1 or 2
        Machine Configuration: Series - N2 --- Create

Wait for the cluster to get ready, it usually takes 3-4 minutes.

  • Select the checkbox of the required cluster --> connect
  • Copy the shown command and run in cloud shell.
  • Run the below set of commands in the cloud shell
    • Create a namespace 'zalenium'

    kubectl create namespace zalenium


    • Add the zalenium repository from git onto cluster.

helm repo add zalenium-github https://raw.githubusercontent.com/zalando/zalenium/master/charts/zalenium


            "zalenium-github" - repo name (can be changed as needed)

    • Search and confirm if the repo is created

                helm search repo zalenium


    • Deploy zalenium onto kubernetes cluster with the given configuration

                        helm install my-grid --namespace zalenium zalenium-github/zalenium --set hub.serviceType="LoadBalancer" --set hub.basicAuth.enabled="true" --set hub.basicAuth.username="seluser" --set hub.basicAuth.password="Selpwd"

                        "my-grid" - Helm's release name (can be changed as needed)

    • Verify if the service is created and up

  kubectl get service my-grid-zalenium --namespace="zalenium"


    • Note the external IP (this can also be found on GCP UI --> Cluster list)

Thats it! You are good to go now.


Validate the below URLs are accessible & then start the execution. 
(Provide the credentials when prompted for)


Live Preview of Test Executions: http://<ExternalIP>/grid/admin/live


Grid Console: http://<ExternalIP>/grid/console


Zalenium Dashboard for test recordings: http://<ExternalIP>/dashboard



Grid Url, authenticated with basic auth: http://seluser:Selpwd@<ExternalIP>/wd/hub


Below code snippet shows the usage of zalenium desired capabilities and the remote url to access the grid.




References:

https://github.com/zalando/zalenium/tree/master/charts/zalenium
https://opensource.zalando.com/zalenium/

1 comment:

  1. Thank you. It's been such a complex task to setup and your blog helps all to explore the simplicity and the power of execution combo it brings. Love your Technical Blogs...keep sharing.

    ReplyDelete