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

sg24os4d  于 2023-04-20  发布在  Jenkins
关注(0)|答案(1)|浏览(134)

我目前正在努力为Jenkins Pipeline运行的K8s集群设置适当的yaml配置(见下文)。
到目前为止,整个配置都是在Jenkins UI中设置的,定义了云,基本的pod模板和不同的工作pod。所有的工作pod都依赖于一个docker镜像,这是在我开始项目之前就已经定制的。还有一个自定义JNLP容器的镜像,我需要使用它。
我的方法是使用JenkinsPipeline日志的输出pod.yaml(基于GUI配置)作为创建我自己的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
pu82cl6c

pu82cl6c1#

我有同样的问题.我能够通过使用声明式管道修复它. Jenkinsfile是不同的,因为这一点.以下是我的一个例子.没有必要为pod. yml. Pods/容器在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/

相关问题