如何创建Pod模板容器以在K8集群中部署

时间:2019-12-16 17:28:42

标签: kubernetes jenkins-pipeline

我本人出于自己的兴趣正在使​​用kubernetes,我已经在Ubuntu计算机上成功设置了kubernetes主计算机和工作计算机,并且都在同一Vnet上运行。

注意:我在两台计算机上都安装了所有必需的软件,其中一个充当主服务器,另一个充当工作器。

$ kubectl get nodes
NAME               STATUS   ROLES    AGE    VERSION
jenkins-linux-vm   Ready    master   2d4h   v1.17.0
suit-poc-worker2   Ready    worker   2d4h   v1.17.0

而且我的jenkins配置测试云测试验证也成功。

Cloud jenkins configuration

现在我正在尝试向docker中添加两个pod模板容器并在其中添加gradle,下面是代码。

def label = "worker-${UUID.randomUUID().toString()}"

podTemplate(label: label, containers: [
  containerTemplate(name: 'gradle', image: 'gradle:4.5.1-jdk9', command: 'cat', ttyEnabled: true),
  containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true)
],
volumes: [
  hostPathVolume(mountPath: '/home/gradle/.gradle', hostPath: '/tmp/jenkins/.gradle'),
  hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
]) {
  node(label) {
    def myRepo = checkout scm
    def gitCommit = myRepo.GIT_COMMIT
    def gitBranch = myRepo.GIT_BRANCH
    def shortGitCommit = "${gitCommit[0..10]}"
    def previousGitCommit = sh(script: "git rev-parse ${gitCommit}~", returnStdout: true)

    stage('Build') {
      container('gradle') {
        sh "gradle build"
      }
    }
    stage('Create Docker images') {
      container('docker') {
          sh 'docker -version'
        }
      }
    }
  }

詹金斯输出

[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node

Still waiting to schedule task
‘worker-05646d6f-4b6d-409f-b5eb-d9d33001bb84-665lk-55s19’ is offline

当我在我的工作人员下线运行我的詹金斯报告时,能否请您帮我解决此问题的方法,并告诉我在哪里必须解决此问题才能继续我的詹金斯工作。

请找到以下容器日志

root@jenkins-linux-vm:/home/poc-admin/Downloads# kubectl logs worker-e5fe76e7-868e-4546-91c2-0d0610c5cd9c-n5r31-1f45m
error: a container name must be specified for pod worker-e5fe76e7-868e-4546-91c2-0d0610c5cd9c-n5r31-1f45m, choose one of: [gradle docker jnlp]
root@jenkins-linux-vm:/home/poc-admin/Downloads# kubectl logs worker-e5fe76e7-868e-4546-91c2-0d0610c5cd9c-n5r31-1f45m docker
root@jenkins-linux-vm:/home/poc-admin/Downloads# kubectl logs worker-e5fe76e7-868e-4546-91c2-0d0610c5cd9c-n5r31-1f45m -c docker
root@jenkins-linux-vm:/home/poc-admin/Downloads# kubectl logs worker-e5fe76e7-868e-4546-91c2-0d0610c5cd9c-n5r31-1f45m -c jnlp
Warning: JnlpProtocol3 is disabled by default, use JNLP_PROTOCOL_OPTS to alter the behavior
Dec 17, 2019 6:10:21 AM hudson.remoting.jnlp.Main createEngine
INFO: Setting up agent: worker-e5fe76e7-868e-4546-91c2-0d0610c5cd9c-n5r31-1f45m
Dec 17, 2019 6:10:21 AM hudson.remoting.jnlp.Main$CuiListener <init>
INFO: Jenkins agent is running in headless mode.
Dec 17, 2019 6:10:22 AM hudson.remoting.Engine startEngine
INFO: Using Remoting version: 3.35
Dec 17, 2019 6:10:22 AM org.jenkinsci.remoting.engine.WorkDirManager initializeWorkDir
INFO: Using /home/jenkins/agent/remoting as a remoting work directory
Dec 17, 2019 6:10:22 AM org.jenkinsci.remoting.engine.WorkDirManager setupLogging
INFO: Both error and output logs will be printed to /home/jenkins/agent/remoting
Dec 17, 2019 6:10:22 AM hudson.remoting.jnlp.Main$CuiListener status
INFO: Locating server among [http://10.0.0.4:9090/]
Dec 17, 2019 6:10:22 AM hudson.remoting.jnlp.Main$CuiListener error
SEVERE: http://10.0.0.4:9090/tcpSlaveAgentListener/ is invalid: 404 Not Found
java.io.IOException: http://10.0.0.4:9090/tcpSlaveAgentListener/ is invalid: 404 Not Found
    at org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.resolve(JnlpAgentEndpointResolver.java:211)
    at hudson.remoting.Engine.innerRun(Engine.java:527)
    at hudson.remoting.Engine.run(Engine.java:488)

1 个答案:

答案 0 :(得分:0)

此问题的解决方法由原始海报提供:

  

我有解决此问题的解决方案,入站代理的端口TCP端口上存在问题:50000,我的詹金斯更新了。

     

-Gowthami Viswa

链接:

demo

Jenkins

Gradle