How to create Pod template container to deploy in K8 cluster

12/16/2019

I'm newly doing kubernetes with my own interest, i have successfully setup my kubernetes master and worker machine in my Ubuntu machine both are up & and running with same Vnet.

Note : i installed all the required software in both machines and one is acting as master and another is worker.

$ 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

And this my jenkins configuration test cloud test validation also successful.

Cloud jenkins configuration

Now i am trying add two pod template container to docker and gradle in it, and below is the code.

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'
        }
      }
    }
  }

jenkins output

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

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

when i am running my job jenkins report below my worker is offline, can you please some help me how to troubleshoot this issue and let me know where i have to fix this to continue my jenkins jobs.

Please find the below container logs

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)
-- Gowthami Viswa
jenkins-pipeline
kubernetes

1 Answer

12/31/2019

The resolution to this issue was provided by original poster:

I got the solution to fix this issue, there was issue on port TCP Port for inbound agents: 50000, i have updated in my jenkins.

-- Gowthami Viswa

Links:

Jenkins

Gradle

Kubernetes

-- Dawid Kruk
Source: StackOverflow