One Jenkins, Two Kubernetes Clusters

3/6/2019

I'm trying to use multiple Kubernetes clouds and have just a single Jenkins. I was able to get both Kubernetes clusters registered as clouds and all the login checks work. When I run a build on the cluster where Jenkins is, it works fine, pulls the code, builds an image and all that.

However, when I change the label to my second cluster, that doesn't have any Jenkins there seems to never want to build there and always builds on the cluster that's local to Jenkins.

I'm missing something stupid I'm sure of it but don't see what it is.

-- Steve
jenkins
kubernetes

1 Answer

9/5/2019

What I did to make it work with two Kubernetes clusters and one Jenkins was I used a directive called: cloud '' like this:

stage('do something') {            
            agent { kubernetes {
                // CluserName is configured in Jenkins --> Manage Jenkins --> configure system in the Kubernetes plugin section
                cloud '<Clustername>'
                label "<TheLabelYouGave>"
                containerTemplate {
                name 'maven'
                image 'maven:3.3.9-jdk-8-alpine'
                ttyEnabled true
                command 'cat'
                }
            }
        }
        steps {
            script {
                echo "${pom.version} ======================================================="
            }                
        }             
}

You can see this in the examples located in the documentation of the Kubernetes plugin for Jenkins repo in GitHub: https://github.com/jenkinsci/kubernetes-plugin Ctrl + f and search for cloud 'kubernetes'

-- mfuxi
Source: StackOverflow