Kubernetes cloud agent for Jenkins always offline during pipeline execution

5/2/2021

I try to deploy microservices into k8s pod using Jenkins pipeline and k8s cloud agent. I configured my agent on Jenkins but during execution I always have message saying my agent is offline.

You could find my Jenkins configuration and my Jenkins file.

Regards,

Jenkinsfile

pipeline {
    environment {
        MAVEN_SETTINGS = ''
        MAVEN_ENV = 'maven-3.6.3'
        JDK_ENV = 'jdk-1.2'
        GIT_URL = 'PRIVATE REPO'
    }
    agent any
    parameters{
        booleanParam(name:"RELEASE",
           description:"Release",
           defaultValue:false
        )
    }
    stages {
        stage ('build & deploy'){
            when{
                expression {!params.RELEASE}
            }
            steps{
                withMaven(
                    maven: env.MAVEN_ENV,
                    mavenSettingsConfig: env.MAVEN_SETTINGS,
                    jdk: env.JDK_ENV) {
                        sh "mvn clean deploy -U"
                }
			}
        }
        stage ('create image'){
            steps{
                script {
                    docker.withRegistry('https://registry.digitalocean.com', 'images-credential') {
                        def customImage = docker.build("images-repo:${params.IMAGE_VERSION}","./target")
                        customImage.push("${params.IMAGE_VERSION}")
                    }
                }
            }
        }
        stage ('Deploy Pod') {

            agent { label 'kubepod' }

            steps {
                script {
                    kubernetesDeploy(configs: "/kubernetes/pod.yml", kubeconfigId: "mykubeconfig")
                    kubernetesDeploy(configs: "/kubernetes/services.yml", kubeconfigId: "mykubeconfig")
                }
            }
        }
    }
}

Kubernetes agent config enter image description here

Pod template config enter image description here

Jenkins global security config enter image description here

Build log enter image description here

-- Ousmane MINTE
devops
jenkins
jenkins-pipeline
kubernetes

2 Answers

5/2/2021

enter image description here

Use TCP port for inbound agents: Fixed and put 50000

-- Dashrath Mundkar
Source: StackOverflow

5/3/2021

You do not have to create direction connection.Please go to Kubernetes cloud details and add your service token and ssl of that token to make connection. you have a issue in your pipeline.Please correct it like

stage(test){
  agent{
    cloud 'cloud name'
    yaml"""

    """

  }
} 

Please follow this article to start from the basic details.

-- Taybur Rahaman
Source: StackOverflow