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")
}
}
}
}
}
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.