K8S - 将 Pod 定义从 Jenkins GUI 切换到 yaml 文件会导致自定义 jnlp 容器出错

问题描述 投票:0回答:1

我目前正在努力为运行我们的 Jenkins 管道的 K8s 集群设置适当的 yaml 配置(见下文)。

到目前为止,整个配置都是在 Jenkins UI 中设置的,定义了云、基本 pod 模板和不同的工作 pod。所有工作的 pod 都依赖于一个 docker 镜像,它在我开始处理该项目之前就已经定制好了。还有一个自定义 JNLP 容器的图像,我需要使用它。

我的方法是使用来自 Jenkins 管道日志(基于 GUI 配置)的输出 pod.yaml 作为创建我自己的 yaml 的基本模板。因此,应正确设置所有必要的参数。我只是想知道 jnlp 容器是否缺少某些凭据...Idk,我有点迷茫,因为我刚刚开始使用相关技术,非常感谢您的帮助。谢谢:)

我收到的错误信息如下:

Dec 08, 2021 3:23:39 PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Protocol JNLP4-connect encountered an unexpected exception
java.util.concurrent.ExecutionException: org.jenkinsci.remoting.protocol.impl.ConnectionRefusalException: Unknown client name: \cloud-work-z8vpq-snct7

在这里查看我的代码:

来自我的 Jenkinsfile 的片段:

stage ('PC Linux x64') {
  agent {
    kubernetes {
      cloud 'our-cloud'
      label 'cloud_work'
      idleMinutes 5
      defaultContainer 'work-docker-dml'
      yamlFile 'pod.yaml'
    }
}

我创建的 YAML 配置(“pod.yaml”):

apiVersion: "v1"
kind: "Pod"
metadata:
  labels:
    jenkins-work: "k8s-jnlp-agents"
    jenkins/label: "cloud_work"
  name: "cloud-work"
spec:
  containers:
  - command:
    - "/bin/bash"
    - "-ex"
    image: "artifactory.company.local:6013/work:ubnt20.04_dml_v2"
    imagePullPolicy: "Always"
    name: "work-docker-dml"
    securityContext:
      privileged: false
      runAsGroup: 1000
      runAsUser: 1000
    tty: true
    volumeMounts:
    - mountPath: "/net/example/examplemount"
      name: "volume-3"
      readOnly: false
    workingDir: "/home/jenkins/agent"
  - command:
    - "jenkins-agent"
    image: "artifactory7.company.local/company-docker/company-focal-jnlp"
    imagePullPolicy: "Always"
    name: "jnlp"
    securityContext:
      privileged: false
      runAsGroup: 1000
      runAsUser: 1000
    tty: true
    volumeMounts:
    - mountPath: "/net/example/examplemount"
      name: "volume-3"
      readOnly: false
    workingDir: "/home/jenkins/agent"
  hostNetwork: false
  imagePullSecrets:
  - name: "secret 1"
  - name: "secret 2"
  nodeSelector:
    kubernetes.io/os: "linux"
  restartPolicy: "Never"
  volumes:
  - emptyDir:
      medium: ""
    name: "workspace-volume"
  - name: "volume-3"
    persistentVolumeClaim:
      claimName: "example"
      readOnly: false
jenkins kubernetes jnlp
1个回答
0
投票

我有同样的问题。我能够通过使用声明式管道来修复它。 Jenkinsfile 因此不同。按照我的一个例子。不需要 pod.yml。 Pod/Container 在 podTemplate-Section:

中声明
podTemplate(containers: [
   containerTemplate(
    name: 'jnlp',
    image: 'containerregistryaktenbewertung.azurecr.io/inbound-jenkins-agent:4.11-1-jdk11',
    args: '${computer.jnlpmac} ${computer.name}',
    envVars: [
      envVar(key: 'GIT_SSL_NO_VERIFY', value: 'true')
    ]),
   containerTemplate(
    name: 'oc-tool',
    image: 'docker.io/appuio/oc:v4.11',
    command: 'tail -f /dev/null'),
  ]) {

    node(POD_LABEL) {
      def gitInfo = checkout scm
      echo 'Checking out branch: ' + gitInfo.GIT_BRANCH

      def namespace
      if (gitInfo.GIT_BRANCH == 'master') {
          namespace = 'prod'
      } else if (gitInfo.GIT_BRANCH == 'develop') {
          namespace = 'dev'
      } else {
          echo 'Returning. No instructions for branch ' + gitInfo.GIT_BRANCH
          currentBuild.result = 'NOT_BUILT'
          return
      }
      echo 'Setting namespace to ' + namespace

      stage('Deployment to OCP') {
        git (
          url: 'https://bitbucket.org/av360/barch_oc_appdeployment',
          branch: gitInfo.GIT_BRANCH,
          credentialsId: 'barch-playground-jenkins',
          changelog: false,
          poll: true
        )

        container('oc-tool') {
         stage('Container build') {
                // Using openshift-Container for deployment of Container
             sh 'oc whoami'
             sh 'helm upgrade -i bewertungskatalog-tool ./openshift_deployment/xred/helm'
          }

        }
        }
  }
}

´´´

References here: https://plugins.jenkins.io/kubernetes/
And here: https://akomljen.com/set-up-a-jenkins-ci-cd-pipeline-with-kubernetes/
© www.soinside.com 2019 - 2024. All rights reserved.