<p>I’m running my POC java application inside the EKS cluster. Here the steps I followed to move my application into containerized application.</p>
<ol>
<li>Java application source code is checkout into my local workstation.</li>
<li>Executed the maven command to generate the package mvn package -DskipTests</li>
<li>As usual mvn package command will generate the packages inside the target folder I can see all the dependencies including jar file which has selenium jar to run the test cases.</li>
<li>Using docker build command I have created a docker image out of the source code docker build -t myapp .</li>
<li>Then I have entered into docker container using below command I can see my test cases are executed successfully without any issue.</li>
</ol>
<p>dockerfile</p>
<pre><code>FROM openjdk:8u191-jre-alpine

# Workspace
WORKDIR /usr/share/selenium_docker

# ADD jar files and any other dependencies from HOST
ADD target/selenium-docker.jar selenium-docker.jar
ADD target/selenium-docker-tests.jar selenium-docker-tests.jar
ADD target/libs libs

# add TestNG suite files
ADD duck_search_tests.xml duck_search_tests.xml
ADD saucedemo_tests.xml saucedemo_tests.xml

# run tests using provided browser/hub address/test suite module
ENTRYPOINT java -cp selenium-docker.jar:selenium-docker-tests.jar:libs/* -DBROWSER=$BROWSER -DHUB_HOST=$HUB_HOST org.testng.TestNG $MODULE
</code></pre>
<pre><code>docker run -e HUB_HOST=192.168.1.1 -e MODULE=saucedemo_tests.xml -v /c/Users/ /workspace/delete/JavaSeleniumDocker/output:/usr/share/selenium_docker/test-output localhost/myapp

Jul 17, 2023 4:41:44 AM org.openqa.selenium.remote.DesiredCapabilities chrome
INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
Jul 17, 2023 4:41:51 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Logging in to Sauce Demo site...
Logged In!
Home page loaded with page header: Products
Added item to cart
Price of item is: $29.99
Logging in to Sauce Demo site...
Logged In!

===============================================
check_price
Total tests run: 2, Failures: 0, Skips: 0
===============================================


</code></pre>
<p>Next i'm moving my docker image into docker hub registry and i'm trying to deploy the image inside the EKS cluster, when i'm doing deployment i can see the pod is up and running and also i run the kubectl logs -f pod command to verify the test case execution i can able to see same like above message like Total tests run: 2, Failures: 0, Skips: 0, but problem is pod is restarting every time when the test case execution completed, its again and again pod status is going to CrashLoopBackOff and running .....</p>
<p>here the K8s yaml file</p>
<pre><code>---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample-app-deployment-deployment
  namespace: devops-java-selenium
  labels:
    app: sample-app-deployment
    name: sample-app-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sample-app-deployment
  template:
    metadata:
      labels:
        app: sample-app-deployment
        name: sample-app-deployment
    spec:
      containers:
        - name: sample-app-deployment
          image: myapp
            env:
             - name: HUB_HOST
               value: &quot;10.1.2.3&quot;
             - name: BROWSER
               value: chrome
             - name: MODULE
               value: 
             - name: selenium_grid_host
               value: &quot;4444&quot;
          volumeMounts:
              - mountPath: /usr/share/selenium/test-output
                name: devops-caas-java-selenium-pv
      volumes:
        - name: devops-caas-java-selenium-pv
          hostPath:
             path: /tmp/palani
</code></pre>
<p>Can you please someone help me on this.</p>

Gowmi
<p>That is the nature of a Deployment. When The pod finishes its task, the pod completes. But the Deployment has the purpose to keep up a certain number of pods (replicas) so it will recreate the pod again and again to fullfill its purpose. This is leading to your CrashLoopBackOff. I think maybe you should use a kubernetes job with the restartPolicy: OnFailure for your specific use case.</p>
