Kubernetes 上的 Selenium Chrome 节点会话删除错误

selenium chrome node session deleted error on kubernetes

提问人:iamarunk 提问时间:10/7/2023 更新时间:10/7/2023 访问量:32

问:

我在 kubernetes 上运行 selenium-chrome-node

我的部署文件如下所示

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "27"
    meta.helm.sh/release-name: selenium-grid
    meta.helm.sh/release-namespace: selenium
  labels:
    app: selenium-chrome-node
    app.kubernetes.io/component: selenium-grid-4.2.1-20220531
    app.kubernetes.io/instance: selenium-grid
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: selenium-chrome-node
    app.kubernetes.io/version: 4.2.1-20220531
    helm.sh/chart: selenium-grid-0.3.1
  name: selenium-chrome-node
  namespace: selenium
spec:
  progressDeadlineSeconds: 600
  replicas: 0
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: selenium-chrome-node
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/event-bus-configmap: 3326d302d3d9be02414e9b1704a096d537227bab08ada6472b5681731d4cb190
      creationTimestamp: null
      labels:
        app: selenium-chrome-node
        app.kubernetes.io/component: selenium-grid-4.2.1-20220531
        app.kubernetes.io/instance: selenium-grid
        app.kubernetes.io/managed-by: helm
        app.kubernetes.io/name: selenium-chrome-node
        app.kubernetes.io/version: 4.2.1-20220531
        helm.sh/chart: selenium-grid-0.3.1
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: type
                operator: In
                values:
                - spot
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - backend
              topologyKey: kubernetes.io/hostname
            weight: 1
      containers:
      - env:
        - name: SE_NODE_MAX_SESSIONS
          value: "4"
        - name: SE_NODE_OVERRIDE_MAX_SESSIONS
          value: "true"
        - name: SE_NODE_SESSION_TIMEOUT
          value: "600"
        envFrom:
        - configMapRef:
            name: selenium-event-bus-config
        image: selenium/node-chrome:4.2.1
        imagePullPolicy: IfNotPresent
        name: selenium-chrome-node
        ports:
        - containerPort: 5553
          protocol: TCP
        resources:
          limits:
            cpu: 1500m
            memory: 2Gi
          requests:
            cpu: 900m
            memory: 1Gi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /dev/shm
          name: dshm
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - emptyDir:
          medium: Memory
          sizeLimit: 2Gi
        name: dshm

我的 Jenkins 文件看起来像

pipeline {
agent any
  environment {
    client_id="xxxx"
    client_email="xxx"
    private_key=credentials('xxx')
    private_key_id=credentials('xxx')  
    project_id="xxx"
    artifact="xxx"
    credentials_id="xxx"
    project_id_harbor="xxx"
    credentials_id_harbor="xxx"
    registry_url_harbor="xxx"
    browser_grid_url="xxx"
  }
  parameters {
    choice(choices: ['STAGING_MAIN', 'DEV_MAIN', 'DEV_BRANCH1','STAGING_BRANCH1'], name: 'EXEC_ENV', description: 'Provided value is passed against the key EXEC_ENV')
    choice(choices: ['chrome', 'firefox', 'safari'], name: 'BROWSER', description: 'Provided value is passed against the key BROWSER')
    booleanParam(defaultValue: false, description: 'Check this, if results are not required to update in TestRail. Provided value is passed against the key DRYRUN', name: 'DRYRUN')
    string(defaultValue: '', description: 'Enter Run ID if results are required to update in TestRail otherwise leave it blank. Provided value is passed against the key TESTRAILRUNID', name: 'TESTRAILRUNID', trim: true)
  }
  stages {
    stage("Start") {
        steps {
            script {
            if("${env.JOB_BASE_NAME}" == 'PR-*') {
                    sh "git merge --ff-only -"
                }
                def git_hash=sh returnStdout:true, script:'git rev-parse HEAD'
                def version="${git_hash.trim()}.${env.BUILD_NUMBER}"
                def imageTag="${env.project_id}/${env.artifact}:${version}"
            }
        }
    }
    stage('Build the image') {
        steps {
                withDockerRegistry(credentialsId: "${credentials_id_harbor}", url: "${registry_url_harbor}") {
                    sh "docker build --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from=${env.project_id_harbor}/${env.artifact}:${env.BRANCH_NAME} --tag ${env.project_id_harbor}/${env.artifact}:${env.BRANCH_NAME} ."
                }
        }
    }
   stage('Execute on Automation') {
    steps {
            withDockerRegistry(credentialsId: "${credentials_id_harbor}", url: "${registry_url_harbor}") {
                sh 'docker run --network host --name lms-automation -e "CLIENT_ID=$client_id" -e "CLIENT_EMAIL=$client_email" -e "PRIVATE_KEY=$private_key" -e "PRIVATE_KEY_ID=$private_key_id" -e "BROWSER_GRID_URL=$browser_grid_url" -e "EXEC_ENV=$EXEC_ENV" -e "BROWSER=$BROWSER" -e "TESTRAILRUNID=$TESTRAILRUNID" -e "DRYRUN=$DRYRUN" -t "$project_id_harbor/$artifact:$BRANCH_NAME"'
                sh "docker cp lms-automation:/usr/src/app/allure-results ./reports"
                sh "chown -R 1000:1000 ./reports"
                sh "ls -lah"
                }
        }
    }
    stage('reports') {
        steps {
        script {
                allure([
                        includeProperties: false,
                        jdk: '',
                        properties: [],
                        reportBuildPolicy: 'ALWAYS',
                        results: [[path: 'reports']]
                ])
           }
        }
     }
  }
}

Jenkins作业成功运行后,我可以在诱惑报告中看到一些测试用例的错误

enter image description here

当我搜索这些错误的解决方案时,我知道这个错误是由于 /dev/shm 大小小而发生的,但在我的部署文件中,/dev/shm 的内存大小为 2Gi。

我仍然收到页面崩溃,我该如何解决?

kubernetes selenium-webdriver selenium-grid

评论


答: 暂无答案