在EKS集群运行Selenium测试遇CrashLoopBackOff问题求助
问题排查:EKS中Selenium测试Pod CrashLoopBackOff及连接失败问题
我将Java代码容器化后部署到EKS 1.24托管节点组集群,已构建Docker镜像并完成K8s部署,但Pod始终处于CrashLoopBackOff状态。工作节点挂载了卷可查看index.html,但测试执行时出现连接错误。
核心报错信息
Caused by: java.net.ConnectException: Failed to connect to localhost/[0:0:0:0:0:0:0:1]:4444
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:242)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
补充环境信息
- 已部署Selenium Grid服务,通过ALB Ingress Controller暴露,可通过AWS提供的外部URL访问带单节点Chrome的Selenium Grid Hub
- Ingress地址:
http://internal-k8s-devops-path-of-the-adddress - 配置变量:
- k8s_host: my-alb-ingress-address
- selenium_grid_host: my-grid-hub-service-name:4444
- MODULE: search-module.xml
Deployment配置文件(k8s-deployment.yaml)
apiVersion: apps/v1 kind: Deployment metadata: name: selenium-grid-k8s-autoscaler-deployment namespace: devops-java-selenium labels: app: selenium-grid-k8s-autoscaler name: selenium-grid-k8s-autoscaler spec: replicas: 1 selector: matchLabels: app: selenium-grid-k8s-autoscaler template: metadata: labels: app: selenium-grid-k8s-autoscaler name: selenium-grid-k8s-autoscaler spec: containers: - name: selenium-grid-k8s-autoscaler image: my-app-image env: - name: k8s_host value: my-alb-ingress-address - name: selenium_grid_host value: selenium-grid-hub:4444 - name: MODULE value: search-module.xml volumeMounts: - mountPath: /usr/share/selenium/test-output name: devops-java-selenium-pv volumes: - name: devops-java-selenium-pv hostPath: path: /tmp/app
应用Pod日志
Jul 10, 2023 6:16:39 AM org.openqa.selenium.remote.DesiredCapabilities chrome INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()` Jul 10, 2023 6:16:39 AM org.openqa.selenium.remote.DesiredCapabilities chrome INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()` Jul 10, 2023 6:16:39 AM org.openqa.selenium.remote.DesiredCapabilities chrome INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()` Jul 10, 2023 6:16:39 AM org.openqa.selenium.remote.DesiredCapabilities chrome INFO: Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()` =============================================== search-module Total tests run: 4, Failures: 0, Skips: 4 Configuration Failures: 4, Skips: 4 ===============================================
排查步骤
验证环境变量读取正确性
- 进入应用Pod内部执行
echo $selenium_grid_host,确认输出为selenium-grid-hub:4444而非localhost。如果Java代码硬编码了localhost:4444,需修改代码改为读取环境变量selenium_grid_host。
- 进入应用Pod内部执行
检查Selenium Grid服务可达性
- 在应用Pod内部执行
curl selenium-grid-hub:4444/wd/hub/status,验证是否能连通Selenium Hub:- 若不通,确认Selenium Grid服务
selenium-grid-hub是否和应用Pod在同一命名空间(devops-java-selenium),不在同一命名空间需使用跨命名访问格式selenium-grid-hub.<namespace>:4444。 - 检查Selenium Hub服务的端口配置,确保暴露的是4444端口。
- 确认Selenium Hub Pod本身运行正常,无Crash或重启情况。
- 若不通,确认Selenium Grid服务
- 在应用Pod内部执行
排查网络策略限制
- 检查当前命名空间是否存在NetworkPolicy,确认没有限制应用Pod访问Selenium Grid服务4444端口的规则。
验证hostPath卷挂载权限
- 进入应用Pod执行
ls -ld /usr/share/selenium/test-output,确认目录存在且容器进程有读写权限。必要时在Dockerfile中添加目录权限配置(如RUN mkdir -p /usr/share/selenium/test-output && chown -R <user>:<group> /usr/share/selenium/test-output)。
- 进入应用Pod执行
查看Pod退出细节
- 执行
kubectl describe pod <pod-name> -n devops-java-selenium,查看Events中的退出原因,确认是否因4个测试配置失败导致进程退出,进而引发CrashLoopBackOff。
- 执行
内容的提问来源于stack exchange,提问作者Gowmi
相关产品推荐
相关产品推荐

